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