Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -858,6 +858,17 @@ assert(C.getAsConstantArrayType(Ty) && "StringLiteral must be of constant array type!"); + // OpenCL v1.1 s6.5.3: a string literal is in the constant address space. + assert((!C.getLangOpts().OpenCL || + (C.getLangOpts().OpenCL && + (Ty.getAddressSpace() == LangAS::Default || + Ty.getAddressSpace() == LangAS::opencl_constant))) && + "StringLiteral must either have no address space or constant address " + "space!"); + + if (C.getLangOpts().OpenCL && Ty.getAddressSpace() == LangAS::Default) + Ty = C.getAddrSpaceQualType(Ty, LangAS::opencl_constant); + // Allocate enough space for the StringLiteral plus an array of locations for // any concatenated string tokens. void *Mem = @@ -881,7 +892,10 @@ void *Mem = C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), alignof(StringLiteral)); - StringLiteral *SL = new (Mem) StringLiteral(QualType()); + StringLiteral *SL = new (Mem) StringLiteral( + C.getLangOpts().OpenCL + ? C.getAddrSpaceQualType(QualType(), LangAS::opencl_constant) + : QualType()); SL->CharByteWidth = 0; SL->Length = 0; SL->NumConcatenated = NumStrs; Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3052,6 +3052,8 @@ /*Pascal*/ false, ResTy, Loc); } else { ResTy = Context.CharTy.withConst(); + if (LangOpts.OpenCL) + ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant); ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, /*IndexTypeQuals*/ 0); SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii, Index: test/SemaOpenCL/predefined-expr.cl =================================================================== --- /dev/null +++ test/SemaOpenCL/predefined-expr.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify + +void f() { + char *f1 = __func__; //expected-error{{initializing 'char *' with an expression of type 'const __constant char *' changes address space of pointer}} + constant char *f2 = __func__; //expected-warning{{initializing '__constant char *' with an expression of type 'const __constant char [2]' discards qualifiers}} + constant const char *f3 = __func__; +}