brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · a37bbfe Raw
61 lines · cpp
1// RUN: %clang_analyze_cc1 -w -x c++ -analyzer-checker=core -analyzer-output=text -verify %s2 3namespace pr34731 {4int b;5class c {6  class B {7   public:8    double ***d;9    B();10  };11  void e(double **, int);12  void f(B &, int &);13};14 15// Properly track the null pointer in the array field back to the default16// constructor of 'h'.17void c::f(B &g, int &i) {18  e(g.d[9], i); // expected-warning{{Array access (via field 'd') results in a null pointer dereference}}19                // expected-note@-1{{Array access (via field 'd') results in a null pointer dereference}}20  B h, a; // expected-note{{Value assigned to 'h.d'}}21  a.d == __null; // expected-note{{Assuming the condition is true}}22  a.d != h.d; // expected-note{{Assuming 'a.d' is equal to 'h.d'}}23  f(h, b); // expected-note{{Calling 'c::f'}}24}25}26 27namespace GH124975 {28void no_crash_in_br_visitors(int *p) {29  if (p) {}30  // expected-note@-1 {{Assuming 'p' is null}}31  // expected-note@-2 {{Taking false branch}}32 33  extern bool ExternLocalCoin;34  // expected-note@+2 {{Assuming 'ExternLocalCoin' is false}}35  // expected-note@+1 {{Taking false branch}}36  if (ExternLocalCoin)37    return;38 39  *p = 4;40  // expected-warning@-1 {{Dereference of null pointer (loaded from variable 'p')}}41  // expected-note@-2    {{Dereference of null pointer (loaded from variable 'p')}}42}43 44// Thread local variables are implicitly static, so let's test them too.45void thread_local_alternative(int *p) {46  if (p) {}47  // expected-note@-1 {{Assuming 'p' is null}}48  // expected-note@-2 {{Taking false branch}}49 50  thread_local bool ThreadLocalCoin;51  // expected-note@+2 {{'ThreadLocalCoin' is false}}52  // expected-note@+1 {{Taking false branch}}53  if (ThreadLocalCoin)54    return;55 56  *p = 4;57  // expected-warning@-1 {{Dereference of null pointer (loaded from variable 'p')}}58  // expected-note@-2    {{Dereference of null pointer (loaded from variable 'p')}}59}60} // namespace GH12497561