[clang] 93b1349 - [CIR] Keep the address space in thunk this and return adjustments (#234183)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 08:08:24 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-10-26T16:08:18+01:00
New Revision: 93b1349dc9cbc739a048806808c475cb757882e4

URL: https://github.com/llvm/llvm-project/commit/93b1349dc9cbc739a048806808c475cb757882e4
DIFF: https://github.com/llvm/llvm-project/commit/93b1349dc9cbc739a048806808c475cb757882e4.diff

LOG: [CIR] Keep the address space in thunk this and return adjustments (#234183)

Thunks cast this to a plain i8 pointer, which broke on spirv64-amd where
this lives in address space 4

Added: 
    clang/test/CIR/CodeGenHIP/thunk-addrspace.hip

Modified: 
    clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index aa3e3d09bb922..069b8c5d8f2ac 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -2281,8 +2281,10 @@ static mlir::Value performTypeAdjustment(CIRGenFunction &cgf,
 
   CIRGenBuilderTy &builder = cgf.getBuilder();
   mlir::Location loc = builder.getUnknownLoc();
-  cir::PointerType i8PtrTy = builder.getUInt8PtrTy();
-  mlir::Value v = builder.createBitcast(initialPtr.getPointer(), i8PtrTy);
+  cir::PointerType ui8DefaultASPtrTy = builder.getUInt8PtrTy();
+  mlir::Value v =
+      builder.createPtrBitcast(initialPtr.getPointer(), builder.getUInt8Ty());
+  auto i8PtrTy = mlir::cast<cir::PointerType>(v.getType());
 
   // In a base-to-derived cast, the non-virtual adjustment is applied first.
   if (nonVirtualAdjustment && !isReturnAdjustment) {
@@ -2295,11 +2297,11 @@ static mlir::Value performTypeAdjustment(CIRGenFunction &cgf,
   if (virtualAdjustment) {
     mlir::Value vtablePtr = cgf.getVTablePtr(
         loc, Address(v, clang::CharUnits::One()), unadjustedClass);
-    vtablePtr = builder.createBitcast(vtablePtr, i8PtrTy);
+    vtablePtr = builder.createBitcast(vtablePtr, ui8DefaultASPtrTy);
 
     mlir::Value offset;
     mlir::Value offsetPtr =
-        cir::PtrStrideOp::create(builder, loc, i8PtrTy, vtablePtr,
+        cir::PtrStrideOp::create(builder, loc, ui8DefaultASPtrTy, vtablePtr,
                                  builder.getSInt64(virtualAdjustment, loc));
     if (cgf.cgm.getLangOpts().RelativeCXXABIVTables) {
       assert(!cir::MissingFeatures::vtableRelativeLayout());

diff  --git a/clang/test/CIR/CodeGenHIP/thunk-addrspace.hip b/clang/test/CIR/CodeGenHIP/thunk-addrspace.hip
new file mode 100644
index 0000000000000..6326ce485aeea
--- /dev/null
+++ b/clang/test/CIR/CodeGenHIP/thunk-addrspace.hip
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -x hip -fcuda-is-device -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -x hip -fcuda-is-device -fclangir -emit-llvm %s -o - \
+// RUN:   | FileCheck --check-prefix=LLVM %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -x hip -fcuda-is-device -emit-llvm %s -o - \
+// RUN:   | FileCheck --check-prefix=LLVM %s
+
+#define __device__ __attribute__((device))
+
+struct A { __device__ virtual void f(); };
+struct B { __device__ virtual void g(); int b; };
+struct C : A, B { __device__ void g() override; };
+__device__ void C::g() {}
+
+// CIR-LABEL: cir.func {{.*}} @_ZThn8_N1C1gEv
+// CIR:         %[[THIS:.*]] = cir.load {{.*}}, !cir.ptr<!rec_C, target_address_space(4)>
+// CIR:         %[[RAW:.*]] = cir.cast bitcast %[[THIS]] : !cir.ptr<!rec_C, target_address_space(4)> -> !cir.ptr<!u8i, target_address_space(4)>
+// CIR:         %[[ADJ:.*]] = cir.ptr_stride %[[RAW]], %{{.*}} : (!cir.ptr<!u8i, target_address_space(4)>, !s64i) -> !cir.ptr<!u8i, target_address_space(4)>
+// CIR:         cir.cast bitcast %[[ADJ]] : !cir.ptr<!u8i, target_address_space(4)> -> !cir.ptr<!rec_C, target_address_space(4)>
+
+// LLVM-LABEL: define spir_func void @_ZThn8_N1C1gEv(
+// LLVM:         %[[THIS:.*]] = load ptr addrspace(4), ptr addrspace(4)
+// LLVM:         getelementptr {{.*}}i8, ptr addrspace(4) %[[THIS]], i64 -8


        


More information about the cfe-commits mailing list