diff options
author | Artem Belevich <tra@google.com> | 2016-02-02 22:29:48 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2016-02-02 22:29:48 +0000 |
commit | 97c01c35f8da48b47c397fd915a82bd1d881d4ab (patch) | |
tree | 06d8b1e2ae200287569e9ad71bdaa548e5ef75d6 /clang/lib/CodeGen/CGDeclCXX.cpp | |
parent | 8abc2e51b81efe2f540f6a61a3028f8fe72fe478 (diff) | |
download | bcm5719-llvm-97c01c35f8da48b47c397fd915a82bd1d881d4ab.tar.gz bcm5719-llvm-97c01c35f8da48b47c397fd915a82bd1d881d4ab.zip |
[CUDA] Do not allow dynamic initialization of global device side variables.
In general CUDA does not allow dynamic initialization of
global device-side variables. One exception is that CUDA allows
records with empty constructors as described in section E2.2.1 of
CUDA 7.5 Programming guide.
This patch applies initializer checks for all device-side variables.
Empty constructors are accepted, but no code is generated for them.
Differential Revision: http://reviews.llvm.org/D15305
llvm-svn: 259592
Diffstat (limited to 'clang/lib/CodeGen/CGDeclCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDeclCXX.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index adba7316879..98d904b1568 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -304,6 +304,17 @@ void CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit) { + + // According to E.2.3.1 in CUDA-7.5 Programming guide: __device__, + // __constant__ and __shared__ variables defined in namespace scope, + // that are of class type, cannot have a non-empty constructor. All + // the checks have been done in Sema by now. Whatever initializers + // are allowed are empty and we just need to ignore them here. + if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice && + (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() || + D->hasAttr<CUDASharedAttr>())) + return; + // Check if we've already initialized this decl. auto I = DelayedCXXInitPosition.find(D); if (I != DelayedCXXInitPosition.end() && I->second == ~0U) |