r338441 - [analyzer] Fix eliding the same destructor twice due to buggy default arguments.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 14:17:40 PDT 2018


Author: dergachev
Date: Tue Jul 31 14:17:40 2018
New Revision: 338441

URL: http://llvm.org/viewvc/llvm-project?rev=338441&view=rev
Log:
[analyzer] Fix eliding the same destructor twice due to buggy default arguments.

Because of incomplete support for CXXDefaultArgExpr, we cannot yet commit to
asserting that the same destructor won't be elided twice.

Suppress the assertion failure for now. Proper support is still an open problem.

Differential Revision: https://reviews.llvm.org/D49213

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=338441&r1=338440&r2=338441&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Jul 31 14:17:40 2018
@@ -460,7 +460,8 @@ ProgramStateRef ExprEngine::elideDestruc
                                             const CXXBindTemporaryExpr *BTE,
                                             const LocationContext *LC) {
   ConstructedObjectKey Key({BTE, /*IsElided=*/true}, LC);
-  assert(!State->contains<ObjectsUnderConstruction>(Key));
+  // FIXME: Currently the state might already contain the marker due to
+  // incorrect handling of temporaries bound to default parameters.
   return State->set<ObjectsUnderConstruction>(Key, UnknownVal());
 }
 

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=338441&r1=338440&r2=338441&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Tue Jul 31 14:17:40 2018
@@ -458,6 +458,21 @@ namespace destructors {
 #endif // TEMPORARY_DTORS
 }
 
+namespace default_param_elided_destructors {
+struct a {
+  ~a();
+};
+struct F {
+  a d;
+  F(char *, a = a());
+};
+void g() {
+  char h[1];
+  for (int i = 0;;)
+    F j(i ? j : h);
+}
+} // namespace default_param_elided_destructors
+
 void testStaticMaterializeTemporaryExpr() {
   static const Trivial &ref = getTrivial();
   clang_analyzer_eval(ref.value == 42); // expected-warning{{TRUE}}




More information about the cfe-commits mailing list