[OpenCL] Make sure we put string literals in the constant address space.
llvm-svn: 194717
This commit is contained in:
parent
dba2692865
commit
561bba2e9f
|
@ -592,6 +592,8 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E,
|
|||
// Const stuff is obviously not modifiable.
|
||||
if (CT.isConstQualified())
|
||||
return Cl::CM_ConstQualified;
|
||||
if (CT.getQualifiers().getAddressSpace() == LangAS::opencl_constant)
|
||||
return Cl::CM_ConstQualified;
|
||||
|
||||
// Arrays are not modifiable, only their elements are.
|
||||
if (CT->isArrayType())
|
||||
|
|
|
@ -2625,11 +2625,16 @@ static llvm::GlobalVariable *GenerateStringLiteral(StringRef str,
|
|||
llvm::Constant *C =
|
||||
llvm::ConstantDataArray::getString(CGM.getLLVMContext(), str, false);
|
||||
|
||||
// OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
|
||||
unsigned AddrSpace = 0;
|
||||
if (CGM.getLangOpts().OpenCL)
|
||||
AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
|
||||
|
||||
// Create a global variable for this string
|
||||
llvm::GlobalVariable *GV =
|
||||
new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant,
|
||||
llvm::GlobalValue::PrivateLinkage,
|
||||
C, GlobalName);
|
||||
llvm::GlobalVariable *GV = new llvm::GlobalVariable(
|
||||
CGM.getModule(), C->getType(), constant,
|
||||
llvm::GlobalValue::PrivateLinkage, C, GlobalName, 0,
|
||||
llvm::GlobalVariable::NotThreadLocal, AddrSpace);
|
||||
GV->setAlignment(Alignment);
|
||||
GV->setUnnamedAddr(true);
|
||||
return GV;
|
||||
|
|
|
@ -1517,6 +1517,11 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks,
|
|||
llvm::APInt(32, Literal.GetNumStringChars()+1),
|
||||
ArrayType::Normal, 0);
|
||||
|
||||
// OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
|
||||
if (getLangOpts().OpenCL) {
|
||||
StrTy = Context.getAddrSpaceQualType(StrTy, LangAS::opencl_constant);
|
||||
}
|
||||
|
||||
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
|
||||
StringLiteral *Lit = StringLiteral::Create(Context, Literal.GetString(),
|
||||
Kind, Literal.Pascal, StrTy,
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// RUN: %clang_cc1 %s -emit-llvm -o - -ffake-address-space-map | FileCheck %s
|
||||
|
||||
__constant char * __constant x = "hello world";
|
||||
__constant char * __constant y = "hello world";
|
||||
|
||||
// CHECK: addrspace(3) unnamed_addr constant
|
||||
// CHECK-NOT: addrspace(3) unnamed_addr constant
|
||||
// CHECK: @x = addrspace(3) global i8 addrspace(3)*
|
||||
// CHECK: @y = addrspace(3) global i8 addrspace(3)*
|
|
@ -0,0 +1,13 @@
|
|||
// RUN: %clang_cc1 %s -verify
|
||||
// expected-no-diagnostics
|
||||
|
||||
constant char * __constant x = "hello world";
|
||||
|
||||
void foo(__constant char * a) {
|
||||
|
||||
}
|
||||
|
||||
void bar() {
|
||||
foo("hello world");
|
||||
foo(x);
|
||||
}
|
Loading…
Reference in New Issue