Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1014,6 +1014,7 @@ Opts.LaxVectorConversions = 0; Opts.DefaultFPContract = 1; Opts.NativeHalfType = 1; + Opts.ConstStrings = 1; } if (LangStd == LangStandard::lang_cuda) Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -1467,6 +1467,11 @@ if (getLangOpts().CPlusPlus || getLangOpts().ConstStrings) StrTy.addConst(); + // 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); + } + // Get an array type for the string, according to C99 6.4.5. This includes // the nul terminator character as well as the string length for pascal // strings. Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -3829,6 +3829,10 @@ unsigned ASIdx = static_cast(addrSpace.getZExtValue()); Type = S.Context.getAddrSpaceQualType(Type, ASIdx); + + // Constant address space implies const qualifier + if(S.getLangOpts().OpenCL && ASIdx == LangAS::opencl_constant) + Type = S.Context.getConstType(Type); } /// Does this type have a "direct" ownership qualifier? That is, Index: test/CodeGenOpenCL/opencl_types.cl =================================================================== --- test/CodeGenOpenCL/opencl_types.cl +++ test/CodeGenOpenCL/opencl_types.cl @@ -1,7 +1,7 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s constant sampler_t glb_smp = 7; -// CHECK: global i32 7 +// CHECK: constant i32 7 void fnc1(image1d_t img) {} // CHECK: @fnc1(%opencl.image1d_t* Index: test/SemaOpenCL/address-spaces.cl =================================================================== --- test/SemaOpenCL/address-spaces.cl +++ test/SemaOpenCL/address-spaces.cl @@ -9,5 +9,5 @@ int *ip; ip = gip; // expected-error {{assigning '__global int *' to 'int *' changes address space of pointer}} ip = &li; // expected-error {{assigning '__local int *' to 'int *' changes address space of pointer}} - ip = &ci; // expected-error {{assigning '__constant int *' to 'int *' changes address space of pointer}} + ip = &ci; // expected-error {{assigning 'const __constant int *' to 'int *' changes address space of pointer}} } Index: test/SemaOpenCL/str_literals.cl =================================================================== --- /dev/null +++ test/SemaOpenCL/str_literals.cl @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -verify +// expected-no-diagnostics + +__constant char * __constant x = "hello world"; + +void foo(__constant char * a) { + +} + +void bar() { + foo("hello world"); +}