summaryrefslogtreecommitdiffstats
path: root/test/SemaOpenCL
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaOpenCL')
-rw-r--r--test/SemaOpenCL/endian-attr.cl9
-rw-r--r--test/SemaOpenCL/event_t.cl17
-rw-r--r--test/SemaOpenCL/event_t_overload.cl11
-rw-r--r--test/SemaOpenCL/half.cl40
-rw-r--r--test/SemaOpenCL/invalid-kernel-attrs.cl16
-rw-r--r--test/SemaOpenCL/invalid-kernel.cl7
-rw-r--r--test/SemaOpenCL/invalid-logical-ops-1.1.cl57
-rw-r--r--test/SemaOpenCL/invalid-logical-ops-1.2.cl57
-rw-r--r--test/SemaOpenCL/sampler_t.cl13
-rw-r--r--test/SemaOpenCL/sampler_t_overload.cl12
-rw-r--r--test/SemaOpenCL/shifts.cl17
-rw-r--r--test/SemaOpenCL/storageclass.cl2
-rw-r--r--test/SemaOpenCL/unsupported.cl9
13 files changed, 266 insertions, 1 deletions
diff --git a/test/SemaOpenCL/endian-attr.cl b/test/SemaOpenCL/endian-attr.cl
new file mode 100644
index 0000000..e851cdf
--- /dev/null
+++ b/test/SemaOpenCL/endian-attr.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify %s
+
+constant long a __attribute__((endian(host))) = 100;
+
+constant long b __attribute__((endian(device))) = 100;
+
+constant long c __attribute__((endian(none))) = 100; // expected-warning {{unknown endian 'none'}}
+
+void func() __attribute__((endian(host))); // expected-warning {{endian attribute only applies to variables}}
diff --git a/test/SemaOpenCL/event_t.cl b/test/SemaOpenCL/event_t.cl
new file mode 100644
index 0000000..57a0981
--- /dev/null
+++ b/test/SemaOpenCL/event_t.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+event_t glb_evt; // expected-error {{the event_t type cannot be used to declare a program scope variable}}
+
+struct evt_s {
+ event_t evt; // expected-error {{the event_t type cannot be used to declare a structure or union field}}
+} evt_str;
+
+void foo(event_t evt); // expected-note {{passing argument to parameter 'evt' here}}
+
+void kernel ker(event_t argevt) { // expected-error {{the event_t type cannot be used to declare a kernel function argument}}
+ event_t e;
+ constant event_t const_evt; // expected-error {{the event_t type can only be used with __private address space qualifier}}
+ foo(e);
+ foo(0);
+ foo(5); // expected-error {{passing 'int' to parameter of incompatible type 'event_t'}}
+}
diff --git a/test/SemaOpenCL/event_t_overload.cl b/test/SemaOpenCL/event_t_overload.cl
new file mode 100644
index 0000000..bc3ec44
--- /dev/null
+++ b/test/SemaOpenCL/event_t_overload.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+void __attribute__((overloadable)) foo(event_t, __local char *); // expected-note {{candidate function not viable: no known conversion from '__global int *' to '__local char *' for 2nd argument}}
+void __attribute__((overloadable)) foo(event_t, __local float *); // expected-note {{candidate function not viable: no known conversion from '__global int *' to '__local float *' for 2nd argument}}
+
+void kernel ker(__local char *src1, __local float *src2, __global int *src3) {
+ event_t evt;
+ foo(evt, src1);
+ foo(0, src2);
+ foo(evt, src3); // expected-error {{no matching function for call to 'foo'}}
+}
diff --git a/test/SemaOpenCL/half.cl b/test/SemaOpenCL/half.cl
new file mode 100644
index 0000000..0e6acb7
--- /dev/null
+++ b/test/SemaOpenCL/half.cl
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+half half_disabled(half *p, // expected-error{{declaring function return value of type 'half' is not allowed}}
+ half h) // expected-error{{declaring function argument of type 'half' is not allowed}}
+{
+ half a[2]; // expected-error{{declaring variable of type 'half [2]' is not allowed}}
+ half b; // expected-error{{declaring variable of type 'half' is not allowed}}
+ *p; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
+ p[1]; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
+
+ float c = 1.0f;
+ b = (half) c; // expected-error{{casting to type 'half' is not allowed}}
+
+ half *allowed = &p[1];
+ half *allowed2 = &*p;
+ half *allowed3 = p + 1;
+
+ return h;
+}
+
+// Exactly the same as above but with the cl_khr_fp16 extension enabled.
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+half half_enabled(half *p, half h)
+{
+ half a[2];
+ half b;
+ *p;
+ p[1];
+
+ float c = 1.0f;
+ b = (half) c;
+
+ half *allowed = &p[1];
+ half *allowed2 = &*p;
+ half *allowed3 = p + 1;
+
+ return h;
+}
diff --git a/test/SemaOpenCL/invalid-kernel-attrs.cl b/test/SemaOpenCL/invalid-kernel-attrs.cl
new file mode 100644
index 0000000..d242eaf
--- /dev/null
+++ b/test/SemaOpenCL/invalid-kernel-attrs.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify %s
+
+kernel __attribute__((vec_type_hint)) void kernel1() {} //expected-error{{attribute takes one argument}}
+
+kernel __attribute__((vec_type_hint(not_type))) void kernel2() {} //expected-error{{unknown type name 'not_type'}}
+
+kernel __attribute__((vec_type_hint(void))) void kernel3() {} //expected-error{{invalid attribute argument 'void' - expecting a vector or vectorizable scalar type}}
+
+kernel __attribute__((vec_type_hint(bool))) void kernel4() {} //expected-error{{invalid attribute argument 'bool' - expecting a vector or vectorizable scalar type}}
+
+kernel __attribute__((vec_type_hint(int))) __attribute__((vec_type_hint(float))) void kernel5() {} //expected-warning{{attribute 'vec_type_hint' is already applied with different parameters}}
+
+kernel __attribute__((work_group_size_hint(8,16,32,4))) void kernel6() {} //expected-error{{attribute requires exactly 3 arguments}}
+
+kernel __attribute__((work_group_size_hint(1,2,3))) __attribute__((work_group_size_hint(3,2,1))) void kernel7() {} //expected-warning{{attribute 'work_group_size_hint' is already applied with different parameters}}
+
diff --git a/test/SemaOpenCL/invalid-kernel.cl b/test/SemaOpenCL/invalid-kernel.cl
new file mode 100644
index 0000000..fb8ce58
--- /dev/null
+++ b/test/SemaOpenCL/invalid-kernel.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -verify %s
+
+kernel void no_ptrptr(global int **i) { } // expected-error{{kernel argument cannot be declared as a pointer to a pointer}}
+
+kernel int bar() { // expected-error {{kernel must have void return type}}
+ return 6;
+}
diff --git a/test/SemaOpenCL/invalid-logical-ops-1.1.cl b/test/SemaOpenCL/invalid-logical-ops-1.1.cl
new file mode 100644
index 0000000..2269dd3
--- /dev/null
+++ b/test/SemaOpenCL/invalid-logical-ops-1.1.cl
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 %s -verify -cl-std=CL1.1 -triple x86_64-unknown-linux-gnu
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+typedef __attribute__((ext_vector_type(4))) float float4;
+typedef __attribute__((ext_vector_type(4))) double double4;
+typedef __attribute__((ext_vector_type(4))) int int4;
+typedef __attribute__((ext_vector_type(4))) long long4;
+
+kernel void float_ops() {
+ int flaf = 0.0f && 0.0f; // expected-error {{invalid operands}}
+ int flof = 0.0f || 0.0f; // expected-error {{invalid operands}}
+ float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}}
+ float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}}
+ float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}}
+ int flai = 0.0f && 0; // expected-error {{invalid operands}}
+ int floi = 0.0f || 0; // expected-error {{invalid operands}}
+ float ibaf = 0 & 0.0f; // expected-error {{invalid operands}}
+ float ibof = 0 | 0.0f; // expected-error {{invalid operands}}
+ float bnf = ~0.0f; // expected-error {{invalid argument type}}
+ float lnf = !0.0f; // expected-error {{invalid argument type}}
+}
+
+kernel void vec_float_ops() {
+ float4 f4 = (float4)(0, 0, 0, 0);
+ int4 f4laf = f4 && 0.0f; // expected-error {{invalid operands}}
+ int4 f4lof = f4 || 0.0f; // expected-error {{invalid operands}}
+ float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}}
+ float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}}
+ float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}}
+ float bnf4 = ~f4; // expected-error {{invalid argument type}}
+ int4 lnf4 = !f4; // expected-error {{invalid argument type}}
+}
+
+kernel void double_ops() {
+ int flaf = 0.0 && 0.0; // expected-error {{invalid operands}}
+ int flof = 0.0 || 0.0; // expected-error {{invalid operands}}
+ double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}}
+ double fbof = 0.0 | 0.0; // expected-error {{invalid operands}}
+ double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}}
+ int flai = 0.0 && 0; // expected-error {{invalid operands}}
+ int floi = 0.0 || 0; // expected-error {{invalid operands}}
+ double ibaf = 0 & 0.0; // expected-error {{invalid operands}}
+ double ibof = 0 | 0.0; // expected-error {{invalid operands}}
+ double bnf = ~0.0; // expected-error {{invalid argument type}}
+ double lnf = !0.0; // expected-error {{invalid argument type}}
+}
+
+kernel void vec_double_ops() {
+ double4 f4 = (double4)(0, 0, 0, 0);
+ long4 f4laf = f4 && 0.0; // expected-error {{invalid operands}}
+ long4 f4lof = f4 || 0.0; // expected-error {{invalid operands}}
+ double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}}
+ double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}}
+ double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}}
+ double bnf4 = ~f4; // expected-error {{invalid argument type}}
+ long4 lnf4 = !f4; // expected-error {{invalid argument type}}
+}
diff --git a/test/SemaOpenCL/invalid-logical-ops-1.2.cl b/test/SemaOpenCL/invalid-logical-ops-1.2.cl
new file mode 100644
index 0000000..7ba1adb
--- /dev/null
+++ b/test/SemaOpenCL/invalid-logical-ops-1.2.cl
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 %s -verify -cl-std=CL1.2 -triple x86_64-unknown-linux-gnu
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+typedef __attribute__((ext_vector_type(4))) float float4;
+typedef __attribute__((ext_vector_type(4))) double double4;
+typedef __attribute__((ext_vector_type(4))) int int4;
+typedef __attribute__((ext_vector_type(4))) long long4;
+
+kernel void float_ops() {
+ int flaf = 0.0f && 0.0f;
+ int flof = 0.0f || 0.0f;
+ float fbaf = 0.0f & 0.0f; // expected-error {{invalid operands}}
+ float fbof = 0.0f | 0.0f; // expected-error {{invalid operands}}
+ float fbxf = 0.0f ^ 0.0f; // expected-error {{invalid operands}}
+ int flai = 0.0f && 0;
+ int floi = 0.0f || 0;
+ float ibaf = 0 & 0.0f; // expected-error {{invalid operands}}
+ float ibof = 0 | 0.0f; // expected-error {{invalid operands}}
+ float bnf = ~0.0f;// expected-error {{invalid argument type}}
+ float lnf = !0.0f;
+}
+
+kernel void vec_float_ops() {
+ float4 f4 = (float4)(0, 0, 0, 0);
+ int4 f4laf = f4 && 0.0f;
+ int4 f4lof = f4 || 0.0f;
+ float4 f4baf = f4 & 0.0f; // expected-error {{invalid operands}}
+ float4 f4bof = f4 | 0.0f; // expected-error {{invalid operands}}
+ float4 f4bxf = f4 ^ 0.0f; // expected-error {{invalid operands}}
+ float bnf4 = ~f4; // expected-error {{invalid argument type}}
+ int4 lnf4 = !f4;
+}
+
+kernel void double_ops() {
+ int flaf = 0.0 && 0.0;
+ int flof = 0.0 || 0.0;
+ double fbaf = 0.0 & 0.0; // expected-error {{invalid operands}}
+ double fbof = 0.0 | 0.0; // expected-error {{invalid operands}}
+ double fbxf = 0.0 ^ 0.0; // expected-error {{invalid operands}}
+ int flai = 0.0 && 0;
+ int floi = 0.0 || 0;
+ double ibaf = 0 & 0.0; // expected-error {{invalid operands}}
+ double ibof = 0 | 0.0; // expected-error {{invalid operands}}
+ double bnf = ~0.0; // expected-error {{invalid argument type}}
+ double lnf = !0.0;
+}
+
+kernel void vec_double_ops() {
+ double4 f4 = (double4)(0, 0, 0, 0);
+ long4 f4laf = f4 && 0.0;
+ long4 f4lof = f4 || 0.0;
+ double4 f4baf = f4 & 0.0; // expected-error {{invalid operands}}
+ double4 f4bof = f4 | 0.0; // expected-error {{invalid operands}}
+ double4 f4bxf = f4 ^ 0.0; // expected-error {{invalid operands}}
+ double bnf4 = ~f4; // expected-error {{invalid argument type}}
+ long4 lnf4 = !f4;
+}
diff --git a/test/SemaOpenCL/sampler_t.cl b/test/SemaOpenCL/sampler_t.cl
new file mode 100644
index 0000000..96f6dbf
--- /dev/null
+++ b/test/SemaOpenCL/sampler_t.cl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+constant sampler_t glb_smp = 5;
+
+void foo(sampler_t);
+
+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}}
+ const sampler_t const_smp = 7;
+ foo(glb_smp);
+ foo(const_smp);
+ foo(5); // expected-error {{sampler_t variable required - got 'int'}}
+}
diff --git a/test/SemaOpenCL/sampler_t_overload.cl b/test/SemaOpenCL/sampler_t_overload.cl
new file mode 100644
index 0000000..83a854f
--- /dev/null
+++ b/test/SemaOpenCL/sampler_t_overload.cl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s
+
+void __attribute__((overloadable)) foo(sampler_t, read_only image1d_t);
+void __attribute__((overloadable)) foo(sampler_t, read_only image2d_t);
+
+constant sampler_t glb_smp = 5;
+
+void kernel ker(read_only image1d_t src1, read_only image2d_t src2) {
+ const sampler_t smp = 10;
+ foo(glb_smp, src1);
+ foo(smp, src2);
+}
diff --git a/test/SemaOpenCL/shifts.cl b/test/SemaOpenCL/shifts.cl
new file mode 100644
index 0000000..5b0c6fb
--- /dev/null
+++ b/test/SemaOpenCL/shifts.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x cl -O0 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// OpenCL essentially reduces all shift amounts to the last word-size bits before evaluating.
+// Test this both for variables and constants evaluated in the front-end.
+
+// CHECK: @gtest1 = constant i64 2147483648
+__constant const unsigned long gtest1 = 1UL << 31;
+
+// CHECK: @negativeShift32
+int negativeShift32(int a,int b) {
+ // CHECK: %array0 = alloca [256 x i8]
+ char array0[((int)1)<<40];
+ // CHECK: %array1 = alloca [256 x i8]
+ char array1[((int)1)<<(-24)];
+
+ // CHECK: ret i32 65536
+ return ((int)1)<<(-16);
+}
diff --git a/test/SemaOpenCL/storageclass.cl b/test/SemaOpenCL/storageclass.cl
index c78e7cd..fdfe134 100644
--- a/test/SemaOpenCL/storageclass.cl
+++ b/test/SemaOpenCL/storageclass.cl
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
-static int A;
+static constant int A = 0;
// static is not allowed at local scope.
void kernel foo() {
diff --git a/test/SemaOpenCL/unsupported.cl b/test/SemaOpenCL/unsupported.cl
new file mode 100644
index 0000000..bb9da4b
--- /dev/null
+++ b/test/SemaOpenCL/unsupported.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify %s
+
+struct {
+ int a : 1; // expected-error {{bitfields are not supported in OpenCL}}
+};
+
+void no_vla(int n) {
+ int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}}
+}
OpenPOWER on IntegriCloud