Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
30 changes: 30 additions & 0 deletions clang/test/CIR/CodeGen/try-catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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