[clang] 7164544 - [CIR] Upstream Try block with only noexcept calls (#165153)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 28 09:23:19 PDT 2025
Author: Amr Hesham
Date: 2025-10-28T17:23:15+01:00
New Revision: 7164544428ea7881ca95b69ef4f3997a83d6fc06
URL: https://github.com/llvm/llvm-project/commit/7164544428ea7881ca95b69ef4f3997a83d6fc06
DIFF: https://github.com/llvm/llvm-project/commit/7164544428ea7881ca95b69ef4f3997a83d6fc06.diff
LOG: [CIR] Upstream Try block with only noexcept calls (#165153)
Upstream try block with only noexcept calls inside, which doesn't need
to be converted to TryCallOp
Issue https://github.com/llvm/llvm-project/issues/154992
Added:
Modified:
clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
clang/test/CIR/CodeGen/try-catch.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
index 21c96febf8403..ca7554e4e3754 100644
--- a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
@@ -606,10 +606,12 @@ class CIRTryOpFlattening : public mlir::OpRewritePattern<cir::TryOp> {
// `cir.try_call`.
llvm::SmallVector<cir::CallOp, 4> callsToRewrite;
tryOp.getTryRegion().walk([&](CallOp op) {
+ if (op.getNothrow())
+ return;
+
// Only grab calls within immediate closest TryOp scope.
if (op->getParentOfType<cir::TryOp>() != tryOp)
return;
- assert(!cir::MissingFeatures::opCallExceptionAttr());
callsToRewrite.push_back(op);
});
diff --git a/clang/test/CIR/CodeGen/try-catch.cpp b/clang/test/CIR/CodeGen/try-catch.cpp
index 1e4d2a63ada01..27e3d8ef41115 100644
--- a/clang/test/CIR/CodeGen/try-catch.cpp
+++ b/clang/test/CIR/CodeGen/try-catch.cpp
@@ -164,3 +164,33 @@ void try_catch_with_alloca() {
// OGCG: %[[TMP_B:.*]] = load i32, ptr %[[B_ADDR]], align 4
// OGCG: %[[RESULT:.*]] = add nsw i32 %[[TMP_A]], %[[TMP_B]]
// OGCG: store i32 %[[RESULT]], ptr %[[C_ADDR]], align 4
+
+void function_with_noexcept() noexcept;
+
+void calling_noexcept_function_inside_try_block() {
+ try {
+ function_with_noexcept();
+ } catch (...) {
+ }
+}
+
+// CIR: cir.scope {
+// CIR: cir.try {
+// CIR: cir.call @_Z22function_with_noexceptv() nothrow : () -> ()
+// CIR: cir.yield
+// CIR: }
+// CIR: }
+
+// LLVM: br label %[[LABEL_1:.*]]
+// LLVM: [[LABEL_1]]:
+// LLVM: br label %[[LABEL_2:.*]]
+// LLVM: [[LABEL_2]]:
+// LLVM: call void @_Z22function_with_noexceptv()
+// LLVM: br label %[[LABEL_3:.*]]
+// LLVM: [[LABEL_3]]:
+// LLVM: br label %[[LABEL_4:.*]]
+// LLVM: [[LABEL_4]]:
+// LLVM: ret void
+
+// OGCG: call void @_Z22function_with_noexceptv()
+// OGCG: ret void
More information about the cfe-commits
mailing list