Skip to content

Commit de018f5

Browse files
authored
[clang][CodeGen] The eh_typeid_for intrinsic needs special care too (#65699)
This change is symmetric with the one reviewed in <https://reviews.llvm.org/D157452> and handles the exception handling specific intrinsic, which slipped through the cracks, in the same way, by inserting an address-space cast iff RTTI is in a non-default AS.
1 parent 0de0b6d commit de018f5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

clang/lib/CodeGen/CGException.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
11361136
// Select the right handler.
11371137
llvm::Function *llvm_eh_typeid_for =
11381138
CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
1139+
llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
1140+
LangAS globAS = CGF.CGM.GetGlobalVarAddressSpace(nullptr);
11391141

11401142
// Load the selector value.
11411143
llvm::Value *selector = CGF.getSelectorFromSlot();
@@ -1149,7 +1151,11 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
11491151
assert(handler.Type.Flags == 0 &&
11501152
"landingpads do not support catch handler flags");
11511153
assert(typeValue && "fell into catch-all case!");
1152-
typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
1154+
// With opaque ptrs, only the address space can be a mismatch.
1155+
if (typeValue->getType() != argTy)
1156+
typeValue =
1157+
CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
1158+
LangAS::Default, argTy);
11531159

11541160
// Figure out the next block.
11551161
bool nextIsEnd;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
2+
3+
struct X { };
4+
5+
const X g();
6+
7+
void f() {
8+
try {
9+
throw g();
10+
// CHECK: ptr addrspace(1) @_ZTI1X
11+
} catch (const X x) {
12+
// CHECK: catch ptr addrspace(1) @_ZTI1X
13+
// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) @_ZTI1X to ptr))
14+
}
15+
}
16+
17+
void h() {
18+
try {
19+
throw "ABC";
20+
// CHECK: ptr addrspace(1) @_ZTIPKc
21+
} catch (char const(&)[4]) {
22+
// CHECK: catch ptr addrspace(1) @_ZTIA4_c
23+
// CHECK: call i32 @llvm.eh.typeid.for(ptr addrspacecast (ptr addrspace(1) @_ZTIA4_c to ptr))
24+
}
25+
}

0 commit comments

Comments
 (0)