1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3 void clang_analyzer_eval(bool);
10 void testImplicitThisSyntax() {
13 clang_analyzer_eval(x
== 3); // expected-warning{{TRUE}}
15 clang_analyzer_eval(x
== 3); // expected-warning{{UNKNOWN}}
33 struct MutDerived
: MutBase
{
41 struct PDerived
: PBase
{
57 void checkThatConstMethodWithoutDefinitionDoesNotInvalidateObject() {
61 clang_analyzer_eval(t
.x
== 3); // expected-warning{{TRUE}}
62 // Test non-const does invalidate
64 clang_analyzer_eval(t
.x
); // expected-warning{{UNKNOWN}}
67 void checkThatConstMethodDoesInvalidateMutableFields() {
71 clang_analyzer_eval(t
.mut
); // expected-warning{{UNKNOWN}}
74 void checkThatConstMethodDoesInvalidatePointedAtMemory() {
79 clang_analyzer_eval(x
); // expected-warning{{UNKNOWN}}
80 clang_analyzer_eval(t
.p
== &x
); // expected-warning{{TRUE}}
83 void checkThatConstMethodDoesInvalidateInheritedMutableFields() {
87 clang_analyzer_eval(t
.b_mut
); // expected-warning{{UNKNOWN}}
90 void checkThatConstMethodDoesInvalidateInheritedPointedAtMemory() {
95 clang_analyzer_eval(x
); // expected-warning{{UNKNOWN}}
96 clang_analyzer_eval(t
.p
== &x
); // expected-warning{{TRUE}}
99 void checkThatConstMethodDoesInvalidateContainedPointedAtMemory() {
105 clang_analyzer_eval(x
); // expected-warning{{UNKNOWN}}
106 clang_analyzer_eval(t
.x
== 2); // expected-warning{{TRUE}}
107 clang_analyzer_eval(t
.in
.p
== &x
); // expected-warning{{TRUE}}
110 void checkThatContainedConstMethodDoesNotInvalidateObjects() {
115 clang_analyzer_eval(t
.x
== 1); // expected-warning{{TRUE}}
116 clang_analyzer_eval(t
.in
.x
== 2); // expected-warning{{TRUE}}
119 void checkPointerTypedThisExpression(A
*a
) {
122 clang_analyzer_eval(a
->x
== 3); // expected-warning{{TRUE}}
124 clang_analyzer_eval(a
->x
== 3); // expected-warning{{UNKNOWN}}
127 void checkReferenceTypedThisExpression(A
&a
) {
130 clang_analyzer_eval(a
.x
== 3); // expected-warning{{TRUE}}
132 clang_analyzer_eval(a
.x
== 3); // expected-warning{{UNKNOWN}}
135 // --- Versions of the above tests where the const method is inherited --- //
141 struct D1
: public B1
{
145 struct D2
: public B1
{
149 struct D3
: public B1
{
153 struct DInner
: public B1
{
158 struct DOuter
: public B1
{
163 void checkThatInheritedConstMethodDoesNotInvalidateObject() {
167 clang_analyzer_eval(t
.x
== 1); // expected-warning{{TRUE}}
170 void checkThatInheritedConstMethodDoesInvalidateMutableFields() {
174 clang_analyzer_eval(t
.mut
); // expected-warning{{UNKNOWN}}
177 void checkThatInheritedConstMethodDoesInvalidatePointedAtMemory() {
182 clang_analyzer_eval(x
); // expected-warning{{UNKNOWN}}
183 clang_analyzer_eval(t
.p
== &x
); // expected-warning{{TRUE}}
186 void checkThatInheritedConstMethodDoesInvalidateContainedPointedAtMemory() {
193 clang_analyzer_eval(x
); // expected-warning{{UNKNOWN}}
194 clang_analyzer_eval(t
.x
== 2); // expected-warning{{TRUE}}
195 clang_analyzer_eval(t
.in
.x
== 3); // expected-warning{{TRUE}}
196 clang_analyzer_eval(t
.in
.p
== &x
); // expected-warning{{TRUE}}
199 void checkThatInheritedContainedConstMethodDoesNotInvalidateObjects() {
204 clang_analyzer_eval(t
.x
== 1); // expected-warning{{TRUE}}
205 clang_analyzer_eval(t
.in
.x
== 2); // expected-warning{{TRUE}}
208 // --- PR21606 --- //
211 void g(const int *i
) const;
219 *i
= 42; // no-warning
231 // --- PR25392 --- //
233 struct HasConstMemberFunction
{
235 void constMemberFunction() const;
238 HasConstMemberFunction
hasNoReturn() { } // expected-warning {{non-void function does not return a value}}
240 void testUnknownWithConstMemberFunction() {
241 hasNoReturn().constMemberFunction();
244 void testNonRegionLocWithConstMemberFunction() {
245 (*((HasConstMemberFunction
*)(&&label
))).constMemberFunction();
251 // When there is a circular reference to an object and a const method is called
252 // the object is not invalidated because TK_PreserveContents has already been
256 struct InnerWithRef
{
266 void checkThatConstMethodCallDoesInvalidateObjectForCircularReferences() {
271 // FIXME: Should be UNKNOWN.
272 clang_analyzer_eval(t
.x
); // expected-warning{{TRUE}}