Lines Matching +full:- +full:p
2 // RUN: -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr,debug.ExprInspection\
3 // RUN: -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
4 // RUN: -analyzer-output=text -std=c++20 %s -verify=expected
7 // RUN: -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr,debug.ExprInspection\
8 // RUN: -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
9 // RUN: -analyzer-output=text -std=c++11 %s -verify=expected
11 #include "Inputs/system-header-simulator-cxx.h"
26 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in derefAfterDefaultCtr() local
27 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterDefaultCtr()
28 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterDefaultCtr()
32 A *NullInnerPtr = nullptr; // expected-note {{'NullInnerPtr' initialized to a null pointer value}} in derefAfterCtrWithNull()
33 …std::unique_ptr<A> P(NullInnerPtr); // expected-note {{Smart pointer 'P' is constructed using a nu… in derefAfterCtrWithNull() local
34 *P; // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterCtrWithNull()
35 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterCtrWithNull()
39 A *NullInnerPtr = nullptr; // expected-note {{'NullInnerPtr' initialized to a null pointer value}} in derefAfterCtrWithNullVariable()
40 …std::unique_ptr<A> P(NullInnerPtr); // expected-note {{Smart pointer 'P' is constructed using a nu… in derefAfterCtrWithNullVariable() local
41 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterCtrWithNullVariable()
42 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterCtrWithNullVariable()
46 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefAfterRelease() local
48 P.release(); // expected-note {{Smart pointer 'P' is released and set to null}} in derefAfterRelease()
49 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterRelease()
50 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterRelease()
54 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefAfterReset() local
55 P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}} in derefAfterReset()
56 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterReset()
57 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterReset()
61 A *NullInnerPtr = nullptr; // expected-note {{'NullInnerPtr' initialized to a null pointer value}} in derefAfterResetWithNull()
62 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefAfterResetWithNull() local
63 P.reset(NullInnerPtr); // expected-note {{Smart pointer 'P' reset using a null value}} in derefAfterResetWithNull()
64 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterResetWithNull()
65 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterResetWithNull()
71 std::unique_ptr<A> P; // FIXME: add note "Default constructed smart pointer 'P' is null" in derefOnReleasedNullRawPtr() local
72 A *AP = P.release(); // expected-note {{'AP' initialized to a null pointer value}} in derefOnReleasedNullRawPtr()
73 AP->foo(); // expected-warning {{Called C++ object pointer is null [core.CallAndMessage]}} in derefOnReleasedNullRawPtr()
74 // expected-note@-1{{Called C++ object pointer is null}} in derefOnReleasedNullRawPtr()
78 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefOnSwappedNullPtr() local
80 P.swap(PNull); in derefOnSwappedNullPtr()
81 PNull->foo(); // No warning. in derefOnSwappedNullPtr()
82 …(*P).foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]… in derefOnSwappedNullPtr()
83 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefOnSwappedNullPtr()
87 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in derefOnStdSwappedNullPtr() local
89 std::swap(P, PNull); in derefOnStdSwappedNullPtr()
90 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefOnStdSwappedNullPtr()
91 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefOnStdSwappedNullPtr()
94 struct StructWithSmartPtr { // expected-note {{Default constructed smart pointer 'S.P' is null}}
95 std::unique_ptr<A> P; member
99 …StructWithSmartPtr S; // expected-note {{Calling implicit default constructor for 'StructWithSmart… in derefAfterDefaultCtrInsideStruct()
100 // expected-note@-1 {{Returning from default constructor for 'StructWithSmartPtr'}} in derefAfterDefaultCtrInsideStruct()
101 …S.P->foo(); // expected-warning {{Dereference of null smart pointer 'S.P' [alpha.cplusplus.SmartPt… in derefAfterDefaultCtrInsideStruct()
102 // expected-note@-1{{Dereference of null smart pointer 'S.P'}} in derefAfterDefaultCtrInsideStruct()
106 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in noNoteTagsForNonInterestingRegion() local
112 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in noNoteTagsForNonInterestingRegion()
113 // expected-note@-1{{Dereference of null smart pointer 'P'}} in noNoteTagsForNonInterestingRegion()
117 std::unique_ptr<A> P; // FIXME: add note "Default constructed smart pointer 'P' is null" in derefOnRawPtrFromGetOnNullPtr() local
118 P.get()->foo(); // expected-warning {{Called C++ object pointer is null [core.CallAndMessage]}} in derefOnRawPtrFromGetOnNullPtr()
119 // expected-note@-1 {{Called C++ object pointer is null}} in derefOnRawPtrFromGetOnNullPtr()
123 std::unique_ptr<A> P(new A()); in derefOnRawPtrFromGetOnValidPtr() local
124 P.get()->foo(); // No warning. in derefOnRawPtrFromGetOnValidPtr()
127 void derefOnRawPtrFromGetOnUnknownPtr(std::unique_ptr<A> P) { in derefOnRawPtrFromGetOnUnknownPtr() argument
128 P.get()->foo(); // No warning. in derefOnRawPtrFromGetOnUnknownPtr()
132 std::unique_ptr<A> PToMove(new A()); // expected-note {{Smart pointer 'PToMove' is constructed}} in derefOnMovedFromValidPtr()
134 std::unique_ptr<A> P; in derefOnMovedFromValidPtr() local
135 …P = std::move(PToMove); // expected-note {{Smart pointer 'PToMove' is null after being moved to 'P… in derefOnMovedFromValidPtr()
136 …PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus… in derefOnMovedFromValidPtr()
137 // expected-note@-1 {{Dereference of null smart pointer 'PToMove'}} in derefOnMovedFromValidPtr()
142 std::unique_ptr<A> P; in derefOnMovedToNullPtr() local
143 P = std::move(PToMove); // No note. in derefOnMovedToNullPtr()
144 P->foo(); // No warning. in derefOnMovedToNullPtr()
148 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefOnNullPtrGotMovedFromValidPtr() local
150 …std::unique_ptr<A> PToMove; // expected-note {{Default constructed smart pointer 'PToMove' is null… in derefOnNullPtrGotMovedFromValidPtr()
151 P = std::move(PToMove); // expected-note {{A null pointer value is moved to 'P'}} in derefOnNullPtrGotMovedFromValidPtr()
152 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefOnNullPtrGotMovedFromValidPtr()
153 // expected-note@-1 {{Dereference of null smart pointer 'P'}} in derefOnNullPtrGotMovedFromValidPtr()
157 std::unique_ptr<A> P; in derefOnMovedUnknownPtr() local
158 …P = std::move(PToMove); // expected-note {{Smart pointer 'PToMove' is null after; previous value m… in derefOnMovedUnknownPtr()
159 …PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus… in derefOnMovedUnknownPtr()
160 // expected-note@-1 {{Dereference of null smart pointer 'PToMove'}} in derefOnMovedUnknownPtr()
164 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in derefOnAssignedNullPtrToNullSmartPtr() local
165 P = nullptr; // expected-note {{Smart pointer 'P' is assigned to null}} in derefOnAssignedNullPtrToNullSmartPtr()
166 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefOnAssignedNullPtrToNullSmartPtr()
167 // expected-note@-1 {{Dereference of null smart pointer 'P'}} in derefOnAssignedNullPtrToNullSmartPtr()
171 std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}} in derefOnAssignedZeroToNullSmartPtr() local
173 P = 0; // expected-note {{Smart pointer 'P' is assigned to null}} in derefOnAssignedZeroToNullSmartPtr()
174 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefOnAssignedZeroToNullSmartPtr()
175 // expected-note@-1 {{Dereference of null smart pointer 'P'}} in derefOnAssignedZeroToNullSmartPtr()
179 …std::unique_ptr<A> PToMove; // expected-note {{Default constructed smart pointer 'PToMove' is null… in derefMoveConstructedWithNullPtr()
180 …std::unique_ptr<A> P(std::move(PToMove)); // expected-note {{A null pointer value is moved to 'P'}} in derefMoveConstructedWithNullPtr() local
181 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefMoveConstructedWithNullPtr()
182 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefMoveConstructedWithNullPtr()
186 std::unique_ptr<A> PToMove(new A()); // expected-note {{Smart pointer 'PToMove' is constructed}} in derefValidPtrMovedToConstruct()
188 …std::unique_ptr<A> P(std::move(PToMove)); // expected-note {{Smart pointer 'PToMove' is null after… in derefValidPtrMovedToConstruct() local
189 …PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus… in derefValidPtrMovedToConstruct()
190 // expected-note@-1{{Dereference of null smart pointer 'PToMove'}} in derefValidPtrMovedToConstruct()
194 …std::unique_ptr<A> PToMove; // expected-note {{Default constructed smart pointer 'PToMove' is null… in derefNullPtrMovedToConstruct()
196 …std::unique_ptr<A> P(std::move(PToMove)); // expected-note {{Smart pointer 'PToMove' is null after… in derefNullPtrMovedToConstruct() local
197 …PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus… in derefNullPtrMovedToConstruct()
198 // expected-note@-1{{Dereference of null smart pointer 'PToMove'}} in derefNullPtrMovedToConstruct()
202 …std::unique_ptr<A> P(std::move(PToMove)); // expected-note {{Smart pointer 'PToMove' is null after… in derefUnknownPtrMovedToConstruct() local
203 …PToMove->foo(); // expected-warning {{Dereference of null smart pointer 'PToMove' [alpha.cplusplus… in derefUnknownPtrMovedToConstruct()
204 // expected-note@-1{{Dereference of null smart pointer 'PToMove'}} in derefUnknownPtrMovedToConstruct()
208 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in derefConditionOnNullPtrFalseBranch() local
209 if (P) { // expected-note {{Taking false branch}} in derefConditionOnNullPtrFalseBranch()
210 P->foo(); // No warning. in derefConditionOnNullPtrFalseBranch()
212 … P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefConditionOnNullPtrFalseBranch()
213 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefConditionOnNullPtrFalseBranch()
218 std::unique_ptr<A> P; // expected-note {{Default constructed smart pointer 'P' is null}} in derefConditionOnNullPtrTrueBranch() local
219 if (!P) { // expected-note {{Taking true branch}} in derefConditionOnNullPtrTrueBranch()
220 … P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefConditionOnNullPtrTrueBranch()
221 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefConditionOnNullPtrTrueBranch()
226 std::unique_ptr<A> P(new A()); in derefConditionOnValidPtrTrueBranch() local
227 std::unique_ptr<A> PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}} in derefConditionOnValidPtrTrueBranch()
228 if (P) { // expected-note {{Taking true branch}} in derefConditionOnValidPtrTrueBranch()
229 …PNull->foo(); // expected-warning {{Dereference of null smart pointer 'PNull' [alpha.cplusplus.Sma… in derefConditionOnValidPtrTrueBranch()
230 // expected-note@-1{{Dereference of null smart pointer 'PNull'}} in derefConditionOnValidPtrTrueBranch()
232 PNull->foo(); // No warning in derefConditionOnValidPtrTrueBranch()
237 std::unique_ptr<A> P(new A()); in derefConditionOnValidPtrFalseBranch() local
238 std::unique_ptr<A> PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}} in derefConditionOnValidPtrFalseBranch()
239 if (!P) { // expected-note {{Taking false branch}} in derefConditionOnValidPtrFalseBranch()
240 PNull->foo(); // No warning in derefConditionOnValidPtrFalseBranch()
242 …PNull->foo(); // expected-warning {{Dereference of null smart pointer 'PNull' [alpha.cplusplus.Sma… in derefConditionOnValidPtrFalseBranch()
243 // expected-note@-1{{Dereference of null smart pointer 'PNull'}} in derefConditionOnValidPtrFalseBranch()
248 std::unique_ptr<A> P(new A()); in derefConditionOnNotValidPtr() local
250 if (!P) in derefConditionOnNotValidPtr()
251 PNull->foo(); // No warning. in derefConditionOnNotValidPtr()
254 void derefConditionOnUnKnownPtrAssumeNull(std::unique_ptr<A> P) { in derefConditionOnUnKnownPtrAssumeNull() argument
255 std::unique_ptr<A> PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}} in derefConditionOnUnKnownPtrAssumeNull()
256 if (!P) { // expected-note {{Taking true branch}} in derefConditionOnUnKnownPtrAssumeNull()
257 // expected-note@-1{{Assuming smart pointer 'P' is null}} in derefConditionOnUnKnownPtrAssumeNull()
258 …PNull->foo(); // expected-warning {{Dereference of null smart pointer 'PNull' [alpha.cplusplus.Sma… in derefConditionOnUnKnownPtrAssumeNull()
259 // expected-note@-1{{Dereference of null smart pointer 'PNull'}} in derefConditionOnUnKnownPtrAssumeNull()
263 void derefConditionOnUnKnownPtrAssumeNonNull(std::unique_ptr<A> P) { in derefConditionOnUnKnownPtrAssumeNonNull() argument
264 std::unique_ptr<A> PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}} in derefConditionOnUnKnownPtrAssumeNonNull()
265 if (P) { // expected-note {{Taking true branch}} in derefConditionOnUnKnownPtrAssumeNonNull()
266 // expected-note@-1{{Assuming smart pointer 'P' is non-null}} in derefConditionOnUnKnownPtrAssumeNonNull()
267 …PNull->foo(); // expected-warning {{Dereference of null smart pointer 'PNull' [alpha.cplusplus.Sma… in derefConditionOnUnKnownPtrAssumeNonNull()
268 // expected-note@-1{{Dereference of null smart pointer 'PNull'}} in derefConditionOnUnKnownPtrAssumeNonNull()
272 void derefOnValidPtrAfterReset(std::unique_ptr<A> P) { in derefOnValidPtrAfterReset() argument
273 P.reset(new A()); in derefOnValidPtrAfterReset()
274 if (!P) in derefOnValidPtrAfterReset()
275 P->foo(); // No warning. in derefOnValidPtrAfterReset()
277 P->foo(); // No warning. in derefOnValidPtrAfterReset()
281 std::unique_ptr<int> P; member
284 if (!P) { // No-note because foo() is pruned in foo()
291 P.reset(new int(0)); // expected-note {{Assigning 0}} in callingFooWithNullPointer()
292 return 1 / *(P.get()); // expected-warning {{Division by zero [core.DivideZero]}} in callingFooWithNullPointer()
293 // expected-note@-1 {{Division by zero}} in callingFooWithNullPointer()
297 P.reset(new int(0)); // expected-note {{Assigning 0}} in callingFooWithValidPointer()
299 return 1 / *(P.get()); // expected-warning {{Division by zero [core.DivideZero]}} in callingFooWithValidPointer()
300 // expected-note@-1 {{Division by zero}} in callingFooWithValidPointer()
304 P.swap(PUnknown); in callingFooWithUnknownPointer()
306 P.reset(new int(0)); // expected-note {{Assigning 0}} in callingFooWithUnknownPointer()
307 return 1 / *(P.get()); // expected-warning {{Division by zero [core.DivideZero]}} in callingFooWithUnknownPointer()
308 // expected-note@-1 {{Division by zero}} in callingFooWithUnknownPointer()
312 void derefAfterBranchingOnUnknownInnerPtr(std::unique_ptr<A> P) { in derefAfterBranchingOnUnknownInnerPtr() argument
313 A *RP = P.get(); in derefAfterBranchingOnUnknownInnerPtr()
314 if (!RP) { // expected-note {{Assuming 'RP' is null}} in derefAfterBranchingOnUnknownInnerPtr()
315 // expected-note@-1 {{Taking true branch}} in derefAfterBranchingOnUnknownInnerPtr()
316 … P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in derefAfterBranchingOnUnknownInnerPtr()
317 // expected-note@-1{{Dereference of null smart pointer 'P'}} in derefAfterBranchingOnUnknownInnerPtr()
322 auto P = std::make_unique<A>(); in makeUniqueReturnsNonNullUniquePtr() local
323 if (!P) { // expected-note {{Taking false branch}} in makeUniqueReturnsNonNullUniquePtr()
324 P->foo(); // should have no warning here, path is impossible in makeUniqueReturnsNonNullUniquePtr()
326 P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}} in makeUniqueReturnsNonNullUniquePtr()
327 // Now P is null in makeUniqueReturnsNonNullUniquePtr()
328 if (!P) { in makeUniqueReturnsNonNullUniquePtr()
329 // expected-note@-1 {{Taking true branch}} in makeUniqueReturnsNonNullUniquePtr()
330 … P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in makeUniqueReturnsNonNullUniquePtr()
331 // expected-note@-1{{Dereference of null smart pointer 'P'}} in makeUniqueReturnsNonNullUniquePtr()
338 auto P = std::make_unique_for_overwrite<A>(); in makeUniqueForOverwriteReturnsNullUniquePtr() local
339 if (!P) { // expected-note {{Taking false branch}} in makeUniqueForOverwriteReturnsNullUniquePtr()
340 P->foo(); // should have no warning here, path is impossible in makeUniqueForOverwriteReturnsNullUniquePtr()
342 P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}} in makeUniqueForOverwriteReturnsNullUniquePtr()
343 // Now P is null in makeUniqueForOverwriteReturnsNullUniquePtr()
344 if (!P) { in makeUniqueForOverwriteReturnsNullUniquePtr()
345 // expected-note@-1 {{Taking true branch}} in makeUniqueForOverwriteReturnsNullUniquePtr()
346 … P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} in makeUniqueForOverwriteReturnsNullUniquePtr()
347 // expected-note@-1{{Dereference of null smart pointer 'P'}} in makeUniqueForOverwriteReturnsNullUniquePtr()
354 int *p; member
355 G(int *p): p(p) {} in G()
356 ~G() { *p = 0; } in ~G()
362 auto P = std::make_unique<G>(&x); in foo() local
364 clang_analyzer_eval(*P->p == 1); // expected-warning {{TRUE}} in foo()
365 // expected-warning@-1 {{FALSE}} in foo()
366 // expected-note@-2 {{Assuming the condition is true}} in foo()
367 // expected-note@-3 {{Assuming the condition is false}} in foo()
368 // expected-note@-4 {{TRUE}} in foo()
369 // expected-note@-5 {{FALSE}} in foo()
370 // expected-note@-6 {{Assuming the condition is false}} in foo()
375 clang_analyzer_eval(x == 0); // expected-warning {{FALSE}} in foo()
376 // expected-note@-1 {{FALSE}} in foo()