r295307 - [OpenCL] Disallow blocks capture other blocks (v2.0, s6.12.5)

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 16 03:13:30 PST 2017


Author: stulova
Date: Thu Feb 16 05:13:30 2017
New Revision: 295307

URL: http://llvm.org/viewvc/llvm-project?rev=295307&view=rev
Log:
[OpenCL] Disallow blocks capture other blocks (v2.0, s6.12.5)


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaOpenCL/invalid-block.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=295307&r1=295306&r2=295307&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Feb 16 05:13:30 2017
@@ -8299,6 +8299,8 @@ def err_opencl_invalid_block_declaration
   "invalid block variable declaration - must be %select{const qualified|initialized}0">;
 def err_opencl_extern_block_declaration : Error<
   "invalid block variable declaration - using 'extern' storage class is disallowed">;
+def err_opencl_block_ref_block : Error<
+  "cannot refer to a block inside block">;
 
 // OpenCL v2.0 s6.13.9 - Address space qualifier functions. 
 def err_opencl_builtin_to_addr_arg_num : Error<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=295307&r1=295306&r2=295307&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 16 05:13:30 2017
@@ -13565,6 +13565,13 @@ static bool isVariableCapturable(Capturi
     }
     return false;
   }
+  // OpenCL v2.0 s6.12.5: Blocks cannot reference/capture other blocks
+  if (S.getLangOpts().OpenCL && IsBlock &&
+      Var->getType()->isBlockPointerType()) {
+    if (Diagnose)
+      S.Diag(Loc, diag::err_opencl_block_ref_block);
+    return false;
+  }
 
   return true;
 }

Modified: cfe/trunk/test/SemaOpenCL/invalid-block.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-block.cl?rev=295307&r1=295306&r2=295307&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl Thu Feb 16 05:13:30 2017
@@ -66,3 +66,18 @@ void f6(bl2_t *bl_ptr) { // expected-err
   *bl;      // expected-error {{invalid argument type 'bl2_t' (aka 'int (__generic ^const)(int)') to unary expression}}
   &bl;      // expected-error {{invalid argument type 'bl2_t' (aka 'int (__generic ^const)(int)') to unary expression}}
 }
+// A block can't reference another block
+kernel void f7() {
+  bl2_t bl1 = ^(int i) {
+    return 1;
+  };
+  void (^bl2)(void) = ^{
+    int i = bl1(1); // expected-error {{cannot refer to a block inside block}}
+  };
+  void (^bl3)(void) = ^{
+  };
+  void (^bl4)(void) = ^{
+    bl3(); // expected-error {{cannot refer to a block inside block}}
+  };
+  return;
+}




More information about the cfe-commits mailing list