brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 985b044 Raw
107 lines · plain
1// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s2// 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  %s3// OpenCL v2.0 s6.12.54void 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.6void f1(void) {7  int (^bl1)(void) = ^(void) {8    return 1;9  };10  int (^const bl2)(void) = ^(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)(void); // expected-error{{invalid block variable declaration - must be initialized}} \17                             expected-warning {{default initialization of an object of type 'int (__generic ^const __private)(void)' leaves the object uninitialized}}18}19 20// A block with extern storage class is not allowed.21extern int (^bl)(void) = ^(void) { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}22  return 1;23};24void f2() {25  extern int (^bl)(void) = ^(void) { // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}26    return 1;27  };28}29 30// A block cannot be the return value or parameter of a function.31typedef int (^bl_t)(void);32bl_t f3a(int);     // expected-error{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}}33bl_t f3b(bl_t bl);34// expected-error@-1{{declaring function return value of type 'bl_t' (aka 'int (__generic ^const)(void)') is not allowed}}35// expected-error@-2{{declaring function parameter of type '__private bl_t' (aka 'int (__generic ^const __private)(void)') is not allowed}}36void f3c(void) {37  // Block with a block argument.38  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}}39    return block_arg(); // expected-error{{use of undeclared identifier 'block_arg'}}40  };41}42 43struct bl_s {44  int (^bl)(void); // expected-error {{the 'int (__generic ^const)(void)' type cannot be used to declare a structure or union field}}45};46 47void f4() {48  __block int a = 10; // expected-error {{the __block storage type is not permitted}}49}50 51// A block with variadic argument is not allowed.52int (^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}}53  return 0;54};55typedef int (^bl1_t)(int, ...); // expected-error {{invalid prototype, variadic arguments are not allowed in OpenCL}}56 57// A block can't be used to declare an array58typedef int (^bl2_t)(int);59void f5(int i) {60  bl2_t bl1 = ^(int i) {61    return 1;62  };63  bl2_t bl2 = ^(int i) {64    return 2;65  };66  bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL}}67  int tmp = i ? bl1(i)      // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}68              : bl2(i);     // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}69  bl2_t bref = i ? bl1      // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}70                 : bl2;     // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}71}72// A block pointer type and all pointer operations are disallowed73void 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 bl = ^(int i) {75    return 1;76  };77  bl2_t *p; // expected-error {{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}}78  *bl;      // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}}79  &bl;      // expected-error {{invalid argument type '__private bl2_t' (aka 'int (__generic ^const __private)(__private int)') to unary expression}}80}81// A block can't reference another block82kernel void f7(void) {83  bl2_t bl1 = ^(int i) {84    return 1;85  };86  void (^bl2)(void) = ^{87    int i = bl1(1); // expected-error {{cannot refer to a block inside block}}88  };89  void (^bl3)(void) = ^{90  };91  void (^bl4)(void) = ^{92    bl3(); // expected-error {{cannot refer to a block inside block}}93  };94  return;95}96 97// Taking address of a capture is not allowed98int g;99kernel void f8(int a1) {100  int a2;101  void (^bl)(void) = ^(void) {102    &g; //expected-warning{{expression result unused}}103    &a1; //expected-error{{taking address of a capture is not allowed}}104    &a2; //expected-error{{taking address of a capture is not allowed}}105  };106}107