diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 4bf0aba27692c..43375bc39acab 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3396,6 +3396,13 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) { return AddrSpace; } + if (LangOpts.SYCLIsDevice) { + if (D && D->getType().isConstQualified()) + return LangAS::opencl_constant; + + return LangAS::opencl_global; + } + if (LangOpts.CUDA && LangOpts.CUDAIsDevice) { if (D && D->hasAttr()) return LangAS::cuda_constant; diff --git a/clang/test/CodeGenSYCL/address-space-new.cpp b/clang/test/CodeGenSYCL/address-space-new.cpp index 15df1b64e032d..e120bc36b8d5b 100644 --- a/clang/test/CodeGenSYCL/address-space-new.cpp +++ b/clang/test/CodeGenSYCL/address-space-new.cpp @@ -3,11 +3,17 @@ void test() { + static const int foo = 0x42; + // CHECK-DEFAULT: @_ZZ4testvE3foo = internal addrspace(2) constant i32 66, align 4 + // CHECK-NEW: @_ZZ4testvE3foo = internal addrspace(2) constant i32 66, align 4 + int i = 0; int *pptr = &i; // CHECK-DEFAULT: store i32* %i, i32** %pptr // CHECK-NEW: %[[GEN:[0-9]+]] = addrspacecast i32* %i to i32 addrspace(4)* // CHECK-NEW: store i32 addrspace(4)* %[[GEN]], i32 addrspace(4)** %pptr + + *pptr = foo; }