From: Anastasia Stulova Date: Thu, 16 Feb 2017 11:13:30 +0000 (+0000) Subject: [OpenCL] Disallow blocks capture other blocks (v2.0, s6.12.5) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20a51bfa6c1c2fdb159b1e53340b8488c966b9a1;p=clang [OpenCL] Disallow blocks capture other blocks (v2.0, s6.12.5) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295307 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6049d488de..615050603d 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -8299,6 +8299,8 @@ def err_opencl_invalid_block_declaration : Error< "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< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 39116f9c1e..ce4c22bb7f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -13565,6 +13565,13 @@ static bool isVariableCapturable(CapturingScopeInfo *CSI, VarDecl *Var, } 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; } diff --git a/test/SemaOpenCL/invalid-block.cl b/test/SemaOpenCL/invalid-block.cl index 598784c95a..89bf03264e 100644 --- a/test/SemaOpenCL/invalid-block.cl +++ b/test/SemaOpenCL/invalid-block.cl @@ -66,3 +66,18 @@ void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type '__generic bl2_t' (a *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; +}