summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/blocks-opencl.cl7
-rw-r--r--clang/test/SemaOpenCL/event_t.cl2
-rw-r--r--clang/test/SemaOpenCL/invalid-block.cl54
-rw-r--r--clang/test/SemaOpenCL/invalid-kernel-parameters.cl5
-rw-r--r--clang/test/SemaOpenCL/sampler_t.cl6
5 files changed, 56 insertions, 18 deletions
diff --git a/clang/test/CodeGen/blocks-opencl.cl b/clang/test/CodeGen/blocks-opencl.cl
index d3562988b73..61c479b7b98 100644
--- a/clang/test/CodeGen/blocks-opencl.cl
+++ b/clang/test/CodeGen/blocks-opencl.cl
@@ -2,15 +2,16 @@
// This used to crash due to trying to generate a bitcase from a cstring
// in the constant address space to i8* in AS0.
-void dummy(float (^op)(float))
-{
+void dummy(float (^const op)(float)) {
}
// CHECK: i8 addrspace(3)* getelementptr inbounds ([9 x i8], [9 x i8] addrspace(3)* @.str, i32 0, i32 0)
kernel void test_block()
{
- float (^X)(float) = ^(float x) { return x + 42.0f; };
+ float (^const X)(float) = ^(float x) {
+ return x + 42.0f;
+ };
dummy(X);
}
diff --git a/clang/test/SemaOpenCL/event_t.cl b/clang/test/SemaOpenCL/event_t.cl
index e09883948cc..3c4b45b9232 100644
--- a/clang/test/SemaOpenCL/event_t.cl
+++ b/clang/test/SemaOpenCL/event_t.cl
@@ -3,7 +3,7 @@
event_t glb_evt; // expected-error {{the event_t type cannot be used to declare a program scope variable}}
constant struct evt_s {
- event_t evt; // expected-error {{the event_t type cannot be used to declare a structure or union field}}
+ event_t evt; // expected-error {{the 'event_t' type cannot be used to declare a structure or union field}}
} evt_str = {0};
void foo(event_t evt); // expected-note {{passing argument to parameter 'evt' here}}
diff --git a/clang/test/SemaOpenCL/invalid-block.cl b/clang/test/SemaOpenCL/invalid-block.cl
index c3989a28c83..c8c88219255 100644
--- a/clang/test/SemaOpenCL/invalid-block.cl
+++ b/clang/test/SemaOpenCL/invalid-block.cl
@@ -1,20 +1,50 @@
// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s
-int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+// OpenCL v2.0 s6.12.5
+
+// All blocks declarations must be const qualified and initialized.
+void f1() {
+ int (^bl1)() = ^() {}; // 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)() = ^const(){
+ };
+}
+
+// A block with extern storage class is not allowed.
+extern int (^const bl)() = ^const(){}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
+void f2() {
+ extern int (^const bl)() = ^const(){}; // 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);
+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}}
+};
+
+void f4() {
+ __block int a = 10; // expected-error {{the __block storage type is not permitted}}
+}
+
+// A block with variadic argument is not allowed.
+int (^const bl)(int, ...) = ^const int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
return 0;
};
-typedef int (^BlkInt)(int);
-void f1(int i) {
- BlkInt B1 = ^int(int I) {return 1;};
- BlkInt B2 = ^int(int I) {return 2;};
- BlkInt Arr[] = {B1, B2}; // expected-error {{array of 'BlkInt' (aka 'int (^)(int)') type is invalid in OpenCL}}
- int tmp = i ? B1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
- : B2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
+// A block can't be used to declare an array
+typedef int (^const bl1_t)(int);
+void f5(int i) {
+ bl1_t bl1 = ^const(int i) {return 1;};
+ bl1_t bl2 = ^const(int i) {return 2;};
+ bl1_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl1_t' (aka 'int (^const)(int)') type is invalid in OpenCL}}
+ 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 f2(BlkInt *BlockPtr) {
- BlkInt B = ^int(int I) {return 1;};
- BlkInt *P = &B; // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}}
- B = *BlockPtr; // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed in OpenCL}}
+void f6(bl1_t * bl_ptr) {
+ bl1_t bl = ^const(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}}
}
diff --git a/clang/test/SemaOpenCL/invalid-kernel-parameters.cl b/clang/test/SemaOpenCL/invalid-kernel-parameters.cl
index de32eae8821..95a56e2972b 100644
--- a/clang/test/SemaOpenCL/invalid-kernel-parameters.cl
+++ b/clang/test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -24,7 +24,10 @@ kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsB
typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}}
{
- image2d_t imageField; // expected-note{{field of illegal type 'image2d_t' declared here}}
+ // TODO: Clean up needed - we don't really need to check for image, event, etc
+ // as a note here any longer.
+ // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r).
+ image2d_t imageField; // expected-note{{field of illegal type 'image2d_t' declared here}} expected-error{{the 'image2d_t' type cannot be used to declare a structure or union field}}
} FooImage2D;
kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
diff --git a/clang/test/SemaOpenCL/sampler_t.cl b/clang/test/SemaOpenCL/sampler_t.cl
index 82fb347bc00..711cdeae920 100644
--- a/clang/test/SemaOpenCL/sampler_t.cl
+++ b/clang/test/SemaOpenCL/sampler_t.cl
@@ -2,7 +2,11 @@
constant sampler_t glb_smp = 5;
-void foo(sampler_t);
+void foo(sampler_t);
+
+constant struct sampler_s {
+ sampler_t smp; // expected-error {{the 'sampler_t' type cannot be used to declare a structure or union field}}
+} sampler_str = {0};
void kernel ker(sampler_t argsmp) {
local sampler_t smp; // expected-error {{sampler type cannot be used with the __local and __global address space qualifiers}}
OpenPOWER on IntegriCloud