1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
3 void clang_analyzer_eval(bool);
5 typedef struct Opaque
*Data
;
10 struct Child
: public IntWrapper
{
11 void set() { x
= 42; }
14 void test(Data data
) {
15 Child
*wrapper
= reinterpret_cast<Child
*>(data
);
16 // Don't crash when upcasting here.
17 // We don't actually know if 'data' is a Child.
19 clang_analyzer_eval(wrapper
->x
== 42); // expected-warning{{TRUE}}
24 class Derived1
: public Base1
{};
29 class Derived2
: public Base2
{};
43 f3(reinterpret_cast<void**>(&p
));
44 // Don't crash when upcasting here.
45 // In this case, 'p' actually refers to a Derived1.
50 namespace rdar13249297
{
51 struct IntWrapperSubclass
: public IntWrapper
{};
53 struct IntWrapperWrapper
{
57 void test(IntWrapperWrapper
*ww
) {
58 reinterpret_cast<IntWrapperSubclass
*>(ww
)->x
= 42;
59 clang_analyzer_eval(reinterpret_cast<IntWrapperSubclass
*>(ww
)->x
== 42); // expected-warning{{TRUE}}
61 clang_analyzer_eval(ww
->w
.x
== 42); // expected-warning{{TRUE}}
64 clang_analyzer_eval(reinterpret_cast<IntWrapperSubclass
*>(ww
)->x
== 42); // expected-warning{{FALSE}}
77 class Derived
: public Base
{};
81 *(reinterpret_cast<void**>(&p
)) = new C
;
84 // We should still be able to do some reasoning about bindings.
86 clang_analyzer_eval(p
->x
== 42); // expected-warning{{TRUE}}
90 int trackpointer_std_addressof() {
92 int *p
= (int*)&reinterpret_cast<const volatile char&>(x
);
94 return x
; // no warning
99 int radar_13146953(void) {
104 return *x
+ *y
; // no warning
112 struct Derived
: Base
{ };
115 Derived
&d
= (Derived
&)(p
);