File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -701,7 +701,6 @@ void ExprEngine::handleConstructor(const Expr *E,
701701 if (CE) {
702702 // FIXME: Is it possible and/or useful to do this before PreStmt?
703703 StmtNodeBuilder Bldr (DstPreVisit, PreInitialized, *currBldrCtx);
704- ASTContext &Ctx = LCtx->getAnalysisDeclContext ()->getASTContext ();
705704 for (ExplodedNode *N : DstPreVisit) {
706705 ProgramStateRef State = N->getState ();
707706 if (CE->requiresZeroInitialization ()) {
@@ -718,7 +717,7 @@ void ExprEngine::handleConstructor(const Expr *E,
718717 // since it's then possible to be initializing one part of a multi-
719718 // dimensional array.
720719 const CXXRecordDecl *TargetHeldRecord =
721- Target. getType (Ctx )->getPointeeCXXRecordDecl ( );
720+ dyn_cast_or_null<CXXRecordDecl>(CE-> getType ()->getAsRecordDecl () );
722721
723722 if (!TargetHeldRecord || !TargetHeldRecord->isEmpty ())
724723 State = State->bindDefaultZero (Target, LCtx);
Original file line number Diff line number Diff line change 1010namespace std {
1111#ifdef EMPTY_CLASS
1212
13+ struct default_delete {};
14+ template <class _Tp , class _Dp = default_delete >
15+ #else
16+ // Class with methods and static members is still empty:
1317 template <typename T>
1418 class default_delete {
1519 T dump ();
1620 static T x;
1721 };
1822 template <class _Tp , class _Dp = default_delete<_Tp> >
19- #else
20-
21- struct default_delete {};
22- template <class _Tp , class _Dp = default_delete >
2323#endif
2424 class unique_ptr {
25- [[__no_unique_address__ ]] _Tp * __ptr_;
26- [[__no_unique_address__ ]] _Dp __deleter_;
25+ [[no_unique_address ]] _Tp * __ptr_;
26+ [[no_unique_address ]] _Dp __deleter_;
2727
2828 public:
2929 explicit unique_ptr (_Tp* __p) noexcept
@@ -40,6 +40,11 @@ struct X {};
4040
4141int main ()
4242{
43- std::unique_ptr<X> a (new X ()); // previously leak falsely reported
44- return 0 ;
43+ // Previously a leak falsely reported here. It was because the
44+ // Static Analyzer engine simulated the initialization of
45+ // `__deleter__` incorrectly. The engine assigned zero to
46+ // `__deleter__`--an empty record sharing offset with `__ptr__`.
47+ // The assignment over wrote `__ptr__`.
48+ std::unique_ptr<X> a (new X ());
49+ return 0 ;
4550}
You can’t perform that action at this time.
0 commit comments