Skip to content

Commit c7b96d3

Browse files
committed
Fix conflict resolution in Ctor for Device Global (#15218)
device global code conflict with 6e45fa9 Fix failure: Clang::CodeGenSYCL/device_global.cpp
1 parent cb2cc2f commit c7b96d3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,8 +2205,17 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
22052205
llvm::PointerType *PtrTy = llvm::PointerType::get(
22062206
getLLVMContext(), TheModule.getDataLayout().getProgramAddressSpace());
22072207

2208+
llvm::PointerType *TargetType = PtrTy;
2209+
// Get target type when templated global variables are used,
2210+
// to emit them correctly in the target (default) address space and avoid
2211+
// emitting them in a private address space.
2212+
if (getLangOpts().SYCLIsDevice)
2213+
TargetType = llvm::PointerType::get(
2214+
getLLVMContext(), getContext().getTargetAddressSpace(LangAS::Default));
2215+
2216+
22082217
// Get the type of a ctor entry, { i32, ptr, ptr }.
2209-
llvm::StructType *CtorStructTy = llvm::StructType::get(Int32Ty, PtrTy, PtrTy);
2218+
llvm::StructType *CtorStructTy = llvm::StructType::get(Int32Ty, PtrTy, TargetType);
22102219

22112220
// Construct the constructor and destructor arrays.
22122221
ConstantInitBuilder Builder(*this);
@@ -2232,9 +2241,10 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
22322241
Ctor.add(I.Initializer);
22332242
}
22342243
if (I.AssociatedData)
2235-
Ctor.add(I.AssociatedData);
2244+
Ctor.add(llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
2245+
I.AssociatedData, TargetType));
22362246
else
2237-
Ctor.addNullPointer(PtrTy);
2247+
Ctor.addNullPointer(TargetType);
22382248
Ctor.finishAndAddTo(Ctors);
22392249
}
22402250

0 commit comments

Comments
 (0)