1// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s 2 3// OpenCL v2.0 s6.12.5 4void f0(int (^const bl)()); // expected-error{{declaring function parameter of type 'int (__generic ^const __private)(void)' is not allowed}} 5// All blocks declarations must be const qualified and initialized. 6void f1() { 7 int (^bl1)(void) = ^() { 8 return 1; 9 }; 10 int (^const bl2)(void) = ^() { 11 return 1; 12 }; 13 f0(bl1); 14 f0(bl2); 15 bl1 = bl2; // expected-error{{invalid operands to binary expression ('int (__generic ^const __private)(void)' and 'int (__generic ^const __private)(void)')}} 16 int (^const bl3)(); // expected-error{{invalid block variable declaration - must be initialized}} 17} 18 19// A block with extern storage class is not allowed. 20extern int (^bl)(void) = ^() { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}} 21 return 1; 22}; 23void f2() { 24 extern int (^bl)(void) = ^() { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}} 25 return 1; 26 }; 27} 28 29// A block cannot be the return value or parameter of a function. 30typedef int (^bl_t)(void); 31bl_t f3a(int); // expected-error{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}} 32bl_t f3b(bl_t bl); 33// expected-error@-1{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}} 34// expected-error@-2{{declaring function parameter of type '__private bl_t' (aka 'int (__generic ^const __private)(void)') is not allowed}} 35void f3c() { 36 // Block with a block argument. 37 int (^const bl2)(bl_t block_arg) = ^() { // expected-error{{declaring function parameter of type '__private bl_t' (aka 'int (__generic ^const __private)(void)') is not allowed}} 38 return block_arg(); // expected-error{{implicit declaration of function 'block_arg' is invalid in OpenCL}} 39 }; 40} 41 42struct bl_s { 43 int (^bl)(void); // expected-error {{the 'int (__generic ^const)(void)' type cannot be used to declare a structure or union field}} 44}; 45 46void f4() { 47 __block int a = 10; // expected-error {{the __block storage type is not permitted}} 48} 49 50// A block with variadic argument is not allowed. 51int (^bl)(int, ...) = ^int(int I, ...) { // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} 52 return 0; 53}; 54typedef int (^bl1_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} 55 56// A block can't be used to declare an array 57typedef int (^bl2_t)(int); 58void f5(int i) { 59 bl2_t bl1 = ^(int i) { 60 return 1; 61 }; 62 bl2_t bl2 = ^(int i) { 63 return 2; 64 }; 65 bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL}} 66 int tmp = i ? bl1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} 67 : bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} 68} 69// A block pointer type and all pointer operations are disallowed 70void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}} 71 bl2_t bl = ^(int i) { 72 return 1; 73 }; 74 bl2_t *p; // expected-error {{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}} 75 *bl; // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}} 76 &bl; // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}} 77} 78// A block can't reference another block 79kernel void f7() { 80 bl2_t bl1 = ^(int i) { 81 return 1; 82 }; 83 void (^bl2)(void) = ^{ 84 int i = bl1(1); // expected-error {{cannot refer to a block inside block}} 85 }; 86 void (^bl3)(void) = ^{ 87 }; 88 void (^bl4)(void) = ^{ 89 bl3(); // expected-error {{cannot refer to a block inside block}} 90 }; 91 return; 92} 93 94// Taking address of a capture is not allowed 95int g; 96kernel void f8(int a1) { 97 int a2; 98 void (^bl)(void) = ^(void) { 99 &g; //expected-warning{{expression result unused}} 100 &a1; //expected-error{{taking address of a capture is not allowed}} 101 &a2; //expected-error{{taking address of a capture is not allowed}} 102 }; 103} 104