summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/returns_nonnull-attribute.cpp
blob: 32d7b5200ef33d648fe8663ba3e2969c4dc62a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// RUN: %clang_analyze_cc1 -analyzer-checker=core,apiModeling.TrustReturnsNonnull -verify %s

int *foo() __attribute__((returns_nonnull));

int *foo_no_attribute();

int test_foo() {
  int *x = foo();
  if (x) {}
  return *x; // no-warning
}

int test_foo_no_attribute() {
  int *x = foo_no_attribute();
  if (x) {}
  return *x;  // expected-warning{{Dereference of null pointer}}
}

void test(void *(*f)(void)) {
  f();  // Shouldn't crash compiler
}