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
{
9 S(int *a
, int *b
) : p1(a
), p2(b
) {} // expected-note{{Null pointer value stored to 's.p1'}}
13 int *x
= nullptr, *y
= nullptr;
14 // expected-note@-1{{'x' initialized to a null pointer value}}
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')}}
34 } // namespace copyMoveTrackCtor
36 namespace copyMoveTrackInitList
{
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')}}
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')}}
79 } // namespace copyMoveTrackInitList
81 namespace copyMoveTrackCtorMemberInitList
{
84 S(int *a
, int *b
) : p1
{a
}, p2
{b
} {} // expected-note{{Null pointer value stored to 's.p1'}}
88 int *x
= nullptr, *y
= nullptr;
89 // expected-note@-1{{'x' initialized to a null pointer value}}
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')}}
109 } // namespace copyMoveTrackCtorMemberInitList
111 namespace directInitList
{
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}}
125 } // namespace directInitList
127 namespace directNestedInitList
{
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}}
146 } // namespace directNestedInitList
148 #if __cplusplus >= 201703L
150 namespace structuredBinding
{
155 void StructuredBinding() {
156 int *x
= nullptr, *y
= nullptr;
157 //expected-note@-1{{'y' initialized to a null pointer value}}
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}}
169 } // namespace structuredBinding
173 namespace nestedCtorInitializer
{
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}}
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}}
210 } // namespace nestedCtorInitializer
212 namespace NestedRegionTrack
{
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'}}
238 // expected-warning@-1{{Dereference of null pointer}}
239 // expected-note@-2{{Dereference of null pointer}}
244 } // namespace NestedRegionTrack
246 namespace NestedElementRegionTrack
{
255 void NestedElementRegionTrack() {
256 int *x
= nullptr, *y
= nullptr;
257 // expected-note@-1{{'y' initialized to a null pointer value}}
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}}
266 // expected-warning@-1{{Dereference of null pointer}}
267 // expected-note@-2{{Dereference of null pointer}}
271 } // namespace NestedElementRegionTrack