summaryrefslogtreecommitdiff
path: root/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-10-10 11:03:41 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-10-10 11:03:41 +0000
commiteac233c8a8711e52d3ecd7f63815b384dce71e04 (patch)
tree7b8db949d85496fead084b6287860b18e8d7d249 /test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
parentfe7f65b081d5d0b32270cb1a82e2ee9a0391a6d1 (diff)
downloadcompiler-rt-eac233c8a8711e52d3ecd7f63815b384dce71e04.tar.gz
[UBSan] Split nullptr-and-nonzero-offset-variable.c in another direction
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@374309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp')
-rw-r--r--test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp b/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
index 2be702047..ec376c7f5 100644
--- a/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
+++ b/test/ubsan/TestCases/Pointer/nullptr-and-nonzero-offset-variable.cpp
@@ -1,8 +1,18 @@
+// RUN: %clang -x c -fsanitize=pointer-overflow -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB-C
+// RUN: %clang -x c -fsanitize=pointer-overflow -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB-C
+// RUN: %clang -x c -fsanitize=pointer-overflow -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB-C
+// RUN: %clang -x c -fsanitize=pointer-overflow -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB-C
+
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK
+// RUN: %clang -x c -fsanitize=pointer-overflow -O0 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
+// RUN: %clang -x c -fsanitize=pointer-overflow -O1 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
+// RUN: %clang -x c -fsanitize=pointer-overflow -O2 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
+// RUN: %clang -x c -fsanitize=pointer-overflow -O3 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
+
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O0 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O1 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
// RUN: %clang -x c++ -fsanitize=pointer-overflow -O2 %s -o %t && %run %t I_AM_UB 2>&1 | FileCheck %s --implicit-check-not="error:" --check-prefix=CHECK-UB
@@ -16,10 +26,6 @@ static char *getelementpointer_inbounds_v0(char *base, unsigned long offset) {
// Potentially UB.
return base + offset;
}
-static char *getelementpointer_inbounds_v1(char *base, unsigned long offset) {
- // Potentially UB.
- return base + offset;
-}
int main(int argc, char *argv[]) {
char *base;
@@ -31,12 +37,8 @@ int main(int argc, char *argv[]) {
base = (char *)0;
offset = argc - 1;
(void)getelementpointer_inbounds_v0(base, offset);
- // CHECK-UB: {{.*}}.cpp:[[@LINE-17]]:15: runtime error: applying non-zero offset 1 to null pointer
-
- base = (char *)(intptr_t)(argc - 1);
- offset = argc == 1 ? 0 : -(argc - 1);
- (void)getelementpointer_inbounds_v1(base, offset);
- // CHECK-UB: {{.*}}.cpp:[[@LINE-18]]:15: runtime error: applying non-zero offset to non-null pointer {{.*}} produced null pointer
+ // CHECK-UB: {{.*}}.cpp:[[@LINE-13]]:15: runtime error: applying non-zero offset 1 to null pointer
+ // CHECK-UB-C: {{.*}}.cpp:[[@LINE-14]]:15: runtime error: applying zero offset to null pointer
return 0;
}