Anastasia created this revision.
Anastasia added reviewers: yaxunl, bader.

String literals must be in `constant` address space.


https://reviews.llvm.org/D46049

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/predefind-expr.cl


Index: test/SemaOpenCL/predefind-expr.cl
===================================================================
--- /dev/null
+++ test/SemaOpenCL/predefind-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__;
+}
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/predefind-expr.cl
===================================================================
--- /dev/null
+++ test/SemaOpenCL/predefind-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__;
+}
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,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to