1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -fblocks -verify -Wno-objc-root-class -analyzer-config eagerly-assume=false %s
3 void clang_analyzer_eval(int);
13 void testInvalidation(Root *obj) {
14 int savedID = obj->uniqueID;
15 clang_analyzer_eval(savedID == obj->uniqueID); // expected-warning{{TRUE}}
18 clang_analyzer_eval(savedID == obj->uniqueID); // expected-warning{{UNKNOWN}}
22 @interface Child : Root
26 - (void)testSuperInvalidation {
27 int savedID = self->uniqueID;
28 clang_analyzer_eval(savedID == self->uniqueID); // expected-warning{{TRUE}}
31 clang_analyzer_eval(savedID == self->uniqueID); // expected-warning{{UNKNOWN}}
36 @interface ManyIvars {
37 struct S { int a, b; } s;
45 @implementation ManyIvars
47 - (void)testMultipleIvarInvalidation:(int)useConstraints {
61 clang_analyzer_eval(s.a == 1); // expected-warning{{TRUE}}
62 clang_analyzer_eval(s.b == 2); // expected-warning{{TRUE}}
63 clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
64 clang_analyzer_eval(d == 4); // expected-warning{{TRUE}}
68 clang_analyzer_eval(s.a == 1); // expected-warning{{TRUE}}
69 clang_analyzer_eval(s.b == 2); // expected-warning{{TRUE}}
70 clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
71 clang_analyzer_eval(d == 0); // expected-warning{{TRUE}}
76 clang_analyzer_eval(s.a == 1); // expected-warning{{UNKNOWN}}
77 clang_analyzer_eval(s.b == 2); // expected-warning{{UNKNOWN}}
78 clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
79 clang_analyzer_eval(d == 4); // expected-warning{{TRUE}}
83 clang_analyzer_eval(s.a == 1); // expected-warning{{TRUE}}
84 clang_analyzer_eval(s.b == 2); // expected-warning{{UNKNOWN}}
85 clang_analyzer_eval(c == 3); // expected-warning{{TRUE}}
86 clang_analyzer_eval(d == 4); // expected-warning{{TRUE}}
89 + (void)testMultipleIvarInvalidation:(int)useConstraints
90 forObject:(ManyIvars *)obj {
92 if (obj->s.a != 1) return;
93 if (obj->s.b != 2) return;
94 if (obj->c != 3) return;
95 if (obj->d != 4) return;
104 clang_analyzer_eval(obj->s.a == 1); // expected-warning{{TRUE}}
105 clang_analyzer_eval(obj->s.b == 2); // expected-warning{{TRUE}}
106 clang_analyzer_eval(obj->c == 3); // expected-warning{{TRUE}}
107 clang_analyzer_eval(obj->d == 4); // expected-warning{{TRUE}}
111 clang_analyzer_eval(obj->s.a == 1); // expected-warning{{TRUE}}
112 clang_analyzer_eval(obj->s.b == 2); // expected-warning{{TRUE}}
113 clang_analyzer_eval(obj->c == 3); // expected-warning{{TRUE}}
114 clang_analyzer_eval(obj->d == 0); // expected-warning{{TRUE}}
119 clang_analyzer_eval(obj->s.a == 1); // expected-warning{{UNKNOWN}}
120 clang_analyzer_eval(obj->s.b == 2); // expected-warning{{UNKNOWN}}
121 clang_analyzer_eval(obj->c == 3); // expected-warning{{TRUE}}
122 clang_analyzer_eval(obj->d == 4); // expected-warning{{TRUE}}
126 clang_analyzer_eval(obj->s.a == 1); // expected-warning{{TRUE}}
127 clang_analyzer_eval(obj->s.b == 2); // expected-warning{{UNKNOWN}}
128 clang_analyzer_eval(obj->c == 3); // expected-warning{{TRUE}}
129 clang_analyzer_eval(obj->d == 4); // expected-warning{{TRUE}}
135 int testNull(Root *obj) {
138 int *x = &obj->uniqueID;
139 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}