44 lines · cpp
1// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-config exploration_strategy=unexplored_first -analyzer-output=text -verify %s2// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-config exploration_strategy=unexplored_first_queue -analyzer-output=text -verify %s3 4extern int coin();5 6int foo() {7 int *x = 0; // expected-note {{'x' initialized to a null pointer value}}8 while (coin()) { // expected-note{{Loop condition is true}}9 if (coin()) // expected-note {{Taking true branch}}10 // expected-note@-1 {{Assuming the condition is true}}11 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}12 // expected-note@-1{{Dereference of null pointer (loaded from variable 'x')}}13 }14 return 0;15}16 17void bar() {18 while(coin())19 if (coin())20 foo();21}22 23int foo2() {24 int *x = 0; // expected-note {{'x' initialized to a null pointer value}}25 while (coin()) { // expected-note{{Loop condition is true}}26 if (coin()) // expected-note {{Taking false branch}}27 // expected-note@-1 {{Assuming the condition is false}}28 return false;29 else30 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}31 // expected-note@-1{{Dereference of null pointer (loaded from variable 'x')}}32 }33 return 0;34}35 36void bar2() {37 while(coin()) // expected-note{{Loop condition is true}}38 if (coin()) // expected-note {{Assuming the condition is false}}39 // expected-note@-1 {{Taking false branch}}40 return;41 else42 foo(); // expected-note{{Calling 'foo'}}43}44