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();
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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits