blob: 4eaed9fed13c5b23eceda957bfc9b4e5f09dd0d0 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify %s
void clang_analyzer_eval(bool);
void clang_analyzer_checkInlined(bool);
class A {
public:
int getZero() { return 0; }
virtual int getNum() { return 0; }
};
void test(A &a) {
clang_analyzer_eval(a.getZero() == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(a.getNum() == 0); // expected-warning{{UNKNOWN}}
A copy(a);
clang_analyzer_eval(copy.getZero() == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(copy.getNum() == 0); // expected-warning{{TRUE}}
}
class One : public A {
public:
virtual int getNum() { return 1; }
};
void testPathSensitivity(int x) {
A a;
One b;
A *ptr;
switch (x) {
case 0:
ptr = &a;
break;
case 1:
ptr = &b;
break;
default:
return;
}
// This should be true on both branches.
clang_analyzer_eval(ptr->getNum() == x); // expected-warning {{TRUE}}
}
namespace PureVirtualParent {
class Parent {
public:
virtual int pureVirtual() const = 0;
int callVirtual() const {
return pureVirtual();
}
};
class Child : public Parent {
public:
virtual int pureVirtual() const {
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
return 42;
}
};
void testVirtual() {
Child x;
clang_analyzer_eval(x.pureVirtual() == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(x.callVirtual() == 42); // expected-warning{{TRUE}}
}
}
namespace PR13569 {
class Parent {
protected:
int m_parent;
virtual int impl() const = 0;
Parent() : m_parent(0) {}
public:
int interface() const {
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
return impl();
}
};
class Child : public Parent {
protected:
virtual int impl() const {
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
return m_parent + m_child;
}
public:
Child() : m_child(0) {}
int m_child;
};
void testVirtual() {
Child x;
x.m_child = 42;
// Don't crash when inlining and devirtualizing.
x.interface();
}
class Grandchild : public Child {};
void testDevirtualizeToMiddle() {
Grandchild x;
x.m_child = 42;
// Don't crash when inlining and devirtualizing.
x.interface();
}
}
namespace PR13569_virtual {
class Parent {
protected:
int m_parent;
virtual int impl() const = 0;
Parent() : m_parent(0) {}
public:
int interface() const {
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
return impl();
}
};
class Child : virtual public Parent {
protected:
virtual int impl() const {
clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
return m_parent + m_child;
}
public:
Child() : m_child(0) {}
int m_child;
};
void testVirtual() {
Child x;
x.m_child = 42;
// Don't crash when inlining and devirtualizing.
x.interface();
}
class Grandchild : virtual public Child {};
void testDevirtualizeToMiddle() {
Grandchild x;
x.m_child = 42;
// Don't crash when inlining and devirtualizing.
x.interface();
}
}
|