r271978 - [OPENCL] Fix wrongly vla error for OpenCL array.

Xiuli Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 6 21:34:00 PDT 2016


Author: pxl
Date: Mon Jun  6 23:34:00 2016
New Revision: 271978

URL: http://llvm.org/viewvc/llvm-project?rev=271978&view=rev
Log:
[OPENCL] Fix wrongly vla error for OpenCL array.

Summary:
OpenCL should support array with const value size length, those const
varibale in global and constant address space and variable in constant
address space.

Fixed test case error.

Reviewers: Anastasia, yaxunl, bader

Subscribers: bader, cfe-commits

Differential Revision: http://reviews.llvm.org/D20090

Added:
    cfe/trunk/test/CodeGenOpenCL/vla.cl
Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=271978&r1=271977&r2=271978&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun  6 23:34:00 2016
@@ -2745,7 +2745,10 @@ static CompleteObject findCompleteObject
       } else if (VD->isConstexpr()) {
         // OK, we can read this variable.
       } else if (BaseType->isIntegralOrEnumerationType()) {
-        if (!BaseType.isConstQualified()) {
+        // In OpenCL if a variable is in constant address space it is a const value.
+        if (!(BaseType.isConstQualified() ||
+              (Info.getLangOpts().OpenCL &&
+               BaseType.getAddressSpace() == LangAS::opencl_constant))) {
           if (Info.getLangOpts().CPlusPlus) {
             Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
             Info.Note(VD->getLocation(), diag::note_declared_at);

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=271978&r1=271977&r2=271978&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun  6 23:34:00 2016
@@ -2063,7 +2063,8 @@ static bool isArraySizeVLA(Sema &S, Expr
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
-                                           S.LangOpts.GNUMode).isInvalid();
+                                           S.LangOpts.GNUMode ||
+                                           S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.

Added: cfe/trunk/test/CodeGenOpenCL/vla.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vla.cl?rev=271978&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/vla.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl Mon Jun  6 23:34:00 2016
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -triple "spir-unknown-unknown" -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = addrspace(2) constant i32 5
+const global int sz1 = 16;
+// CHECK: @sz1 = addrspace(1) constant i32 16
+const constant int sz2 = 8;
+// CHECK: @sz2 = addrspace(2) constant i32 8
+// CHECK: @testvla.vla2 = internal addrspace(3) global [8 x i16] undef
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32]
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8]
+  local short vla2[sz2];
+}




More information about the cfe-commits mailing list