1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3 void clang_analyzer_eval(bool);
5 void usePointer(int * const *);
6 void useReference(int * const &);
14 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
16 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
20 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
22 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
26 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
28 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
32 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
34 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
42 void useStruct(Wrapper
&w
);
43 void useConstStruct(const Wrapper
&w
);
45 void testPointerStruct() {
51 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
53 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
57 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
59 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
67 void useStruct(RefWrapper
&w
);
68 void useConstStruct(const RefWrapper
&w
);
70 void testReferenceStruct() {
75 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
77 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
80 // FIXME: This test is split into two functions because region invalidation
81 // does not preserve reference bindings.
82 void testConstReferenceStruct() {
87 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
89 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
93 void usePointerPure(int * const *) __attribute__((pure
));
94 void usePointerConst(int * const *) __attribute__((const));
96 void testPureConst() {
104 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
105 clang_analyzer_eval(global
== -5); // expected-warning{{TRUE}}
108 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
109 clang_analyzer_eval(global
== -5); // expected-warning{{TRUE}}
112 clang_analyzer_eval(x
== 42); // expected-warning{{TRUE}}
113 clang_analyzer_eval(global
== -5); // expected-warning{{TRUE}}
116 clang_analyzer_eval(x
== 42); // expected-warning{{UNKNOWN}}
117 clang_analyzer_eval(global
== -5); // expected-warning{{UNKNOWN}}
128 void useAnything(void *);
129 void useAnythingConst(const void *);
131 void testInvalidationThroughBaseRegionPointer() {
135 clang_analyzer_eval(s1
.x
== 1); // expected-warning{{TRUE}}
136 clang_analyzer_eval(s1
.z
== 1); // expected-warning{{TRUE}}
137 // Not only passing a structure pointer through const pointer parameter,
138 // but also passing a field pointer through const pointer parameter
139 // should preserve the contents of the structure.
140 useAnythingConst(&(s1
.y
));
141 clang_analyzer_eval(s1
.x
== 1); // expected-warning{{TRUE}}
142 // FIXME: Should say "UNKNOWN", because it is not uncommon to
143 // modify a mutable member variable through const pointer.
144 clang_analyzer_eval(s1
.z
== 1); // expected-warning{{TRUE}}
145 useAnything(&(s1
.y
));
146 clang_analyzer_eval(s1
.x
== 1); // expected-warning{{UNKNOWN}}
150 void useFirstConstSecondNonConst(const void *x
, void *y
);
151 void useFirstNonConstSecondConst(void *x
, const void *y
);
153 void testMixedConstNonConstCalls() {
156 useFirstConstSecondNonConst(&(s2
.x
), &(s2
.y
));
157 clang_analyzer_eval(s2
.x
== 1); // expected-warning{{UNKNOWN}}
159 useFirstNonConstSecondConst(&(s2
.x
), &(s2
.y
));
160 clang_analyzer_eval(s2
.x
== 1); // expected-warning{{UNKNOWN}}
162 useFirstConstSecondNonConst(&(s2
.x
), &(s2
.y
));
163 clang_analyzer_eval(s2
.y
== 1); // expected-warning{{UNKNOWN}}
165 useFirstNonConstSecondConst(&(s2
.x
), &(s2
.y
));
166 clang_analyzer_eval(s2
.y
== 1); // expected-warning{{UNKNOWN}}