[llvm-branch-commits] [clang] release/19.x: [Clang][CodeGen] Don't emit assumptions if current block is unreachable. (#106936) (PR #107183)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 3 22:42:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang
Author: None (llvmbot)
<details>
<summary>Changes</summary>
Backport c94bd96c277e0b48e198fdc831bb576d9a04aced
Requested by: @<!-- -->dtcxzyw
---
Full diff: https://github.com/llvm/llvm-project/pull/107183.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGStmt.cpp (+1-1)
- (modified) clang/test/SemaCXX/cxx23-assume.cpp (+9)
``````````diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index aa97f685ac7a9f..2f466602d2f680 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -745,7 +745,7 @@ void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) {
} break;
case attr::CXXAssume: {
const Expr *Assumption = cast<CXXAssumeAttr>(A)->getAssumption();
- if (getLangOpts().CXXAssumptions &&
+ if (getLangOpts().CXXAssumptions && Builder.GetInsertBlock() &&
!Assumption->HasSideEffects(getContext())) {
llvm::Value *AssumptionVal = EvaluateExprAsBool(Assumption);
Builder.CreateAssumption(AssumptionVal);
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp b/clang/test/SemaCXX/cxx23-assume.cpp
index 9138501d726dd6..eeae59daea3f70 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -158,3 +158,12 @@ foo (int x, int y)
return x + y;
}
}
+
+// Do not crash when assumptions are unreachable.
+namespace gh106898 {
+int foo () {
+ while(1);
+ int a = 0, b = 1;
+ __attribute__((assume (a < b)));
+}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107183
More information about the llvm-branch-commits
mailing list