Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / ubsan / TestCases / Misc / nonnull.cpp
blobc612cd8247156d5f0ceba300f59215cf0ee0dad4
1 // RUN: %clangxx -fsanitize=returns-nonnull-attribute -w %s -O3 -o %t
2 // RUN: %run %t foo 2>&1 | FileCheck %s --check-prefix=NOERROR --allow-empty --implicit-check-not='runtime error'
3 // RUN: %run %t 2>&1 | FileCheck %s
4 // RUN: %clangxx -fsanitize=returns-nonnull-attribute -fno-sanitize-recover=returns-nonnull-attribute -w %s -O3 -o %t.abort
5 // RUN: not %run %t.abort &> /dev/null
7 __attribute__((returns_nonnull)) char *foo(char *a);
9 char *foo(char *a) {
10 // CHECK: nonnull.cpp:[[@LINE+2]]:3: runtime error: null pointer returned from function declared to never return null
11 // CHECK-NEXT: nonnull.cpp:[[@LINE-4]]:16: note: returns_nonnull attribute specified here
12 return a;
15 __attribute__((returns_nonnull)) char *bar(int x, char *a) {
16 if (x > 10) {
17 // CHECK: nonnull.cpp:[[@LINE+2]]:5: runtime error: null pointer returned from function declared to never return null
18 // CHECK-NEXT: nonnull.cpp:[[@LINE-3]]:16: note: returns_nonnull attribute specified here
19 return a;
20 } else {
21 // CHECK: nonnull.cpp:[[@LINE+2]]:5: runtime error: null pointer returned from function declared to never return null
22 // CHECK-NEXT: nonnull.cpp:[[@LINE-7]]:16: note: returns_nonnull attribute specified here
23 return a;
27 int main(int argc, char **argv) {
28 char *a = argv[1];
30 foo(a);
32 bar(20, a);
34 // We expect to see a runtime error the first time we cover the "else"...
35 bar(5, a);
37 // ... but not a second time.
38 // CHECK-NOT: runtime error
39 bar(5, a);
41 return 0;
44 // NOERROR-NOT: runtime error