[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 03:12:06 PDT 2018


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46049.143886.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180425/e67adbb9/attachment.bin>


More information about the cfe-commits mailing list