]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix eliding the same destructor twice due to buggy default arguments.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 31 Jul 2018 21:17:40 +0000 (21:17 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 31 Jul 2018 21:17:40 +0000 (21:17 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338441 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/ExprEngine.cpp
test/Analysis/temporaries.cpp

index f90c7f8e8f63ee81ecd78015c5140a42ddfb77ba..2b4bdd754fdbcdd101a5d4417af654060166de4e 100644 (file)
@@ -460,7 +460,8 @@ ProgramStateRef ExprEngine::elideDestructor(ProgramStateRef State,
                                             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());
 }
 
index 539882f17eaafa41dc7fef2788503b532307f34f..e760d7ea283ade225c5415bdc8a511e27eee5630 100644 (file)
@@ -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}}