]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | // RUN: %clangxx -fsanitize=returns-nonnull-attribute -w %s -O3 -o %t |
2 | // RUN: %run %t foo 2>&1 | count 0 | |
92a42be0 | 3 | // RUN: %run %t 2>&1 | FileCheck %s |
2c00a5a8 XL |
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 | |
92a42be0 SL |
6 | |
7 | __attribute__((returns_nonnull)) char *foo(char *a); | |
8 | ||
9 | char *foo(char *a) { | |
2c00a5a8 XL |
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 | |
92a42be0 | 12 | return a; |
2c00a5a8 XL |
13 | } |
14 | ||
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; | |
24 | } | |
92a42be0 SL |
25 | } |
26 | ||
27 | int main(int argc, char **argv) { | |
2c00a5a8 XL |
28 | char *a = argv[1]; |
29 | ||
30 | foo(a); | |
31 | ||
32 | bar(20, a); | |
33 | ||
34 | // We expect to see a runtime error the first time we cover the "else"... | |
35 | bar(5, a); | |
36 | ||
37 | // ... but not a second time. | |
38 | // CHECK-NOT: runtime error | |
39 | bar(5, a); | |
40 | ||
41 | return 0; | |
92a42be0 | 42 | } |