From 301e23305d03cfb4004f845a1d9dfdc5e5931fd8 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Tue, 22 Sep 2020 12:52:07 -0400 Subject: [CUDA][HIP] Fix static device var used by host code only A static device variable may be accessed in host code through cudaMemCpyFromSymbol etc. Currently clang does not emit the static device variable if it is only referenced by host code, which causes host code to fail at run time. This patch fixes that. Differential Revision: https://reviews.llvm.org/D88115 --- clang/lib/CodeGen/CodeGenModule.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 3ecc8743265c..6a77f6b040a1 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2195,6 +2195,11 @@ void CodeGenModule::EmitDeferred() { assert(DeferredVTables.empty()); } + // Emit CUDA/HIP static device variables referenced by host code only. + if (getLangOpts().CUDA) + for (auto V : getContext().CUDAStaticDeviceVarReferencedByHost) + DeferredDeclsToEmit.push_back(V); + // Stop if we're out of both deferred vtables and deferred declarations. if (DeferredDeclsToEmit.empty()) return; -- cgit v1.2.3