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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of compiler-rt/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-summary.cpp