1*67e74705SXin Li // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=text -verify %s 2*67e74705SXin Li 3*67e74705SXin Li struct S { 4*67e74705SXin Li int *x; 5*67e74705SXin Li int y; 6*67e74705SXin Li }; 7*67e74705SXin Li 8*67e74705SXin Li S &getSomeReference(); test(S * p)9*67e74705SXin Livoid test(S *p) { 10*67e74705SXin Li S &r = *p; //expected-note {{'r' initialized here}} 11*67e74705SXin Li if (p) return; 12*67e74705SXin Li //expected-note@-1{{Taking false branch}} 13*67e74705SXin Li //expected-note@-2{{Assuming 'p' is null}} 14*67e74705SXin Li r.y = 5; // expected-warning {{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}} 15*67e74705SXin Li // expected-note@-1{{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}} 16*67e74705SXin Li } 17*67e74705SXin Li testRefParam(int * ptr)18*67e74705SXin Livoid testRefParam(int *ptr) { 19*67e74705SXin Li int &ref = *ptr; // expected-note {{'ref' initialized here}} 20*67e74705SXin Li if (ptr) 21*67e74705SXin Li // expected-note@-1{{Assuming 'ptr' is null}} 22*67e74705SXin Li // expected-note@-2{{Taking false branch}} 23*67e74705SXin Li return; 24*67e74705SXin Li 25*67e74705SXin Li extern void use(int &ref); 26*67e74705SXin Li use(ref); // expected-warning{{Forming reference to null pointer}} 27*67e74705SXin Li // expected-note@-1{{Forming reference to null pointer}} 28*67e74705SXin Li } 29*67e74705SXin Li testRefToNullPtr()30*67e74705SXin Liint testRefToNullPtr() { 31*67e74705SXin Li int *p = 0; // expected-note {{'p' initialized to a null pointer value}} 32*67e74705SXin Li int *const &p2 = p; // expected-note{{'p2' initialized here}} 33*67e74705SXin Li int *p3 = p2; // expected-note {{'p3' initialized to a null pointer value}} 34*67e74705SXin Li return *p3; // expected-warning {{Dereference of null pointer}} 35*67e74705SXin Li // expected-note@-1{{Dereference of null pointer}} 36*67e74705SXin Li } 37*67e74705SXin Li testRefToNullPtr2()38*67e74705SXin Liint testRefToNullPtr2() { 39*67e74705SXin Li int *p = 0; // expected-note {{'p' initialized to a null pointer value}} 40*67e74705SXin Li int *const &p2 = p;// expected-note{{'p2' initialized here}} 41*67e74705SXin Li return *p2; //expected-warning {{Dereference of null pointer}} 42*67e74705SXin Li // expected-note@-1{{Dereference of null pointer}} 43*67e74705SXin Li }