summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaOpenCL/invalid-block.cl
diff options
context:
space:
mode:
authorAnastasia Stulova <anastasia.stulova@arm.com>2016-07-11 13:46:02 +0000
committerAnastasia Stulova <anastasia.stulova@arm.com>2016-07-11 13:46:02 +0000
commit4d8500396454334975ab8bb6766d6521c5140b13 (patch)
tree7a98430197c60e9b0a425afd57ab5bac30c5225d /clang/test/SemaOpenCL/invalid-block.cl
parentc73301bbe3dbcd6253b22a09e6acdb30eae31581 (diff)
downloadbcm5719-llvm-4d8500396454334975ab8bb6766d6521c5140b13.tar.gz
bcm5719-llvm-4d8500396454334975ab8bb6766d6521c5140b13.zip
[OpenCL] Improved diagnostics of OpenCL types.
- Changes diagnostics for Blocks to be implicitly const qualified OpenCL v2.0 s6.12.5. - Added and unified diagnostics of some OpenCL special types: blocks, images, samplers, pipes. These types are intended for use with the OpenCL builtin functions only and, therefore, most regular uses are not allowed including assignments, arithmetic operations, pointer dereferencing, etc. Review: http://reviews.llvm.org/D21989 llvm-svn: 275061
Diffstat (limited to 'clang/test/SemaOpenCL/invalid-block.cl')
-rw-r--r--clang/test/SemaOpenCL/invalid-block.cl32
1 files changed, 18 insertions, 14 deletions
diff --git a/clang/test/SemaOpenCL/invalid-block.cl b/clang/test/SemaOpenCL/invalid-block.cl
index 98a2e8bdfe5..6721d0ea234 100644
--- a/clang/test/SemaOpenCL/invalid-block.cl
+++ b/clang/test/SemaOpenCL/invalid-block.cl
@@ -1,26 +1,29 @@
// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
// OpenCL v2.0 s6.12.5
-
+void f0(int (^const bl)());
// All blocks declarations must be const qualified and initialized.
void f1() {
- int (^bl1)() = ^() {return 1;}; // expected-error{{invalid block variable declaration - must be const qualified}}
- int (^const bl2)(); // expected-error{{invalid block variable declaration - must be initialized}}
- int (^const bl3)() = ^(){return 1;};
+ int (^bl1)() = ^() {return 1;};
+ int (^const bl2)() = ^(){return 1;};
+ f0(bl1);
+ f0(bl2);
+ bl1 = bl2; // expected-error{{invalid operands to binary expression ('int (^const)()' and 'int (^const)()')}}
+ int (^const bl3)(); // expected-error{{invalid block variable declaration - must be initialized}}
}
// A block with extern storage class is not allowed.
-extern int (^const bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
+extern int (^bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
void f2() {
- extern int (^const bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
+ extern int (^bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
}
// A block cannot be the return value of a function.
-typedef int (^const bl_t)(void);
+typedef int (^bl_t)(void);
bl_t f3(bl_t bl); // expected-error{{declaring function return value of type 'bl_t' (aka 'int (^const)(void)') is not allowed}}
struct bl_s {
- int (^const bl)(void); // expected-error {{the 'int (^const)(void)' type cannot be used to declare a structure or union field}}
+ int (^bl)(void); // expected-error {{the 'int (^const)(void)' type cannot be used to declare a structure or union field}}
};
void f4() {
@@ -28,12 +31,12 @@ void f4() {
}
// A block with variadic argument is not allowed.
-int (^const bl)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+int (^bl)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
return 0;
};
// A block can't be used to declare an array
-typedef int (^const bl1_t)(int);
+typedef int (^bl1_t)(int);
void f5(int i) {
bl1_t bl1 = ^(int i) {return 1;};
bl1_t bl2 = ^(int i) {return 2;};
@@ -41,9 +44,10 @@ void f5(int i) {
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}}
}
-
-void f6(bl1_t * bl_ptr) {
+// A block pointer type and all pointer operations are disallowed
+void f6(bl1_t * bl_ptr) { // expected-error{{pointer to type '__generic bl1_t' (aka 'int (^const __generic)(int)') is invalid in OpenCL}}
bl1_t bl = ^(int i) {return 1;};
- bl1_t *p = &bl; // expected-error {{invalid argument type 'bl1_t' (aka 'int (^const)(int)') to unary expression}}
- bl = *bl_ptr; // expected-error {{dereferencing pointer of type '__generic bl1_t *' (aka 'int (^const __generic *)(int)') is not allowed in OpenCL}}
+ bl1_t *p; // expected-error {{pointer to type '__generic bl1_t' (aka 'int (^const __generic)(int)') is invalid in OpenCL}}
+ *bl; // expected-error {{invalid argument type 'bl1_t' (aka 'int (^const)(int)') to unary expression}}
+ &bl; // expected-error {{invalid argument type 'bl1_t' (aka 'int (^const)(int)') to unary expression}}
}
OpenPOWER on IntegriCloud