blob: aaa600e4b96e58c4c5334f54153728240fbb5b48 (
plain)
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
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s
void clang_analyzer_eval(bool);
typedef struct Opaque *Data;
struct IntWrapper {
int x;
};
struct Child : public IntWrapper {
void set() { x = 42; }
};
void test(Data data) {
Child *wrapper = reinterpret_cast<Child*>(data);
// Don't crash when upcasting here.
// We don't actually know if 'data' is a Child.
wrapper->set();
clang_analyzer_eval(wrapper->x == 42); // expected-warning{{TRUE}}
}
namespace PR14872 {
class Base1 {};
class Derived1 : public Base1 {};
Derived1 *f1();
class Base2 {};
class Derived2 : public Base2 {};
void f2(Base2 *foo);
void f3(void** out)
{
Base1 *v;
v = f1();
*out = v;
}
void test()
{
Derived2 *p;
f3(reinterpret_cast<void**>(&p));
// Don't crash when upcasting here.
// In this case, 'p' actually refers to a Derived1.
f2(p);
}
}
|