[PATCH] D26794: [OpenCL] Blocks are allowed to capture arrays in OpenCL 2.0 and higher.
Egor Churaev via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 17 05:44:34 PST 2016
echuraev created this revision.
echuraev added a reviewer: Anastasia.
echuraev added subscribers: cfe-commits, yaxunl, bader.
https://reviews.llvm.org/D26794
Files:
lib/Sema/SemaExpr.cpp
test/SemaOpenCL/blocks_with_arrays.cl
Index: test/SemaOpenCL/blocks_with_arrays.cl
===================================================================
--- /dev/null
+++ test/SemaOpenCL/blocks_with_arrays.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+ int a[3] = {1, 2, 3};
+ block_t b = ^() {
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i64 0, i64 0
+ return a[0];
+ };
+ return b();
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13477,13 +13477,16 @@
bool ByRef = false;
// Blocks are not allowed to capture arrays.
- if (CaptureType->isArrayType()) {
- if (BuildAndDiagnose) {
- S.Diag(Loc, diag::err_ref_array_type);
- S.Diag(Var->getLocation(), diag::note_previous_decl)
- << Var->getDeclName();
+ // Only if it's not OpenCL 2.0.
+ if (!(S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200)) {
+ if (CaptureType->isArrayType()) {
+ if (BuildAndDiagnose) {
+ S.Diag(Loc, diag::err_ref_array_type);
+ S.Diag(Var->getLocation(), diag::note_previous_decl)
+ << Var->getDeclName();
+ }
+ return false;
}
- return false;
}
// Forbid the block-capture of autoreleasing variables.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26794.78351.patch
Type: text/x-patch
Size: 1443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161117/0de4ce90/attachment.bin>
More information about the cfe-commits
mailing list