[PATCH] D155870: [Clang][CodeGen] Another follow-up for `vtable`, `typeinfo` et al. are globals
Alex Voicu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 20 10:54:18 PDT 2023
AlexVlx created this revision.
AlexVlx added reviewers: rjmccall, efriedma, yaxunl.
AlexVlx added a project: clang.
Herald added a subscriber: arichardson.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added a subscriber: cfe-commits.
Turns out that in https://reviews.llvm.org/rG8acdcf4016876d122733991561be706b64026e73 I missed another use case (`dynamic_cast` relies on `typeinfo`, which its signature assumed to be in the generic address space), sadly. This patch corrects the oversight and adds an associated test.
P.S.: the current and @bjope 's inquiry on https://reviews.llvm.org/D153092 makes me wonder if we want to consider a more centralised approach to all of the polymorphism related bits, so that future changes can be localised to one / a few spots, and then propagate around. I admit I've not thought deeply about it though and it would probably be non-trivial.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155870
Files:
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
Index: clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/dynamic-cast-address-space.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -I%S %s -triple amdgcn-amd-amdhsa -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+struct A { virtual void f(); };
+struct B : A { };
+
+// CHECK: {{define.*@_Z1fP1A}}
+// CHECK-SAME: personality ptr @__gxx_personality_v0
+B fail;
+const B& f(A *a) {
+ try {
+ // CHECK: call ptr @__dynamic_cast
+ // CHECK: br i1
+ // CHECK: invoke void @__cxa_bad_cast() [[NR:#[0-9]+]]
+ dynamic_cast<const B&>(*a);
+ } catch (...) {
+ // CHECK: landingpad { ptr, i32 }
+ // CHECK-NEXT: catch ptr null
+ }
+ return fail;
+}
+
+// CHECK: declare ptr @__dynamic_cast(ptr, ptr addrspace(1), ptr addrspace(1), i64) [[NUW_RO:#[0-9]+]]
+
+// CHECK: attributes [[NUW_RO]] = { nounwind memory(read) }
+// CHECK: attributes [[NR]] = { noreturn }
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1296,15 +1296,16 @@
static llvm::FunctionCallee getItaniumDynamicCastFn(CodeGenFunction &CGF) {
// void *__dynamic_cast(const void *sub,
- // const abi::__class_type_info *src,
- // const abi::__class_type_info *dst,
+ // global_as const abi::__class_type_info *src,
+ // global_as const abi::__class_type_info *dst,
// std::ptrdiff_t src2dst_offset);
llvm::Type *Int8PtrTy = CGF.Int8PtrTy;
+ llvm::Type *GlobInt8PtrTy = CGF.GlobalsInt8PtrTy;
llvm::Type *PtrDiffTy =
CGF.ConvertType(CGF.getContext().getPointerDiffType());
- llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
+ llvm::Type *Args[4] = { Int8PtrTy, GlobInt8PtrTy, GlobInt8PtrTy, PtrDiffTy };
llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155870.542589.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230720/1cc30cec/attachment.bin>
More information about the cfe-commits
mailing list