deref-track-symbolic-region.cpp revision 6cc4e25e76981ae47019bc47911724eaaf2f9a3f
1// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=text -verify %s
2
3struct S {
4  int *x;
5  int y;
6};
7
8S &getSomeReference();
9void test(S *p) {
10  S &r = *p;   //expected-note {{'r' initialized here}}
11  if (p) return;
12               //expected-note@-1{{Taking false branch}}
13               //expected-note@-2{{Assuming 'p' is null}}
14  r.y = 5; // expected-warning {{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}}
15           // expected-note@-1{{Access to field 'y' results in a dereference of a null pointer (loaded from variable 'r')}}
16}
17
18void testRefParam(int *ptr) {
19	int &ref = *ptr; // expected-note {{'ref' initialized here}}
20	if (ptr)
21    // expected-note@-1{{Assuming 'ptr' is null}}
22    // expected-note@-2{{Taking false branch}}
23		return;
24
25	extern void use(int &ref);
26	use(ref); // expected-warning{{Forming reference to null pointer}}
27            // expected-note@-1{{Forming reference to null pointer}}
28}