]> granicus.if.org Git - clang/commitdiff
Work around default parameter problem in the static analyzer.
authorManuel Klimek <klimek@google.com>
Mon, 11 Aug 2014 14:54:30 +0000 (14:54 +0000)
committerManuel Klimek <klimek@google.com>
Mon, 11 Aug 2014 14:54:30 +0000 (14:54 +0000)
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
test/Analysis/temporaries.cpp

index b30a4417e9a96e5817445bb67183e9a4bc266f8d..e837f5b740a551f537531e200e4162bb2fb9e265 100644 (file)
@@ -671,10 +671,13 @@ void ExprEngine::ProcessTemporaryDtor(const CFGTemporaryDtor D,
   ExplodedNodeSet CleanDtorState;
   StmtNodeBuilder StmtBldr(Pred, CleanDtorState, *currBldrCtx);
   ProgramStateRef State = Pred->getState();
-  assert(State->contains<InitializedTemporariesSet>(
-      std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame())));
-  State = State->remove<InitializedTemporariesSet>(
-      std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()));
+  if (State->contains<InitializedTemporariesSet>(
+      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<InitializedTemporariesSet>(
+        std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()));
+  }
   StmtBldr.generateNode(D.getBindTemporaryExpr(), Pred, State);
 
   QualType varType = D.getBindTemporaryExpr()->getSubExpr()->getType();
index 165e65a5659deb8470bbf433672a23283e95870f..b1099d1f207e58f63f343917110a675844aa73d5 100644 (file)
@@ -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
 }