[PATCH] D125936: [Sema] Relax an assertion in BuildStmtExpr

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 18 16:33:58 PDT 2022


ahatanak created this revision.
ahatanak added reviewers: rjmccall, akyrtzi.
ahatanak added a project: clang.
Herald added a project: All.
ahatanak requested review of this revision.

The assertion doesn't hold if there are temporaries created in the AsmStmt passed to the method.

rdar://92845835


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125936

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaTemplate/instantiate-expr-1.cpp


Index: clang/test/SemaTemplate/instantiate-expr-1.cpp
===================================================================
--- clang/test/SemaTemplate/instantiate-expr-1.cpp
+++ clang/test/SemaTemplate/instantiate-expr-1.cpp
@@ -190,3 +190,19 @@
     test_asm_tied(1.f); // expected-note {{instantiation of}}
   }
 }
+
+namespace TestAsmCleanup {
+struct S {
+  operator int() const { return 1; }
+  ~S();
+};
+
+template <class T>
+void foo() {
+  __asm__ __volatile__("%[i]"
+                       :
+                       : [i] "r"(-S()));
+}
+
+void test() { foo<void>(); }
+} // namespace TestAsmCleanup
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15745,7 +15745,9 @@
 
   if (hasAnyUnrecoverableErrorsInThisFunction())
     DiscardCleanupsInEvaluationContext();
-  assert(!Cleanup.exprNeedsCleanups() &&
+  // Cleanups may be needed if temporaries are created in an AsmStmt.
+  assert((!Cleanup.exprNeedsCleanups() ||
+          (!Compound->body_empty() && isa<AsmStmt>(Compound->body_front()))) &&
          "cleanups within StmtExpr not correctly bound!");
   PopExpressionEvaluationContext();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125936.430532.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220518/7964a8a8/attachment.bin>


More information about the cfe-commits mailing list