diff options
author | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2020-09-22 12:52:07 -0400 |
---|---|---|
committer | Yaxun (Sam) Liu <yaxun.liu@amd.com> | 2020-09-23 08:18:19 -0400 |
commit | 301e23305d03cfb4004f845a1d9dfdc5e5931fd8 (patch) | |
tree | c3a992eb5e0132b556c10fc68c8ee1d74ba73f83 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | bd72ed93d22a1579362859e64a0c7f9c68460cf8 (diff) | |
download | llvm-301e23305d03cfb4004f845a1d9dfdc5e5931fd8.zip llvm-301e23305d03cfb4004f845a1d9dfdc5e5931fd8.tar.gz llvm-301e23305d03cfb4004f845a1d9dfdc5e5931fd8.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 3ecc874..6a77f6b 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; |