[PATCH] D20090: [OPENCL] Fix wrongly vla error for OpenCL array.
Xiuli PAN via cfe-commits
cfe-commits at lists.llvm.org
Tue May 10 01:03:22 PDT 2016
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, &SizeVal, Diagnoser,
- S.LangOpts.GNUMode).isInvalid();
+ return S
+ .VerifyIntegerConstantExpression(ArraySize, &SizeVal, 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20090.56670.patch
Type: text/x-patch
Size: 2207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160510/00c70bbe/attachment.bin>
More information about the cfe-commits
mailing list