Adding the last restriction from s6.12.5 OpenCL C v2.0.
"A Block cannot reference or capture another Block variable declared in the outer scope".
Differential D29764
[OpenCL] Blocks cannot capture/reference another block Anastasia on Feb 9 2017, 7:34 AM. Authored by
Details
Adding the last restriction from s6.12.5 OpenCL C v2.0. "A Block cannot reference or capture another Block variable declared in the outer scope".
Diff Detail Event TimelineComment Actions Looking at "Example 4" in the standard it looks like this should also be illegal. int (^block1)(void) = ^int {return 1;}; int foo() { return block1(); } __kernel void k(global int *z) { int (^block2)(void) = ^int { return foo(); // expected-error {{cannot refer to a block inside block}} }; } Unless I missed something it's not erroring in this case. Comment Actions To diagnose this needs to traverse the AST tree. I think it is too much to do it during parsing. It may be done through static analysis though. Comment Actions Yes, it will require quite some expensive checks to implement visiting the AST to trace back the block variables declared in other functions. Additionally this example doesn't seem to cause any issues really. It is mainly in the case with blocks captured from the stack: kernel void foo() { bl2_t bl1 = ^(int i) { return 1; }; void (^bl2)(void) = ^{ int i = bl1(1); // expected-error {{cannot refer to a block inside block}} }; } }
|
v0 is not used!