Skip to content

[clang][CodeGen] Fix EmitInvariantStart for non-zero addrspace #94346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) {
// Grab the llvm.invariant.start intrinsic.
llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
// Overloaded address space type.
llvm::Type *ObjectPtr[1] = {Int8PtrTy};
assert(Addr->getType()->isPointerTy() && "Address must be a pointer");
llvm::Type *ObjectPtr[1] = {Addr->getType()};
llvm::Function *InvariantStart = CGM.getIntrinsic(InvStartID, ObjectPtr);

// Emit a call with the size in bytes of the object.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGenCXX/init-invariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern const C c = C();
int f();
// CHECK: @d ={{.*}} global i32 0
extern const int d = f();
// CHECK: @d2 ={{.*}} addrspace(10) global i32 0
extern const int __attribute__((address_space(10))) d2 = f();

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

// CHECK: call noundef i32 @_Z1fv(
// CHECK: store {{.*}}, ptr addrspace(10) @d2
// CHECK: call {{.*}}@llvm.invariant.start.p10(i64 4, ptr addrspace(10) @d2)

// CHECK-LABEL: define{{.*}} void @_Z1ev(
// CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)
// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)
Expand Down
Loading