global_region_invalidation.mm
5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
void clang_analyzer_eval(int);
#include "Inputs/system-header-simulator.h"
void use(int);
id foo(int x) {
if (x)
return 0;
static id p = foo(1);
clang_analyzer_eval(p == 0); // expected-warning{{TRUE}}
return p;
}
const int &globalIntRef = 42;
void testGlobalRef() {
// FIXME: Should be TRUE, but should at least not crash.
clang_analyzer_eval(globalIntRef == 42); // expected-warning{{UNKNOWN}}
}
extern int globalInt;
struct IntWrapper {
int value;
};
extern struct IntWrapper globalStruct;
extern void invalidateGlobals();
void testGlobalInvalidation() {
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
if (globalInt != 42)
return;
if (globalStruct.value != 43)
return;
clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
// Repeat to make sure we don't get the /same/ new symbolic values.
if (globalInt != 42)
return;
if (globalStruct.value != 43)
return;
clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
}
void testGlobalInvalidationWithDirectBinding() {
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
globalInt = 42;
globalStruct.value = 43;
clang_analyzer_eval(globalInt == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(globalInt == 42); // expected-warning{{UNKNOWN}}
clang_analyzer_eval(globalStruct.value == 43); // expected-warning{{UNKNOWN}}
}
void testStaticLocals(void) {
static int i;
int tmp;
extern int someSymbolicValue();
i = someSymbolicValue();
if (i == 5) {
clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
scanf("%d", &tmp);
clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
}
i = 6;
clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
scanf("%d", &tmp);
clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
i = someSymbolicValue();
if (i == 7) {
clang_analyzer_eval(i == 7); // expected-warning{{TRUE}}
scanf("%d", &i);
clang_analyzer_eval(i == 7); // expected-warning{{UNKNOWN}}
}
i = 8;
clang_analyzer_eval(i == 8); // expected-warning{{TRUE}}
scanf("%d", &i);
clang_analyzer_eval(i == 8); // expected-warning{{UNKNOWN}}
}
void testNonSystemGlobals(void) {
extern int i;
int tmp;
if (i == 5) {
clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
scanf("%d", &tmp);
clang_analyzer_eval(i == 5); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(i == 5); // expected-warning{{UNKNOWN}}
}
i = 6;
clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
scanf("%d", &tmp);
clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(i == 6); // expected-warning{{UNKNOWN}}
if (i == 7) {
clang_analyzer_eval(i == 7); // expected-warning{{TRUE}}
scanf("%d", &i);
clang_analyzer_eval(i == 7); // expected-warning{{UNKNOWN}}
}
i = 8;
clang_analyzer_eval(i == 8); // expected-warning{{TRUE}}
scanf("%d", &i);
clang_analyzer_eval(i == 8); // expected-warning{{UNKNOWN}}
}
void testWrappedGlobals(void) {
extern char c;
SomeStruct s;
if (c == 'C') {
s.p = &c;
clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(0);
clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(&s);
clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
}
c = 'c';
s.p = &c;
clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(0);
clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(&s);
clang_analyzer_eval(c == 'c'); // expected-warning{{UNKNOWN}}
if (c == 'C') {
s.p = &c;
clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(0);
clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
fakeSystemHeaderCall(&s);
clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
}
}
void testWrappedStaticsViaGlobal(void) {
static char c;
extern SomeStruct s;
extern char getSomeChar();
c = getSomeChar();
if (c == 'C') {
s.p = &c;
clang_analyzer_eval(c == 'C'); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(c == 'C'); // expected-warning{{UNKNOWN}}
}
c = 'c';
s.p = &c;
clang_analyzer_eval(c == 'c'); // expected-warning{{TRUE}}
invalidateGlobals();
clang_analyzer_eval(c == 'c'); // expected-warning{{UNKNOWN}}
}