[clang] de018f5 - [clang][CodeGen] The `eh_typeid_for` intrinsic needs special care too (#65699)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 20 09:12:23 PDT 2023
Author: Alex Voicu
Date: 2023-09-20T17:12:19+01:00
New Revision: de018f5ca4b2598f6bbf7a27a1fb51935792c276
URL: https://github.com/llvm/llvm-project/commit/de018f5ca4b2598f6bbf7a27a1fb51935792c276
DIFF: https://github.com/llvm/llvm-project/commit/de018f5ca4b2598f6bbf7a27a1fb51935792c276.diff
LOG: [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.
Added:
clang/test/CodeGenCXX/try-catch-with-address-space.cpp
Modified:
clang/lib/CodeGen/CGException.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 3996f2948349cb5..87594f71b26ec53 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1136,6 +1136,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
// Select the right handler.
llvm::Function *llvm_eh_typeid_for =
CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
+ llvm::Type *argTy = llvm_eh_typeid_for->getArg(0)->getType();
+ LangAS globAS = CGF.CGM.GetGlobalVarAddressSpace(nullptr);
// Load the selector value.
llvm::Value *selector = CGF.getSelectorFromSlot();
@@ -1149,7 +1151,11 @@ 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);
+ // With opaque ptrs, only the address space can be a mismatch.
+ if (typeValue->getType() != argTy)
+ typeValue =
+ CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
+ LangAS::Default, argTy);
// Figure out the next block.
bool nextIsEnd;
diff --git a/clang/test/CodeGenCXX/try-catch-with-address-space.cpp b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
new file mode 100644
index 000000000000000..279d29f50fd4101
--- /dev/null
+++ b/clang/test/CodeGenCXX/try-catch-with-address-space.cpp
@@ -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))
+ }
+}
More information about the cfe-commits
mailing list