summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiuli Pan <xiulipan@outlook.com>2016-06-07 04:34:00 +0000
committerXiuli Pan <xiulipan@outlook.com>2016-06-07 04:34:00 +0000
commit244e3f69e400aac91045acc6f0be1371da6c7cd6 (patch)
tree97c6577ae26ffa07184d594adc75071a188dc1e3
parentcc1fb35705c5d2f83345e50a362779691f752ec9 (diff)
downloadbcm5719-llvm-244e3f69e400aac91045acc6f0be1371da6c7cd6.tar.gz
bcm5719-llvm-244e3f69e400aac91045acc6f0be1371da6c7cd6.zip
[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 llvm-svn: 271978
-rw-r--r--clang/lib/AST/ExprConstant.cpp5
-rw-r--r--clang/lib/Sema/SemaType.cpp3
-rw-r--r--clang/test/CodeGenOpenCL/vla.cl18
3 files changed, 24 insertions, 2 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 8c24b0333e1..e14330cf60e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2745,7 +2745,10 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
} 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);
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 9786f7fb4f8..ddcdef84310 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2063,7 +2063,8 @@ static bool isArraySizeVLA(Sema &S, Expr *ArraySize, llvm::APSInt &SizeVal) {
} Diagnoser;
return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
- S.LangOpts.GNUMode).isInvalid();
+ S.LangOpts.GNUMode ||
+ S.LangOpts.OpenCL).isInvalid();
}
/// \brief Build an array type.
diff --git a/clang/test/CodeGenOpenCL/vla.cl b/clang/test/CodeGenOpenCL/vla.cl
new file mode 100644
index 00000000000..cbf98445ce0
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/vla.cl
@@ -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];
+}
OpenPOWER on IntegriCloud