1 // RUN
: %clang_cc1 -verify -fblocks -cl-std
=CL2.0 %s
2 // RUN
: %clang_cc1 -verify -fblocks -cl-std
=CL3.0 -cl-ext
=-all
,+__opencl_c_device_enqueue
,+__opencl_c_generic_address_space
,+__opencl_c_program_scope_global_variables %s
4 void f0
(int (^const bl
)(void)); // 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.
7 int
(^bl1
)(void) = ^
(void) {
10 int
(^const bl2
)(void) = ^
(void) {
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
)(void); // expected-error{{invalid block variable declaration - must be initialized}}
19 // A block with extern storage class is not allowed.
20 extern int
(^bl
)(void) = ^
(void) { // expected-error
{{invalid block variable declaration - using
'extern
' storage class is disallowed
}}
24 extern int
(^bl
)(void) = ^
(void) { // expected-error
{{invalid block variable declaration - using
'extern
' storage class is disallowed
}}
29 // A block cannot be the return value or parameter of a function.
30 typedef int
(^bl_t
)(void);
31 bl_t f3a
(int); // expected-error{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}}
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
}}
36 // Block with a block argument.
37 int
(^const bl2
)(bl_t block_arg
) = ^
(void) { // 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{{use of undeclared identifier 'block_arg'}}
43 int
(^bl
)(void); // expected-error {{the 'int (__generic ^const)(void)' type cannot be used to declare a structure or union field}}
47 __block int a
= 10; // expected-error {{the __block storage type is not permitted}}
50 // A block with variadic argument is not allowed.
51 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
}}
54 typedef int
(^bl1_t
)(int, ...
); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}
56 // A block can
't be used to declare an array
57 typedef int
(^bl2_t
)(int);
59 bl2_t bl1
= ^
(int i
) {
62 bl2_t bl2
= ^
(int i
) {
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}}
69 // A block pointer type and all pointer operations are disallowed
70 void f6
(bl2_t *bl_ptr
) { // expected-error
{{pointer to type
'bl2_t
' (aka 'int
(__generic ^const
)(__private int
)') is invalid in OpenCL
}}
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}}
78 // A block can
't reference another block
79 kernel void f7
(void) {
80 bl2_t bl1
= ^
(int i
) {
83 void
(^bl2
)(void) = ^
{
84 int i
= bl1
(1); // expected-error {{cannot refer to a block inside block}}
86 void
(^bl3
)(void) = ^
{
88 void
(^bl4
)(void) = ^
{
89 bl3
(); // expected-error {{cannot refer to a block inside block}}
94 // Taking address of a capture is not allowed
96 kernel void f8
(int a1
) {
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}}