r215554 - Work around missing handling of temporaries bound to default arguments.
Manuel Klimek
klimek at google.com
Wed Aug 13 08:25:56 PDT 2014
Author: klimek
Date: Wed Aug 13 10:25:55 2014
New Revision: 215554
URL: http://llvm.org/viewvc/llvm-project?rev=215554&view=rev
Log:
Work around missing handling of temporaries bound to default arguments.
Yet more problems due to the missing CXXBindTemporaryExpr in the CFG for
default arguments.
Unfortunately we cannot just switch off inserting temporaries for the
corresponding default arguments, as that breaks existing tests
(test/SemaCXX/return-noreturn.cpp:245).
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/temporaries.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=215554&r1=215553&r2=215554&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Aug 13 10:25:55 2014
@@ -681,8 +681,11 @@ void ExprEngine::ProcessTemporaryDtor(co
StmtBldr.generateNode(D.getBindTemporaryExpr(), Pred, State);
QualType varType = D.getBindTemporaryExpr()->getSubExpr()->getType();
- assert(CleanDtorState.size() == 1);
- ExplodedNode *CleanPred = *CleanDtorState.begin();
+ // FIXME: Currently CleanDtorState can be empty here due to temporaries being
+ // bound to default parameters.
+ assert(CleanDtorState.size() <= 1);
+ ExplodedNode *CleanPred =
+ CleanDtorState.empty() ? Pred : *CleanDtorState.begin();
// FIXME: Inlining of temporary destructors is not supported yet anyway, so
// we just put a NULL region for now. This will need to be changed later.
VisitCXXDestructor(varType, nullptr, D.getBindTemporaryExpr(),
@@ -718,10 +721,16 @@ void ExprEngine::VisitCXXBindTemporaryEx
StmtNodeBuilder StmtBldr(PreVisit, Dst, *currBldrCtx);
for (ExplodedNode *Node : PreVisit) {
ProgramStateRef State = Node->getState();
- assert(!State->contains<InitializedTemporariesSet>(
- std::make_pair(BTE, Node->getStackFrame())));
- State = State->add<InitializedTemporariesSet>(
- std::make_pair(BTE, Node->getStackFrame()));
+
+ if (!State->contains<InitializedTemporariesSet>(
+ std::make_pair(BTE, Node->getStackFrame()))) {
+ // FIXME: Currently the state might already contain the marker due to
+ // incorrect handling of temporaries bound to default parameters; for
+ // those, we currently skip the CXXBindTemporaryExpr but rely on adding
+ // temporary destructor nodes.
+ State = State->add<InitializedTemporariesSet>(
+ std::make_pair(BTE, Node->getStackFrame()));
+ }
StmtBldr.generateNode(BTE, Node, State);
}
}
Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=215554&r1=215553&r2=215554&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Wed Aug 13 10:25:55 2014
@@ -398,6 +398,27 @@ namespace destructors {
void testDefaultParameters() {
f();
}
+
+ struct DefaultParam {
+ DefaultParam(int, const Dtor& d = Dtor());
+ ~DefaultParam();
+ };
+ void testDefaultParamConstructorsInLoops() {
+ while (true) {
+ // FIXME: This exact pattern triggers the temporary cleanup logic
+ // to fail when adding a 'clean' state.
+ DefaultParam(42);
+ DefaultParam(42);
+ }
+ }
+ void testDefaultParamConstructorsInTernariesInLoops(bool value) {
+ while (true) {
+ // FIXME: This exact pattern triggers the temporary cleanup logic
+ // to visit the bind-temporary logic with a state that already has that
+ // temporary marked as executed.
+ value ? DefaultParam(42) : DefaultParam(42);
+ }
+ }
#endif // TEMPORARY_DTORS
}
More information about the cfe-commits
mailing list