https://github.com/vtjnash updated 
https://github.com/llvm/llvm-project/pull/177044

>From d3b95627148d9101aed8bf1b76a0adba1011202d Mon Sep 17 00:00:00 2001
From: Jameson Nash <[email protected]>
Date: Tue, 20 Jan 2026 22:21:02 +0000
Subject: [PATCH] [clang] consistent addrspace for GetVTTParameter result

Avoid using VTT->getValueType() and VoidPtrTy and DRY the code to more
accurately get and set the addrspace without relying on the behavior of
struct indexing into a GlobalValue declared type.
---
 clang/lib/CodeGen/CGClass.cpp                    | 10 +++++-----
 clang/test/CodeGenCXX/inheriting-constructor.cpp |  4 ++--
 clang/test/CodeGenCXX/vtt-address-space.cpp      | 13 ++++++-------
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index e91dde147a889..02e8912bdbbf0 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -476,16 +476,16 @@ llvm::Value *CodeGenFunction::GetVTTParameter(GlobalDecl 
GD,
     assert(SubVTTIndex != 0 && "Sub-VTT index must be greater than zero!");
   }
 
+  llvm::Value *VTT;
   if (CGM.getCXXABI().NeedsVTTParameter(CurGD)) {
     // A VTT parameter was passed to the constructor, use it.
-    llvm::Value *VTT = LoadCXXVTT();
-    return Builder.CreateConstInBoundsGEP1_64(VoidPtrTy, VTT, SubVTTIndex);
+    VTT = LoadCXXVTT();
   } else {
     // We're the complete constructor, so get the VTT by name.
-    llvm::GlobalValue *VTT = CGM.getVTables().GetAddrOfVTT(RD);
-    return Builder.CreateConstInBoundsGEP2_64(VTT->getValueType(), VTT, 0,
-                                              SubVTTIndex);
+    VTT = CGM.getVTables().GetAddrOfVTT(RD);
   }
+  return Builder.CreateConstInBoundsGEP1_64(CGM.GlobalsInt8PtrTy, VTT,
+                                            SubVTTIndex);
 }
 
 namespace {
diff --git a/clang/test/CodeGenCXX/inheriting-constructor.cpp 
b/clang/test/CodeGenCXX/inheriting-constructor.cpp
index 21751bea055dc..41ab5399f38a0 100644
--- a/clang/test/CodeGenCXX/inheriting-constructor.cpp
+++ b/clang/test/CodeGenCXX/inheriting-constructor.cpp
@@ -113,7 +113,7 @@ namespace noninline_virt {
   // constructor, which takes no arguments other than the this pointer and VTT.
   // ITANIUM-LABEL: define linkonce_odr void 
@_ZN14noninline_virt1CCI1NS_1AEEiO1QPvU17pass_object_size0(
   // ITANIUM: call void 
@_ZN14noninline_virt1AC2EiO1QPvU17pass_object_size0({{.*}} %{{.*}}, i32 
%{{.*}}, ptr {{.*}}, ptr %{{.*}}, i{{32|64}} %{{.*}})
-  // ITANIUM: call void 
@_ZN14noninline_virt1BCI2NS_1AEEiO1QPvU17pass_object_size0(ptr {{[^,]*}} 
%{{.*}}, ptr getelementptr inbounds ([2 x ptr], ptr @_ZTTN14noninline_virt1CE, 
i64 0, i64 1))
+  // ITANIUM: call void 
@_ZN14noninline_virt1BCI2NS_1AEEiO1QPvU17pass_object_size0(ptr {{[^,]*}} 
%{{.*}}, ptr getelementptr inbounds (ptr, ptr @_ZTTN14noninline_virt1CE, i64 1))
   // ITANIUM: store {{.*}} @_ZTVN14noninline_virt1CE
 
   // C constructor forwards to B constructor and A constructor. We pass the 
args
@@ -371,7 +371,7 @@ namespace inline_virt {
   // ITANIUM: call void @_ZN1QC1Ei({{.*}}, i32 4)
   // ITANIUM: %[[A:.*]] = getelementptr {{.*}}, i{{32|64}} {{12|16}}
   // ITANIUM: call void ({{.*}}, ...) @_ZN11inline_virt1AC2E1QiS1_OS1_z(ptr 
{{[^,]*}} %[[A]], {{.*}}, i32 2, {{.*}}, {{.*}}, i32 5, i32 6)
-  // ITANIUM: call void @_ZN11inline_virt1BCI2NS_1AEE1QiS1_OS1_z({{[^,]*}}, 
ptr getelementptr inbounds ([2 x ptr], ptr @_ZTTN11inline_virt1CE, i64 0, i64 
1))
+  // ITANIUM: call void @_ZN11inline_virt1BCI2NS_1AEE1QiS1_OS1_z({{[^,]*}}, 
ptr getelementptr inbounds (ptr, ptr @_ZTTN11inline_virt1CE, i64 1))
   // ITANIUM: store {{.*}} @_ZTVN11inline_virt1CE
   // ITANIUM: call void @_ZN1QD1Ev(
   // ITANIUM: call void @_ZN1QD1Ev(
diff --git a/clang/test/CodeGenCXX/vtt-address-space.cpp 
b/clang/test/CodeGenCXX/vtt-address-space.cpp
index 3409bc7cbb69d..0c99ed82e9b92 100644
--- a/clang/test/CodeGenCXX/vtt-address-space.cpp
+++ b/clang/test/CodeGenCXX/vtt-address-space.cpp
@@ -19,16 +19,15 @@ namespace Test {
   D d;
 }
 
-// CHECK: linkonce_odr unnamed_addr addrspace(1) constant [13 x ptr 
addrspace(1)] [ptr addrspace(1) getelementptr inbounds inrange(-40, 0) ({ [5 x 
ptr addrspace(1)], [7 x ptr addrspace(1)], [4 x ptr addrspace(1)], [3 x ptr 
addrspace(1)] }, ptr addrspace(1) @_ZTVN4Test1DE, i32 0, i32 0, i32 5), ptr 
addrspace(1) getelementptr inbounds inrange(-24, 0) ({ [3 x ptr addrspace(1)], 
[4 x ptr addrspace(1)] }, ptr addrspace(1) @_ZTCN4Test1DE0_NS_2C1E, i32 0, i32 
0, i32 3), ptr addrspace(1) getelementptr inbounds inrange(-24, 8) ({ [3 x ptr 
addrspace(1)], [4 x ptr addrspace(1)] }, ptr addrspace(1) 
@_ZTCN4Test1DE0_NS_2C1E, i32 0, i32 1, i32 3), ptr addrspace(1) getelementptr 
inbounds inrange(-48, 8) ({ [7 x ptr addrspace(1)], [3 x ptr addrspace(1)], [4 
x ptr addrspace(1)] }, ptr addrspace(1) @_ZTCN4Test1DE16_NS_2C2E, i32 0, i32 0, 
i32 6), ptr addrspace(1) getelementptr inbounds inrange(-48, 8) ({ [7 x ptr 
addrspace(1)], [3 x ptr addrspace(1)], [4 x ptr addrspace(1)] }, ptr 
addrspace(1) @_ZTCN4Test1DE16_NS_2C2E, i32 0, i32 0, i32 6), ptr addrspace(1) 
getelementptr inbounds inrange(-24, 0) ({ [7 x ptr addrspace(1)], [3 x ptr 
addrspace(1)], [4 x ptr addrspace(1)] }, ptr addrspace(1) 
@_ZTCN4Test1DE16_NS_2C2E, i32 0, i32 1, i32 3), ptr addrspace(1) getelementptr 
inbounds inrange(-24, 8) ({ [7 x ptr addrspace(1)], [3 x ptr addrspace(1)], [4 
x ptr addrspace(1)] }, ptr addrspace(1) @_ZTCN4Test1DE16_NS_2C2E, i32 0, i32 2, 
i32 3), ptr addrspace(1) getelementptr inbounds inrange(-24, 8) ({ [5 x ptr 
addrspace(1)], [7 x ptr addrspace(1)], [4 x ptr addrspace(1)], [3 x ptr 
addrspace(1)] }, ptr addrspace(1) @_ZTVN4Test1DE, i32 0, i32 2, i32 3), ptr 
addrspace(1) getelementptr inbounds inrange(-48, 8) ({ [5 x ptr addrspace(1)], 
[7 x ptr addrspace(1)], [4 x ptr addrspace(1)], [3 x ptr addrspace(1)] }, ptr 
addrspace(1) @_ZTVN4Test1DE, i32 0, i32 1, i32 6), ptr addrspace(1) 
getelementptr inbounds inrange(-48, 8) ({ [5 x ptr addrspace(1)], [7 x ptr 
addrspace(1)], [4 x ptr addrspace(1)], [3 x ptr addrspace(1)] }, ptr 
addrspace(1) @_ZTVN4Test1DE, i32 0, i32 1, i32 6), ptr addrspace(1) 
getelementptr inbounds inrange(-24, 0) ({ [5 x ptr addrspace(1)], [7 x ptr 
addrspace(1)], [4 x ptr addrspace(1)], [3 x ptr addrspace(1)] }, ptr 
addrspace(1) @_ZTVN4Test1DE, i32 0, i32 3, i32 3), ptr addrspace(1) 
getelementptr inbounds inrange(-24, 0) ({ [3 x ptr addrspace(1)], [4 x ptr 
addrspace(1)] }, ptr addrspace(1) @_ZTCN4Test1DE64_NS_2V2E, i32 0, i32 0, i32 
3), ptr addrspace(1) getelementptr inbounds inrange(-24, 8) ({ [3 x ptr 
addrspace(1)], [4 x ptr addrspace(1)] }, ptr addrspace(1) 
@_ZTCN4Test1DE64_NS_2V2E, i32 0, i32 1, i32 3)], comdat, align 8
-// CHECK: call void @_ZN4Test2V2C2Ev(ptr noundef nonnull align 8 
dereferenceable(20) %2, ptr addrspace(1) noundef getelementptr inbounds ([13 x 
ptr addrspace(1)], ptr addrspace(1) @_ZTTN4Test1DE, i64 0, i64 11))
-// CHECK: call void @_ZN4Test2C1C2Ev(ptr noundef nonnull align 8 
dereferenceable(12) %this1, ptr addrspace(1) noundef getelementptr inbounds 
([13 x ptr addrspace(1)], ptr addrspace(1) @_ZTTN4Test1DE, i64 0, i64 1))
-// CHECK: call void @_ZN4Test2C2C2Ev(ptr noundef nonnull align 8 
dereferenceable(12) %3, ptr addrspace(1) noundef getelementptr inbounds ([13 x 
ptr addrspace(1)], ptr addrspace(1) @_ZTTN4Test1DE, i64 0, i64 3))
+// CHECK: call void @_ZN4Test2V2C2Ev(ptr noundef nonnull align 8 
dereferenceable(20) %2, ptr addrspace(1) noundef getelementptr inbounds (ptr 
addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 11))
+// CHECK: call void @_ZN4Test2C1C2Ev(ptr noundef nonnull align 8 
dereferenceable(12) %this1, ptr addrspace(1) noundef getelementptr inbounds 
(ptr addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 1))
+// CHECK: call void @_ZN4Test2C2C2Ev(ptr noundef nonnull align 8 
dereferenceable(12) %3, ptr addrspace(1) noundef getelementptr inbounds (ptr 
addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 3))
 // CHECK: define linkonce_odr void @_ZN4Test2V2C2Ev(ptr noundef nonnull align 
8 dereferenceable(20) %this, ptr addrspace(1) noundef %vtt)
 // CHECK: define linkonce_odr void @_ZN4Test2C1C2Ev(ptr noundef nonnull align 
8 dereferenceable(12) %this, ptr addrspace(1) noundef %vtt)
 // CHECK: define linkonce_odr void @_ZN4Test2C2C2Ev(ptr noundef nonnull align 
8 dereferenceable(12) %this, ptr addrspace(1) noundef %vtt)
-// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2V2C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(20) %2, ptr addrspace(1) noundef 
getelementptr inbounds ([13 x ptr addrspace(1)], ptr addrspace(1) 
@_ZTTN4Test1DE, i64 0, i64 11))
-// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2C1C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(12) %this1, ptr addrspace(1) noundef 
getelementptr inbounds ([13 x ptr addrspace(1)], ptr addrspace(1) 
@_ZTTN4Test1DE, i64 0, i64 1))
-// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2C2C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(12) %3, ptr addrspace(1) noundef 
getelementptr inbounds ([13 x ptr addrspace(1)], ptr addrspace(1) 
@_ZTTN4Test1DE, i64 0, i64 3))
+// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2V2C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(20) %2, ptr addrspace(1) noundef 
getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 
11))
+// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2C1C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(12) %this1, ptr addrspace(1) noundef 
getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 
1))
+// WITH-NONZERO-DEFAULT-AS: call {{.*}} void @_ZN4Test2C2C2Ev(ptr addrspace(4) 
noundef align 8 dereferenceable_or_null(12) %3, ptr addrspace(1) noundef 
getelementptr inbounds (ptr addrspace(1), ptr addrspace(1) @_ZTTN4Test1DE, i64 
3))
 // WITH-NONZERO-DEFAULT-AS: define linkonce_odr {{.*}} void 
@_ZN4Test2V2C2Ev(ptr addrspace(4) noundef align 8 dereferenceable_or_null(20) 
%this, ptr addrspace(1) noundef %vtt)
 // WITH-NONZERO-DEFAULT-AS: define linkonce_odr {{.*}} void 
@_ZN4Test2C1C2Ev(ptr addrspace(4) noundef align 8 dereferenceable_or_null(12) 
%this, ptr addrspace(1) noundef %vtt)
 // WITH-NONZERO-DEFAULT-AS: define linkonce_odr {{.*}} void 
@_ZN4Test2C2C2Ev(ptr addrspace(4) noundef align 8 dereferenceable_or_null(12) 
%this, ptr addrspace(1) noundef %vtt)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to