2016-02-24 12:29:36 +08:00
|
|
|
// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
|
|
|
|
|
2016-03-03 21:33:19 +08:00
|
|
|
// OpenCL v2.0 s6.12.5
|
2016-07-11 21:46:02 +08:00
|
|
|
void f0(int (^const bl)());
|
2016-03-03 21:33:19 +08:00
|
|
|
// All blocks declarations must be const qualified and initialized.
|
|
|
|
void f1() {
|
2017-01-27 23:11:34 +08:00
|
|
|
int (^bl1)(void) = ^() {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
int (^const bl2)(void) = ^() {
|
|
|
|
return 1;
|
|
|
|
};
|
2016-07-11 21:46:02 +08:00
|
|
|
f0(bl1);
|
|
|
|
f0(bl2);
|
2019-12-27 21:38:48 +08:00
|
|
|
bl1 = bl2; // expected-error{{invalid operands to binary expression ('int (__generic ^const __private)(void)' and 'int (__generic ^const __private)(void)')}}
|
2016-07-11 21:46:02 +08:00
|
|
|
int (^const bl3)(); // expected-error{{invalid block variable declaration - must be initialized}}
|
2016-03-03 21:33:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// A block with extern storage class is not allowed.
|
2017-01-27 23:11:34 +08:00
|
|
|
extern int (^bl)(void) = ^() { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
|
|
|
|
return 1;
|
|
|
|
};
|
2016-03-03 21:33:19 +08:00
|
|
|
void f2() {
|
2017-01-27 23:11:34 +08:00
|
|
|
extern int (^bl)(void) = ^() { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
|
|
|
|
return 1;
|
|
|
|
};
|
2016-03-03 21:33:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// A block cannot be the return value of a function.
|
2016-07-11 21:46:02 +08:00
|
|
|
typedef int (^bl_t)(void);
|
2017-01-27 23:11:34 +08:00
|
|
|
bl_t f3(bl_t bl); // expected-error{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}}
|
2016-03-03 21:33:19 +08:00
|
|
|
|
|
|
|
struct bl_s {
|
2017-01-27 23:11:34 +08:00
|
|
|
int (^bl)(void); // expected-error {{the 'int (__generic ^const)(void)' type cannot be used to declare a structure or union field}}
|
2016-03-03 21:33:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void f4() {
|
|
|
|
__block int a = 10; // expected-error {{the __block storage type is not permitted}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A block with variadic argument is not allowed.
|
2016-10-28 20:59:39 +08:00
|
|
|
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}}
|
2016-02-24 12:29:36 +08:00
|
|
|
return 0;
|
|
|
|
};
|
2016-10-28 20:59:39 +08:00
|
|
|
typedef int (^bl1_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
|
2016-02-24 12:29:36 +08:00
|
|
|
|
2016-03-03 21:33:19 +08:00
|
|
|
// A block can't be used to declare an array
|
2016-10-28 20:59:39 +08:00
|
|
|
typedef int (^bl2_t)(int);
|
2016-03-03 21:33:19 +08:00
|
|
|
void f5(int i) {
|
2016-10-28 20:59:39 +08:00
|
|
|
bl2_t bl1 = ^(int i) {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
bl2_t bl2 = ^(int i) {
|
|
|
|
return 2;
|
|
|
|
};
|
2019-12-27 21:38:48 +08:00
|
|
|
bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL}}
|
2016-03-03 21:33:19 +08:00
|
|
|
int tmp = i ? bl1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
|
|
|
|
: bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
|
2016-02-24 12:29:36 +08:00
|
|
|
}
|
2016-07-11 21:46:02 +08:00
|
|
|
// A block pointer type and all pointer operations are disallowed
|
2019-12-27 21:38:48 +08:00
|
|
|
void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}}
|
2016-10-28 20:59:39 +08:00
|
|
|
bl2_t bl = ^(int i) {
|
|
|
|
return 1;
|
|
|
|
};
|
2019-12-27 21:38:48 +08:00
|
|
|
bl2_t *p; // expected-error {{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}}
|
|
|
|
*bl; // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}}
|
|
|
|
&bl; // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}}
|
2016-02-24 12:29:36 +08:00
|
|
|
}
|
2017-02-16 19:13:30 +08:00
|
|
|
// 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;
|
|
|
|
}
|
2017-09-08 01:00:33 +08:00
|
|
|
|
|
|
|
// Taking address of a capture is not allowed
|
|
|
|
int g;
|
|
|
|
kernel void f8(int a1) {
|
|
|
|
int a2;
|
|
|
|
void (^bl)(void) = ^(void) {
|
|
|
|
&g; //expected-warning{{expression result unused}}
|
|
|
|
&a1; //expected-error{{taking address of a capture is not allowed}}
|
|
|
|
&a2; //expected-error{{taking address of a capture is not allowed}}
|
|
|
|
};
|
|
|
|
}
|