Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CodeGen] Fix extra Yieldop case during try-catch generation #1370

Merged
merged 4 commits into from
Feb 20, 2025
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
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,8 @@ struct CallEndCatch final : EHScopeStack::Cleanup {
// here. For CIR, just let it pass since the cleanup is going
// to be emitted on a later pass when lowering the catch region.
// CGF.EmitRuntimeCallOrTryCall(getEndCatchFn(CGF.CGM));
CGF.getBuilder().create<cir::YieldOp>(*CGF.currSrcLoc);
if (!CGF.getBuilder().getBlock()->mightHaveTerminator())
CGF.getBuilder().create<cir::YieldOp>(*CGF.currSrcLoc);
}
};
} // namespace
Expand Down
41 changes: 32 additions & 9 deletions clang/test/CIR/CodeGen/try-catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,49 @@ unsigned long long tc3() {
return z;
}

// CIR: cir.func @_Z3tc4v()
// CHECK: cir.func @_Z3tc4v()
unsigned long long tc4() {
int x = 50, y = 3;
unsigned long long z;

// CIR-NOT: cir.try
// CHECK-NOT: cir.try
try {
int a = 4;
a++;

// CIR: cir.scope {
// CIR: cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
// CIR-NOT: cir.alloca !cir.ptr<!cir.eh.info>
// CIR: cir.const #cir.int<4> : !s32i
// CIR: cir.unary(inc,
// CIR: cir.store %11, %8 : !s32i, !cir.ptr<!s32i>
// CHECK: cir.scope {
// CHECK: cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
// CHECK-NOT: cir.alloca !cir.ptr<!cir.eh.info>
// CHECK: cir.const #cir.int<4> : !s32i
// CHECK: cir.unary(inc,
// CHECK: cir.store %11, %8 : !s32i, !cir.ptr<!s32i>
} catch (int idx) {
z = 98;
idx++;
}

return z;
}
}

struct S {
S() {};
int a;
};

// CHECK: cir.func @_Z3tc5v()
void tc5() {
try {
S s;
} catch (...) {
tc5();
}
}

// CHECK: cir.try {
// CHECK: cir.call exception @_ZN1SC2Ev({{.*}}) : (!cir.ptr<!ty_S>) -> ()
// CHECK: cir.yield
// CHECK: } catch [type #cir.all {
// CHECK: {{.*}} = cir.catch_param -> !cir.ptr<!void>
// CHECK: cir.call exception @_Z3tc5v() : () -> ()
// CHECK: cir.yield
// CHECK: }]