From a8a5ebf30c3a526d522faa2f997dd4e3674649cd Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Mon, 11 Aug 2014 14:54:30 +0000 Subject: [PATCH] Work around default parameter problem in the static analyzer. In cases like: struct C { ~C(); } void f(C c = C()); void t() { f(); } We currently do not add the CXXBindTemporaryExpr for the temporary (the code mentions that as the default parameter expressions are owned by the declaration, we'd otherwise add the same expression multiple times), but we add the temporary destructor pointing to the CXXBindTemporaryExpr. We need to fix that before we can re-enable the assertion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215357 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/ExprEngine.cpp | 11 +++++++---- test/Analysis/temporaries.cpp | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index b30a4417e9..e837f5b740 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -671,10 +671,13 @@ void ExprEngine::ProcessTemporaryDtor(const CFGTemporaryDtor D, ExplodedNodeSet CleanDtorState; StmtNodeBuilder StmtBldr(Pred, CleanDtorState, *currBldrCtx); ProgramStateRef State = Pred->getState(); - assert(State->contains( - std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()))); - State = State->remove( - std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame())); + if (State->contains( + std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()))) { + // FIXME: Currently we insert temporary destructors for default parameters, + // but we don't insert the constructors. + State = State->remove( + std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame())); + } StmtBldr.generateNode(D.getBindTemporaryExpr(), Pred, State); QualType varType = D.getBindTemporaryExpr()->getSubExpr()->getType(); diff --git a/test/Analysis/temporaries.cpp b/test/Analysis/temporaries.cpp index 165e65a565..b1099d1f20 100644 --- a/test/Analysis/temporaries.cpp +++ b/test/Analysis/temporaries.cpp @@ -393,6 +393,11 @@ namespace destructors { b || (check(Dtor()) + check(NoReturnDtor())); clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} } + + void f(Dtor d = Dtor()); + void testDefaultParameters() { + f(); + } #endif // TEMPORARY_DTORS } -- 2.40.0