1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s 2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file %s -o %t.plist 3 // RUN: %normalize_plist <%t.plist | diff -u %S/Inputs/expected-plists/method-call-path-notes.cpp.plist - 4 5 // Test warning about null or uninitialized pointer values used as instance member 6 // calls. 7 class TestInstanceCall { 8 public: 9 void foo() {} 10 }; 11 12 void test_ic() { 13 TestInstanceCall *p; // expected-note {{'p' declared without an initial value}} 14 p->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} expected-note {{Called C++ object pointer is uninitialized}} 15 } 16 17 void test_ic_null() { 18 TestInstanceCall *p = 0; // expected-note {{'p' initialized to a null pointer value}} 19 p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}} 20 } 21 22 void test_ic_set_to_null() { 23 TestInstanceCall *p; 24 p = 0; // expected-note {{Null pointer value stored to 'p'}} 25 p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}} 26 } 27 28 void test_ic_null(TestInstanceCall *p) { 29 if (!p) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}} 30 p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}} 31 } 32 33 void test_ic_member_ptr() { 34 TestInstanceCall *p = 0; // expected-note {{'p' initialized to a null pointer value}} 35 typedef void (TestInstanceCall::*IC_Ptr)(); 36 IC_Ptr bar = &TestInstanceCall::foo; 37 (p->*bar)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}} 38 } 39 40 void test_cast(const TestInstanceCall *p) { 41 if (!p) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}} 42 const_cast<TestInstanceCall *>(p)->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}} 43 } 44 45