Xiuli Pan | 89307aa | 2016-02-24 04:29:36 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s |
| 2 | |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 3 | // OpenCL v2.0 s6.12.5 |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 4 | void f0(int (^const bl)()); |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 5 | // All blocks declarations must be const qualified and initialized. |
| 6 | void f1() { |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 7 | int (^bl1)() = ^() {return 1;}; |
| 8 | int (^const bl2)() = ^(){return 1;}; |
| 9 | f0(bl1); |
| 10 | f0(bl2); |
| 11 | bl1 = bl2; // expected-error{{invalid operands to binary expression ('int (^const)()' and 'int (^const)()')}} |
| 12 | int (^const bl3)(); // expected-error{{invalid block variable declaration - must be initialized}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | // A block with extern storage class is not allowed. |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 16 | extern int (^bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 17 | void f2() { |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 18 | extern int (^bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | // A block cannot be the return value of a function. |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 22 | typedef int (^bl_t)(void); |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 23 | bl_t f3(bl_t bl); // expected-error{{declaring function return value of type 'bl_t' (aka 'int (^const)(void)') is not allowed}} |
| 24 | |
| 25 | struct bl_s { |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 26 | int (^bl)(void); // expected-error {{the 'int (^const)(void)' type cannot be used to declare a structure or union field}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | void f4() { |
| 30 | __block int a = 10; // expected-error {{the __block storage type is not permitted}} |
| 31 | } |
| 32 | |
| 33 | // A block with variadic argument is not allowed. |
Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 34 | int (^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}} |
Xiuli Pan | 89307aa | 2016-02-24 04:29:36 +0000 | [diff] [blame] | 35 | return 0; |
| 36 | }; |
Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 37 | typedef int (^bl1_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}} |
Xiuli Pan | 89307aa | 2016-02-24 04:29:36 +0000 | [diff] [blame] | 38 | |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 39 | // A block can't be used to declare an array |
Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 40 | typedef int (^bl2_t)(int); |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 41 | void f5(int i) { |
Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 42 | bl2_t bl1 = ^(int i) { |
| 43 | return 1; |
| 44 | }; |
| 45 | bl2_t bl2 = ^(int i) { |
| 46 | return 2; |
| 47 | }; |
| 48 | bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (^const)(int)') type is invalid in OpenCL}} |
Anastasia Stulova | 1f95cc0 | 2016-03-03 13:33:19 +0000 | [diff] [blame] | 49 | int tmp = i ? bl1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} |
| 50 | : bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} |
Xiuli Pan | 89307aa | 2016-02-24 04:29:36 +0000 | [diff] [blame] | 51 | } |
Anastasia Stulova | 4d85003 | 2016-07-11 13:46:02 +0000 | [diff] [blame] | 52 | // A block pointer type and all pointer operations are disallowed |
Anastasia Stulova | 7c30533 | 2016-10-28 12:59:39 +0000 | [diff] [blame] | 53 | void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type '__generic bl2_t' (aka 'int (^const __generic)(int)') is invalid in OpenCL}} |
| 54 | bl2_t bl = ^(int i) { |
| 55 | return 1; |
| 56 | }; |
| 57 | bl2_t *p; // expected-error {{pointer to type '__generic bl2_t' (aka 'int (^const __generic)(int)') is invalid in OpenCL}} |
| 58 | *bl; // expected-error {{invalid argument type 'bl2_t' (aka 'int (^const)(int)') to unary expression}} |
| 59 | &bl; // expected-error {{invalid argument type 'bl2_t' (aka 'int (^const)(int)') to unary expression}} |
Xiuli Pan | 89307aa | 2016-02-24 04:29:36 +0000 | [diff] [blame] | 60 | } |