[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / ctor-bug-path.cpp
blob107e5b0c3389c6ea3ec878f6763009c29956a385
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-output=text -std=c++11 -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-output=text -std=c++17 -verify %s
4 #include "Inputs/system-header-simulator-cxx.h"
6 namespace copyMoveTrackCtor {
7 struct S {
8 int *p1, *p2;
9 S(int *a, int *b) : p1(a), p2(b) {} // expected-note{{Null pointer value stored to 's.p1'}}
12 void CtorDirect() {
13 int *x = nullptr, *y = nullptr;
14 // expected-note@-1{{'x' initialized to a null pointer value}}
16 S s(x, y);
17 // expected-note@-1{{Passing null pointer value via 1st parameter 'a'}}
18 // expected-note@-2{{Calling constructor for 'S'}}
19 // expected-note@-3{{Returning from constructor for 'S'}}
20 // expected-note@-4{{'s' initialized here}}
21 S s2 = s; // expected-note{{Null pointer value stored to 's2.p1'}}
22 // expected-note@-1{{'s2' initialized here}}
23 S s3 = s2; // expected-note{{Null pointer value stored to 's3.p1'}}
24 // expected-note@-1{{'s3' initialized here}}
25 S s4 = std::move(s3); // expected-note{{Null pointer value stored to 's4.p1'}}
26 // expected-note@-1{{'s4' initialized here}}
27 S s5 = s4; // expected-note{{Null pointer value stored to 's5.p1'}}
29 int i = *s5.p1; // expected-warning{{Dereference of null pointer}}
30 // expected-note@-1{{Dereference of null pointer (loaded from field 'p1')}}
32 (void) i;
34 } // namespace copyMoveTrackCtor
36 namespace copyMoveTrackInitList {
37 struct S {
38 int *p1, *p2;
41 void InitListDirect() {
42 int *x = nullptr, *y = nullptr; //expected-note{{'x' initialized to a null pointer value}}
44 S s{x, y}; //expected-note{{'s.p1' initialized to a null pointer value}}
45 //expected-note@-1{{'s' initialized here}}
46 S s2 = s; // expected-note{{Null pointer value stored to 's2.p1'}}
47 // expected-note@-1{{'s2' initialized here}}
48 S s3 = s2; // expected-note{{Null pointer value stored to 's3.p1'}}
49 // expected-note@-1{{'s3' initialized here}}
50 S s4 = std::move(s3); // expected-note{{Null pointer value stored to 's4.p1'}}
51 // expected-note@-1{{'s4' initialized here}}
52 S s5 = s4; // expected-note{{Null pointer value stored to 's5.p1'}}
54 int i = *s5.p1; // expected-warning{{Dereference of null pointer}}
55 // expected-note@-1{{Dereference of null pointer (loaded from field 'p1')}}
57 (void) i;
60 void InitListAssign() {
61 int *x = nullptr, *y = nullptr; //expected-note{{'x' initialized to a null pointer value}}
63 S s = {x, y}; //expected-note{{'s.p1' initialized to a null pointer value}}
64 //expected-note@-1{{'s' initialized here}}
65 S s2 = s; // expected-note{{Null pointer value stored to 's2.p1'}}
66 // expected-note@-1{{'s2' initialized here}}
67 S s3 = s2; // expected-note{{Null pointer value stored to 's3.p1'}}
68 // expected-note@-1{{'s3' initialized here}}
69 S s4 = std::move(s3); // expected-note{{Null pointer value stored to 's4.p1'}}
70 // expected-note@-1{{'s4' initialized here}}
71 S s5 = s4; // expected-note{{Null pointer value stored to 's5.p1'}}
73 int i = *s5.p1; // expected-warning{{Dereference of null pointer}}
74 // expected-note@-1{{Dereference of null pointer (loaded from field 'p1')}}
76 (void) i;
79 } // namespace copyMoveTrackInitList
81 namespace copyMoveTrackCtorMemberInitList {
82 struct S {
83 int *p1, *p2;
84 S(int *a, int *b) : p1{a}, p2{b} {} // expected-note{{Null pointer value stored to 's.p1'}}
87 void CtorDirect() {
88 int *x = nullptr, *y = nullptr;
89 // expected-note@-1{{'x' initialized to a null pointer value}}
91 S s{x, y};
92 // expected-note@-1{{Passing null pointer value via 1st parameter 'a'}}
93 // expected-note@-2{{Calling constructor for 'S'}}
94 // expected-note@-3{{Returning from constructor for 'S'}}
95 // expected-note@-4{{'s' initialized here}}
96 S s2 = s; // expected-note{{Null pointer value stored to 's2.p1'}}
97 // expected-note@-1{{'s2' initialized here}}
98 S s3 = s2; // expected-note{{Null pointer value stored to 's3.p1'}}
99 // expected-note@-1{{'s3' initialized here}}
100 S s4 = std::move(s3); // expected-note{{Null pointer value stored to 's4.p1'}}
101 // expected-note@-1{{'s4' initialized here}}
102 S s5 = s4; // expected-note{{Null pointer value stored to 's5.p1'}}
104 int i = *s5.p1; // expected-warning{{Dereference of null pointer}}
105 // expected-note@-1{{Dereference of null pointer (loaded from field 'p1')}}
107 (void) i;
109 } // namespace copyMoveTrackCtorMemberInitList
111 namespace directInitList {
112 struct S {
113 int *p1, *p2;
116 void InitListDirect() {
117 int *x = nullptr, *y = nullptr; //expected-note{{'y' initialized to a null pointer value}}
119 S s{x, y}; //expected-note{{'s.p2' initialized to a null pointer value}}
121 int i = *s.p2; // expected-warning{{Dereference of null pointer}}
122 // expected-note@-1{{Dereference of null pointer}}
123 (void) i;
125 } // namespace directInitList
127 namespace directNestedInitList {
128 struct S2 {
129 int *p1, *p2;
132 struct S {
133 S2 s;
136 void InitListNestedDirect() {
137 int *x = nullptr, *y = nullptr; //expected-note{{'y' initialized to a null pointer value}}
139 //FIXME: Put more information to the notes.
140 S s{x, y}; //expected-note{{'s.s.p2' initialized to a null pointer value}}
142 int i = *s.s.p2; // expected-warning{{Dereference of null pointer}}
143 // expected-note@-1{{Dereference of null pointer}}
144 (void) i;
146 } // namespace directNestedInitList
148 #if __cplusplus >= 201703L
150 namespace structuredBinding {
151 struct S {
152 int *p1, *p2;
155 void StructuredBinding() {
156 int *x = nullptr, *y = nullptr;
157 //expected-note@-1{{'y' initialized to a null pointer value}}
159 S s{x, y};
160 //expected-note@-1{{'s.p2' initialized to a null pointer value}}
161 //expected-note@-2{{'s' initialized here}}
163 auto [a, b] = s; //expected-note{{Null pointer value stored to '.p2'}}
165 int i = *b; // expected-warning{{Dereference of null pointer}}
166 // expected-note@-1{{Dereference of null pointer}}
167 (void) i;
169 } // namespace structuredBinding
171 #endif
173 namespace nestedCtorInitializer {
174 struct S5{
175 int *x, *y;
178 struct S4 {
179 S5 s5;
182 struct S3 {
183 S4 s4;
186 struct S2 {
187 S3 s3;
190 struct S {
191 S2 s2;
193 //FIXME: Put more information to the notes.
194 S(int *x, int *y) : s2{x, y} {};
195 // expected-note@-1{{Null pointer value stored to 's.s2.s3.s4.s5.y'}}
198 void nestedCtorInit(){
199 int *x = nullptr, *y = nullptr; // expected-note{{'y' initialized to a null pointer value}}
201 S s{x,y};
202 // expected-note@-1{{Passing null pointer value via 2nd parameter}}
203 // expected-note@-2{{Calling constructor for 'S'}}
204 // expected-note@-3{{Returning from constructor for 'S'}}
206 int i = *s.s2.s3.s4.s5.y; // expected-warning{{Dereference of null pointer}}
207 // expected-note@-1{{Dereference of null pointer}}
208 (void) i;
210 } // namespace nestedCtorInitializer
212 namespace NestedRegionTrack {
213 struct N {
214 int *e;
217 struct S {
218 N y;
221 void NestedRegionTrack() {
222 int *x = nullptr, *y = nullptr;
223 // expected-note@-1{{'y' initialized to a null pointer value}}
225 // Test for nested single element initializer list here.
226 S a{{{{{{{{y}}}}}}}};
227 // expected-note@-1{{'a.y.e' initialized to a null pointer value}}
228 // expected-note@-2{{'a' initialized here}}
229 // expected-warning@-3{{too many braces around scalar initializer}}
230 // expected-warning@-4{{too many braces around scalar initializer}}
231 // expected-warning@-5{{too many braces around scalar initializer}}
232 // expected-warning@-6{{too many braces around scalar initializer}}
233 // expected-warning@-7{{too many braces around scalar initializer}}
235 S b = a; // expected-note{{Null pointer value stored to 'b.y.e'}}
237 int i = *b.y.e;
238 // expected-warning@-1{{Dereference of null pointer}}
239 // expected-note@-2{{Dereference of null pointer}}
240 (void) i;
241 (void) x;
244 } // namespace NestedRegionTrack
246 namespace NestedElementRegionTrack {
247 struct N {
248 int *arr[2];
251 struct S {
252 N n;
255 void NestedElementRegionTrack() {
256 int *x = nullptr, *y = nullptr;
257 // expected-note@-1{{'y' initialized to a null pointer value}}
259 S a{{x, y}};
260 // expected-note@-1{{Initializing to a null pointer value}}
261 // expected-note@-2{{'a' initialized here}}
263 S b = a; // expected-note{{Storing null pointer value}}
265 int i = *b.n.arr[1];
266 // expected-warning@-1{{Dereference of null pointer}}
267 // expected-note@-2{{Dereference of null pointer}}
268 (void) i;
271 } // namespace NestedElementRegionTrack