Skip to content

[clang][CodeGen] The eh_typeid_for intrinsic needs special care too #65699

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

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/CGException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,10 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
assert(handler.Type.Flags == 0 &&
"landingpads do not support catch handler flags");
assert(typeValue && "fell into catch-all case!");
typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
// With opaque ptrs, only the address space can be a mismatch.
if (typeValue->getType() != argTy)
typeValue = CGF.Builder.CreateAddrSpaceCast(typeValue, argTy);

// Figure out the next block.
bool nextIsEnd;
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CodeGenCXX/try-catch-with-address-space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s

struct X { };

const X g();

void f() {
try {
throw g();
// CHECK: ptr addrspace(1) @_ZTI1X
} catch (const X x) {
// CHECK: catch ptr addrspace(1) @_ZTI1X
// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) @_ZTI1X to ptr))
}
}

void h() {
try {
throw "ABC";
// CHECK: ptr addrspace(1) @_ZTIPKc
} catch (char const(&)[4]) {
// CHECK: catch ptr addrspace(1) @_ZTIA4_c
// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) @_ZTIA4_c to ptr))
}
}