1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-ipa=inlining -analyzer-output=text -verify %s
2 
3 // Test warning about null or uninitialized pointer values used as instance member
4 // calls.
5 class TestInstanceCall {
6 public:
7   void foo() {}
8 };
9 
10 void test_ic() {
11   TestInstanceCall *p; // expected-note {{Variable 'p' declared without an initial value}}
12   p->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} expected-note {{Called C++ object pointer is uninitialized}}
13 }
14 
15 void test_ic_null() {
16   TestInstanceCall *p = 0; // expected-note {{Variable 'p' initialized to a null pointer value}}
17   p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
18 }
19 
20 void test_ic_set_to_null() {
21   TestInstanceCall *p;
22   p = 0; // expected-note {{Null pointer value stored to 'p'}}
23   p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
24 }
25 
26 void test_ic_null(TestInstanceCall *p) {
27   if (!p) // expected-note {{Assuming pointer value is null}} expected-note {{Taking true branch}}
28     p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
29 }
30 
31 void test_ic_member_ptr() {
32   TestInstanceCall *p = 0; // expected-note {{Variable 'p' initialized to a null pointer value}}
33   typedef void (TestInstanceCall::*IC_Ptr)();
34   IC_Ptr bar = &TestInstanceCall::foo;
35   (p->*bar)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
36 }
37