clang/test/Analysis/returns_nonnull-attribute.cpp
raw| 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,apiModeling.TrustReturnsNonnull -verify %s |
| 2 | |
| 3 | int *foo() __attribute__((returns_nonnull)); |
| 4 | |
| 5 | int *foo_no_attribute(); |
| 6 | |
| 7 | int test_foo() { |
| 8 | int *x = foo(); |
| 9 | if (x) {} |
| 10 | return *x; // no-warning |
| 11 | } |
| 12 | |
| 13 | int test_foo_no_attribute() { |
| 14 | int *x = foo_no_attribute(); |
| 15 | if (x) {} |
| 16 | return *x; // expected-warning{{Dereference of null pointer}} |
| 17 | } |
| 18 | |
| 19 | void test(void *(*f)(void)) { |
| 20 | f(); // Shouldn't crash compiler |
| 21 | } |