1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection %s -verify
3 void clang_analyzer_eval(int);
6 typedef struct bf
{ unsigned x
:2; } bf
;
9 *(unsigned*)&y
= foo();
19 int *p
= &(a
.n
) + 1; // expected-warning{{Pointer arithmetic on}}
29 (void)(p
= getit()).x
;
32 #define true ((bool)1)
33 #define false ((bool)0)
37 void testLazyCompoundVal(void) {
40 clang_analyzer_eval((q
= p
).x
== 42); // expected-warning{{TRUE}}
41 clang_analyzer_eval(q
.x
== 42); // expected-warning{{TRUE}}
61 void testBitfields(void) {
64 if (foo() && bits
.b
) // expected-warning {{garbage}}
66 if (foo() && bits
.inner
.e
) // expected-warning {{garbage}}
70 clang_analyzer_eval(bits
.c
== 1); // expected-warning {{TRUE}}
72 if (foo() && bits
.b
) // expected-warning {{garbage}}
74 if (foo() && bits
.x
) // expected-warning {{garbage}}
78 clang_analyzer_eval(bits
.x
== true); // expected-warning{{TRUE}}
80 clang_analyzer_eval(bits
.x
== true); // expected-warning{{TRUE}}
81 if (foo() && bits
.c
) // no-warning
85 if (foo() && bits
.inner
.e
) // no-warning
87 if (foo() && bits
.inner
.y
) // expected-warning {{garbage}}
89 if (foo() && bits
.inner
.f
) // expected-warning {{garbage}}
92 extern struct InnerBits
getInner(void);
93 bits
.inner
= getInner();
95 if (foo() && bits
.inner
.e
) // no-warning
97 if (foo() && bits
.inner
.y
) // no-warning
99 if (foo() && bits
.inner
.f
) // no-warning
104 if (foo() && bits
.inner
.e
) // no-warning
106 if (foo() && bits
.inner
.y
) // no-warning
108 if (foo() && bits
.inner
.f
) // no-warning
111 if (foo() && bits
.a
) // expected-warning {{garbage}}
116 //-----------------------------------------------------------------------------
117 // Incorrect behavior
118 //-----------------------------------------------------------------------------
120 void testTruncation(void) {
122 bits
.c
= 0x11; // expected-warning{{implicit truncation}}
123 // FIXME: We don't model truncation of bitfields.
124 clang_analyzer_eval(bits
.c
== 1); // expected-warning {{FALSE}}