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: 4 additions & 0 deletions clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ class CIRTryOpFlattening : public mlir::OpRewritePattern<cir::TryOp> {
if (auto tryBodyYield = dyn_cast<cir::YieldOp>(afterBody->getTerminator()))
rewriter.replaceOpWithNewOp<cir::BrOp>(tryBodyYield, afterTry);

mlir::ArrayAttr catches = tryOp.getCatchTypesAttr();
if (!catches || catches.empty())
return;

// Start the landing pad by getting the inflight exception information.
mlir::Block *nextDispatcher =
buildLandingPads(tryOp, rewriter, beforeCatch, afterTry, callsToRewrite,
Expand Down
37 changes: 37 additions & 0 deletions clang/test/CIR/CodeGen/try-catch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -mconstructor-aliases -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -mconstructor-aliases -fclangir -emit-cir-flat %s -o %t.cir.flat
// RUN: FileCheck --check-prefix=FLAT --input-file=%t.cir.flat %s

double division(int a, int b);

Expand Down Expand Up @@ -168,3 +170,38 @@ void tc7() {
// CHECK: cir.return
// CHECK: }
// CHECK: }

struct S2 {
int a, b;
};

void tc8() {
try {
S2 s{1, 2};
} catch (...) {
}
}

// CHECK: cir.scope {
// CHECK: %[[V0:.*]] = cir.alloca !rec_S2, !cir.ptr<!rec_S2>, ["s"] {alignment = 4 : i64}
// CHECK: cir.try {
// CHECK: %[[V1:.*]] = cir.const #cir.const_record<{#cir.int<1> : !s32i, #cir.int<2> : !s32i}> : !rec_S2
// CHECK: cir.store align(4) %[[V1]], %[[V0]] : !rec_S2, !cir.ptr<!rec_S2>
// CHECK: cir.yield
// CHECK: }
// CHECK: }

// FLAT: cir.func @_Z3tc8v()
// FLAT: %[[V0:.*]] = cir.alloca !rec_S2, !cir.ptr<!rec_S2>, ["s"] {alignment = 4 : i64}
// FLAT: cir.br ^bb[[#B1:]]
// FLAT: ^bb[[#B1]]:
// FLAT: cir.br ^bb[[#B2:]]
// FLAT: ^bb[[#B2]]:
// FLAT: %[[V1:.*]] = cir.const #cir.const_record<{#cir.int<1> : !s32i, #cir.int<2> : !s32i}> : !rec_S2
// FLAT: cir.store align(4) %[[V1]], %[[V0]] : !rec_S2, !cir.ptr<!rec_S2>
// FLAT: cir.br ^bb[[#B3:]]
// FLAT: ^bb[[#B3]]:
// FLAT: cir.br ^bb[[#B4:]]
// FLAT: ^bb[[#B4]]:
// FLAT: cir.return
// FLAT: }
Loading