brintos

brintos / llvm-project-archived public Read only

0
0
Text · 452 B · 32d7b52 Raw
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