Skip to content

Commit c2d9f25

Browse files
[clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace (#94346)
The `llvm.invariant.start` intrinsic is already overloaded to work with memory objects in any address space. We simply instantiate the intrinsic with the appropriate pointer type. Fixes #94345. Co-authored-by: Vito Kortbeek <[email protected]>
1 parent 6d973b4 commit c2d9f25

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) {
162162
// Grab the llvm.invariant.start intrinsic.
163163
llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
164164
// Overloaded address space type.
165-
llvm::Type *ObjectPtr[1] = {Int8PtrTy};
165+
assert(Addr->getType()->isPointerTy() && "Address must be a pointer");
166+
llvm::Type *ObjectPtr[1] = {Addr->getType()};
166167
llvm::Function *InvariantStart = CGM.getIntrinsic(InvStartID, ObjectPtr);
167168

168169
// Emit a call with the size in bytes of the object.

clang/test/CodeGenCXX/init-invariant.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extern const C c = C();
4646
int f();
4747
// CHECK: @d ={{.*}} global i32 0
4848
extern const int d = f();
49+
// CHECK: @d2 ={{.*}} addrspace(10) global i32 0
50+
extern const int __attribute__((address_space(10))) d2 = f();
4951

5052
void e() {
5153
static const A a = A();
@@ -67,6 +69,10 @@ void e() {
6769
// CHECK: store {{.*}}, ptr @d
6870
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d)
6971

72+
// CHECK: call noundef i32 @_Z1fv(
73+
// CHECK: store {{.*}}, ptr addrspace(10) @d2
74+
// CHECK: call {{.*}}@llvm.invariant.start.p10(i64 4, ptr addrspace(10) @d2)
75+
7076
// CHECK-LABEL: define{{.*}} void @_Z1ev(
7177
// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)
7278
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)

0 commit comments

Comments
 (0)