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