1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3 void clang_analyzer_eval(int);
5 #include "Inputs/system-header-simulator.h"
12 clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
16 const int &globalIntRef = 42;
18 void testGlobalRef() {
19 // FIXME: Should be TRUE, but should at least not crash.
20 clang_analyzer_eval(globalIntRef == 42); // expected-warning{{UNKNOWN}}
27 extern struct IntWrapper globalStruct;
28 extern void invalidateGlobals();
30 void testGlobalInvalidation() {
31 clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
32 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
36 if (globalStruct.value != 43)
38 clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
39 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
42 clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
43 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
45 // Repeat to make sure we don't get the /same/ new symbolic values.
48 if (globalStruct.value != 43)
50 clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
51 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
54 clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
55 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
58 void testGlobalInvalidationWithDirectBinding() {
59 clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
60 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
63 globalStruct.value = 43;
64 clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
65 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
68 clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
69 clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
72 void testStaticLocals(void) {
76 extern int someSymbolicValue();
77 i = someSymbolicValue();
80 clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
82 clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
84 clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
88 clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
90 clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
92 clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
94 i = someSymbolicValue();
96 clang_analyzer_eval(i == 7); // expected-warning{{TRUE}}
98 clang_analyzer_eval(i == 7); // expected-warning{{UNKNOWN}}
102 clang_analyzer_eval(i == 8); // expected-warning{{TRUE}}
104 clang_analyzer_eval(i == 8); // expected-warning{{UNKNOWN}}
107 void testNonSystemGlobals(void) {
112 clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
114 clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
116 clang_analyzer_eval(i == 5); // expected-warning{{UNKNOWN}}
120 clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
122 clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
124 clang_analyzer_eval(i == 6); // expected-warning{{UNKNOWN}}
127 clang_analyzer_eval(i == 7); // expected-warning{{TRUE}}
129 clang_analyzer_eval(i == 7); // expected-warning{{UNKNOWN}}
133 clang_analyzer_eval(i == 8); // expected-warning{{TRUE}}
135 clang_analyzer_eval(i == 8); // expected-warning{{UNKNOWN}}
138 void testWrappedGlobals(void) {
144 clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
145 fakeSystemHeaderCall(0);
146 clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
147 fakeSystemHeaderCall(&s);
148 clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
153 clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
154 fakeSystemHeaderCall(0);
155 clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
156 fakeSystemHeaderCall(&s);
157 clang_analyzer_eval(c == 'c'); // expected-warning{{UNKNOWN}}
161 clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
162 fakeSystemHeaderCall(0);
163 clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
164 fakeSystemHeaderCall(&s);
165 clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
169 void testWrappedStaticsViaGlobal(void) {
173 extern char getSomeChar();
178 clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
180 clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
185 clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
187 clang_analyzer_eval(c == 'c'); // expected-warning{{UNKNOWN}}