r194717 - [OpenCL] Make sure we put string literals in the constant address space.
Joey Gouly
joey.gouly at arm.com
Thu Nov 14 10:26:10 PST 2013
Author: joey
Date: Thu Nov 14 12:26:10 2013
New Revision: 194717
URL: http://llvm.org/viewvc/llvm-project?rev=194717&view=rev
Log:
[OpenCL] Make sure we put string literals in the constant address space.
Added:
cfe/trunk/test/CodeGenOpenCL/str_literals.cl
cfe/trunk/test/SemaOpenCL/str_literals.cl
Modified:
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=194717&r1=194716&r2=194717&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Thu Nov 14 12:26:10 2013
@@ -592,6 +592,8 @@ static Cl::ModifiableType IsModifiable(A
// 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())
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=194717&r1=194716&r2=194717&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Nov 14 12:26:10 2013
@@ -2625,11 +2625,16 @@ static llvm::GlobalVariable *GenerateStr
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;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=194717&r1=194716&r2=194717&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Nov 14 12:26:10 2013
@@ -1517,6 +1517,11 @@ Sema::ActOnStringLiteral(const Token *St
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,
Added: cfe/trunk/test/CodeGenOpenCL/str_literals.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/str_literals.cl?rev=194717&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/str_literals.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/str_literals.cl Thu Nov 14 12:26:10 2013
@@ -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)*
Added: cfe/trunk/test/SemaOpenCL/str_literals.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/str_literals.cl?rev=194717&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/str_literals.cl (added)
+++ cfe/trunk/test/SemaOpenCL/str_literals.cl Thu Nov 14 12:26:10 2013
@@ -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);
+}
More information about the cfe-commits
mailing list