1 // RUN: %clang -x c -fsanitize=pointer-overflow %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NOTYPE,CHECK-NOTYPE-C
3 // RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-TYPE,CHECK-TYPE-C
4 
5 // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t
6 // RUN: %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NOTYPE,CHECK-NOTYPE-CPP
7 // RUN: %env_ubsan_opts=report_error_type=1 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-TYPE,CHECK-TYPE-CPP
8 
9 // REQUIRES: !ubsan-standalone && !ubsan-standalone-static
10 
11 #include <stdlib.h>
12 
13 int main(int argc, char *argv[]) {
14   char *base, *result;
15 
16   base = (char *)0;
17   result = base + 0;
18   // CHECK-NOTYPE-C: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:17
19   // CHECK-TYPE-C: SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset {{.*}}summary.cpp:[[@LINE-2]]:17
20   // CHECK-NOTYPE-CPP-NOT: SUMMARY:
21   // CHECK-TYPE-CPP-NOT: SUMMARY:
22 
23   base = (char *)0;
24   result = base + 1;
25   // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:17
26   // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-nonzero-offset {{.*}}summary.cpp:[[@LINE-2]]:17
27 
28   base = (char *)1;
29   result = base - 1;
30   // CHECK-NOTYPE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}summary.cpp:[[@LINE-1]]:17
31   // CHECK-TYPE: SUMMARY: UndefinedBehaviorSanitizer: nullptr-after-nonzero-offset {{.*}}summary.cpp:[[@LINE-2]]:17
32 
33   return 0;
34 }
35