[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

Tim Shen via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 02:23:51 PDT 2016


timshen created this revision.
timshen added a reviewer: rsmith.
timshen added a subscriber: cfe-commits.

Before r272296, the assertion was !ExprNeedsCleanups, which means that there is no cleanups (with dtor calls). It should still check so after r272296. This fixes pr30306.

https://reviews.llvm.org/D24333

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cleanup-side-effects-assert.cpp

Index: clang/test/SemaCXX/cleanup-side-effects-assert.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cleanup-side-effects-assert.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+int f(int const &p) { return p; }
+
+struct A {
+  ~A();
+};
+
+template <typename T>
+void g(T) { int a[f(3)]; } // expected-no-diagnostics
+
+int main() {
+  g<int>(2);
+  return 0;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5746,7 +5746,7 @@
 
   unsigned FirstCleanup = ExprEvalContexts.back().NumCleanupObjects;
   assert(ExprCleanupObjects.size() >= FirstCleanup);
-  assert(Cleanup.exprNeedsCleanups() ||
+  assert(Cleanup.cleanupsHaveSideEffects() ||
          ExprCleanupObjects.size() == FirstCleanup);
   if (!Cleanup.exprNeedsCleanups())
     return SubExpr;
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -11736,7 +11736,7 @@
 
   if (hasAnyUnrecoverableErrorsInThisFunction())
     DiscardCleanupsInEvaluationContext();
-  assert(!Cleanup.exprNeedsCleanups() &&
+  assert(!Cleanup.cleanupsHaveSideEffects() &&
          "cleanups within StmtExpr not correctly bound!");
   PopExpressionEvaluationContext();
 
@@ -12204,7 +12204,7 @@
   // Leave the expression-evaluation context.
   if (hasAnyUnrecoverableErrorsInThisFunction())
     DiscardCleanupsInEvaluationContext();
-  assert(!Cleanup.exprNeedsCleanups() &&
+  assert(!Cleanup.cleanupsHaveSideEffects() &&
          "cleanups within block not correctly bound!");
   PopExpressionEvaluationContext();
 
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11830,7 +11830,8 @@
     assert(ExprCleanupObjects.size() ==
                ExprEvalContexts.back().NumCleanupObjects &&
            "Leftover temporaries in function");
-    assert(!Cleanup.exprNeedsCleanups() && "Unaccounted cleanups in function");
+    assert(!Cleanup.cleanupsHaveSideEffects() &&
+           "Unaccounted cleanups in function");
     assert(MaybeODRUseExprs.empty() &&
            "Leftover expressions for odr-use checking");
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24333.70665.patch
Type: text/x-patch
Size: 2419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160908/3422f95c/attachment.bin>


More information about the cfe-commits mailing list