[PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2020-10-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaType.cpp:2067
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }

This looks wrong to me. The OpenCL rules don't permit arbitrary constant 
folding in array bounds.

If OpenCL intends to permit reading from const globals of integral types in 
constant expressions (as C++ does but C does not), then the right way to handle 
that would be to change `CheckICE` to permit such cases, as it does in C++ 
mode, not to enable arbitrary constant folding in array bounds.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D20090/new/

https://reviews.llvm.org/D20090

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-06-06 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL271971: [OPENCL] Fix wrongly vla error for OpenCL array. 
(authored by pxl).

Changed prior to commit:
  http://reviews.llvm.org/D20090?vs=58932=59823#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20090

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

Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -2745,7 +2745,10 @@
   } 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);
Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: cfe/trunk/test/CodeGenOpenCL/vla.cl
===
--- cfe/trunk/test/CodeGenOpenCL/vla.cl
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}


Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -2745,7 +2745,10 @@
   } 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);
Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: cfe/trunk/test/CodeGenOpenCL/vla.cl
===
--- cfe/trunk/test/CodeGenOpenCL/vla.cl
+++ cfe/trunk/test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-06-03 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.

LGTM! Thanks!


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-29 Thread Xiuli PAN via cfe-commits
pxli168 updated this revision to Diff 58932.
pxli168 added a comment.

Make all tests in OpenCL 2.0.


http://reviews.llvm.org/D20090

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/vla.cl

Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2740,7 +2740,10 @@
   } 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);


Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+const global int sz1 = 16;
+// CHECK: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CHECK: @sz2 = constant i32 8, align 4
+// CHECK: @testvla.vla2 = internal global [8 x i16] undef, align 16
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+  char vla1[sz1];
+// CHECK: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@
   } Diagnoser;
 
   return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+   S.LangOpts.GNUMode ||
+   S.LangOpts.OpenCL).isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2740,7 +2740,10 @@
   } 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);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-27 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

pxli168 wrote:
> Anastasia wrote:
> > pxli168 wrote:
> > > Anastasia wrote:
> > > > Could we have a Sema test instead where we accept the VLA if constant 
> > > > AS object is used and give an error otherwise?
> > > > 
> > > > Also do we need to test CL2.0? We don't seem to be doing anything 
> > > > different for that version. 
> > > In earier than OpenCL1.2  program scope variable must reside in constant 
> > > address space and no
> > > ```
> > > const global int
> > > ```
> > > can be here.
> > > But const global value should also not be seen as VLA either.
> > Why not? Could you write a complete example perhaps? I am not sure I 
> > understand your point.
> > 
> > Thanks!
> Oh, I mean that in OpenCL 1.2 there will be some error message with
> ```
> const global int
> ```
> But I want to have a test with something that not only with the constant 
> address space.
> Or what you suggest is that I make all the test in OpenCL 2.0?
Yes, I think this should be enough for testing your change.


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-26 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

Anastasia wrote:
> pxli168 wrote:
> > Anastasia wrote:
> > > Formatting looks weird though... may be better to leave the first line 
> > > unmodified?
> > I felt very strange, too. But this is what clang-format gives me.
> I see. clang-format doesn't take readability into account unfortunately. :)
> 
> Let's just leave the first line of this change unmodified at least to make it 
> more readable.
OK, I also found the clang-format can do some strange thing.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

Anastasia wrote:
> pxli168 wrote:
> > Anastasia wrote:
> > > Could we have a Sema test instead where we accept the VLA if constant AS 
> > > object is used and give an error otherwise?
> > > 
> > > Also do we need to test CL2.0? We don't seem to be doing anything 
> > > different for that version. 
> > In earier than OpenCL1.2  program scope variable must reside in constant 
> > address space and no
> > ```
> > const global int
> > ```
> > can be here.
> > But const global value should also not be seen as VLA either.
> Why not? Could you write a complete example perhaps? I am not sure I 
> understand your point.
> 
> Thanks!
Oh, I mean that in OpenCL 1.2 there will be some error message with
```
const global int
```
But I want to have a test with something that not only with the constant 
address space.
Or what you suggest is that I make all the test in OpenCL 2.0?


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-12 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

pxli168 wrote:
> Anastasia wrote:
> > Formatting looks weird though... may be better to leave the first line 
> > unmodified?
> I felt very strange, too. But this is what clang-format gives me.
I see. clang-format doesn't take readability into account unfortunately. :)

Let's just leave the first line of this change unmodified at least to make it 
more readable.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

pxli168 wrote:
> Anastasia wrote:
> > Could we have a Sema test instead where we accept the VLA if constant AS 
> > object is used and give an error otherwise?
> > 
> > Also do we need to test CL2.0? We don't seem to be doing anything different 
> > for that version. 
> In earier than OpenCL1.2  program scope variable must reside in constant 
> address space and no
> ```
> const global int
> ```
> can be here.
> But const global value should also not be seen as VLA either.
Why not? Could you write a complete example perhaps? I am not sure I understand 
your point.

Thanks!


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

Anastasia wrote:
> Formatting looks weird though... may be better to leave the first line 
> unmodified?
I felt very strange, too. But this is what clang-format gives me.


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

Anastasia wrote:
> Could we have a Sema test instead where we accept the VLA if constant AS 
> object is used and give an error otherwise?
> 
> Also do we need to test CL2.0? We don't seem to be doing anything different 
> for that version. 
In earier than OpenCL1.2  program scope variable must reside in constant 
address space and no
```
const global int
```
can be here.
But const global value should also not be seen as VLA either.


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/Sema/SemaType.cpp:2055
@@ -2054,3 +2054,3 @@
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,

Formatting looks weird though... may be better to leave the first line 
unmodified?


Comment at: test/CodeGenOpenCL/vla.cl:1
@@ +1,2 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20

Could we have a Sema test instead where we accept the VLA if constant AS object 
is used and give an error otherwise?

Also do we need to test CL2.0? We don't seem to be doing anything different for 
that version. 


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Alexey Bader via cfe-commits
bader accepted this revision.
bader added a reviewer: bader.
bader added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Yaxun Liu via cfe-commits
yaxunl added a comment.

LGTM. Thanks.


http://reviews.llvm.org/D20090



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.

2016-05-10 Thread Xiuli PAN via cfe-commits
pxli168 created this revision.
pxli168 added reviewers: Anastasia, yaxunl.
pxli168 added subscribers: cfe-commits, bader.

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


http://reviews.llvm.org/D20090

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/vla.cl

Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s 
--check-prefix=CL20
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+#ifdef CL20
+const global int sz1 = 16;
+// CL20: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CL20: @sz2 = constant i32 8, align 4
+// CL20: @testvla.vla2 = internal global [8 x i16] undef, align 16
+#endif
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+#ifdef CL20
+  char vla1[sz1];
+// CL20: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+#endif
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2052,8 +2052,10 @@
 }
   } Diagnoser;
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
+   S.LangOpts.GNUMode || S.LangOpts.OpenCL)
+  .isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2685,7 +2685,10 @@
   } 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);


Index: test/CodeGenOpenCL/vla.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/vla.cl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -DCL20 -o - %s | FileCheck %s --check-prefix=CL20
+
+constant int sz0 = 5;
+// CHECK: @sz0 = constant i32 5, align 4
+#ifdef CL20
+const global int sz1 = 16;
+// CL20: @sz1 = constant i32 16, align 4
+const constant int sz2 = 8;
+// CL20: @sz2 = constant i32 8, align 4
+// CL20: @testvla.vla2 = internal global [8 x i16] undef, align 16
+#endif
+
+kernel void testvla()
+{
+  int vla0[sz0];
+// CHECK: %vla0 = alloca [5 x i32], align 16
+#ifdef CL20
+  char vla1[sz1];
+// CL20: %vla1 = alloca [16 x i8], align 16
+  local short vla2[sz2];
+#endif
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2052,8 +2052,10 @@
 }
   } Diagnoser;
 
-  return S.VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
-   S.LangOpts.GNUMode).isInvalid();
+  return S
+  .VerifyIntegerConstantExpression(ArraySize, , Diagnoser,
+   S.LangOpts.GNUMode || S.LangOpts.OpenCL)
+  .isInvalid();
 }
 
 /// \brief Build an array type.
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -2685,7 +2685,10 @@
   } 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);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits