diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4438,7 +4438,9 @@ if (GV && LangOpts.CUDA) { if (LangOpts.CUDAIsDevice) { if (Linkage != llvm::GlobalValue::InternalLinkage && - (D->hasAttr() || D->hasAttr())) + (D->hasAttr() || D->hasAttr() || + D->getType()->isCUDADeviceBuiltinSurfaceType() || + D->getType()->isCUDADeviceBuiltinTextureType())) GV->setExternallyInitialized(true); } else { getCUDARuntime().internalizeDeviceSideVar(D, Linkage); diff --git a/clang/test/CodeGenCUDA/surface.cu b/clang/test/CodeGenCUDA/surface.cu --- a/clang/test/CodeGenCUDA/surface.cu +++ b/clang/test/CodeGenCUDA/surface.cu @@ -19,7 +19,7 @@ }; // On the device side, surface references are represented as `i64` handles. -// DEVICE: @surf ={{.*}} addrspace(1) global i64 undef, align 4 +// DEVICE: @surf ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 // On the host side, they remain in the original type. // HOST: @surf = internal global %struct.surface // HOST: @0 = private unnamed_addr constant [5 x i8] c"surf\00" diff --git a/clang/test/CodeGenCUDA/texture.cu b/clang/test/CodeGenCUDA/texture.cu --- a/clang/test/CodeGenCUDA/texture.cu +++ b/clang/test/CodeGenCUDA/texture.cu @@ -19,8 +19,8 @@ }; // On the device side, texture references are represented as `i64` handles. -// DEVICE: @tex ={{.*}} addrspace(1) global i64 undef, align 4 -// DEVICE: @norm ={{.*}} addrspace(1) global i64 undef, align 4 +// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 +// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4 // On the host side, they remain in the original type. // HOST: @tex = internal global %struct.texture // HOST: @norm = internal global %struct.texture