diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-11-29 17:01:19 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-11-29 17:01:19 +0000 |
commit | e4a1c38109dd21c92e0dd6f233a047d9ac862dbe (patch) | |
tree | 51dc41488bfcc6b4d16b32d57dec65dddae68a62 /clang/lib/CodeGen/CGDecl.cpp | |
parent | bca5fd4f812db9fc692029ebb35fce5871fe6c24 (diff) | |
download | bcm5719-llvm-e4a1c38109dd21c92e0dd6f233a047d9ac862dbe.tar.gz bcm5719-llvm-e4a1c38109dd21c92e0dd6f233a047d9ac862dbe.zip |
[OpenCL] Prevent generation of globals in non-constant AS for OpenCL.
Avoid using shortcut for const qualified non-constant address space
aggregate variables while generating them on the stack such that
the alloca object is used instead of a global variable containing
initializer.
Review: https://reviews.llvm.org/D27109
llvm-svn: 288163
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 5ad709d0b80..695e92ea1d0 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -948,8 +948,12 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) { // If the variable's a const type, and it's neither an NRVO // candidate nor a __block variable and has no mutable members, // emit it as a global instead. - if (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef && - CGM.isTypeConstant(Ty, true)) { + // Exception is if a variable is located in non-constant address space + // in OpenCL. + if ((!getLangOpts().OpenCL || + Ty.getAddressSpace() == LangAS::opencl_constant) && + (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef && + CGM.isTypeConstant(Ty, true))) { EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); // Signal this condition to later callbacks. |