summaryrefslogtreecommitdiffstats
path: root/test/SemaOpenCL
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaOpenCL')
-rw-r--r--test/SemaOpenCL/cond.cl132
-rw-r--r--test/SemaOpenCL/extension-fp64-cl1.1.cl19
-rw-r--r--test/SemaOpenCL/optional-core-fp64-cl1.2.cl20
-rw-r--r--test/SemaOpenCL/optional-core-fp64-cl2.0.cl20
-rw-r--r--test/SemaOpenCL/shifts.cl76
5 files changed, 248 insertions, 19 deletions
diff --git a/test/SemaOpenCL/cond.cl b/test/SemaOpenCL/cond.cl
index 802ad9b..a1e32df 100644
--- a/test/SemaOpenCL/cond.cl
+++ b/test/SemaOpenCL/cond.cl
@@ -1,6 +1,132 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
-// expected-no-diagnostics
-typedef __attribute__((ext_vector_type(4))) float float4;
+typedef unsigned char uchar;
+typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
-float4 foo(float4 a, float4 b, float4 c, float4 d) { return a < b ? c : d; }
+typedef char char2 __attribute__((ext_vector_type(2)));
+typedef char char3 __attribute__((ext_vector_type(3)));
+
+typedef int int2 __attribute__((ext_vector_type(2)));
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+
+// ** Positive tests **
+
+// all scalars, but widths do not match.
+int ptest01(char C, char X, int Y)
+{
+ return C ? X : Y;
+}
+
+char ptest02(int C, char X, char Y)
+{
+ return C ? X : Y;
+}
+
+// scalar condition and mixed-width vectors and scalars
+int2 ptest03(char C, char X, int2 Y)
+{
+ return C ? X : Y;
+}
+
+// uniform vectors
+char2 ptest04(char2 X, char2 Y, char2 C)
+{
+ return C ? X : Y;
+}
+
+// vector condition and mixed scalar operands
+int2 ptest05(int2 C, int X, char Y)
+{
+ return C ? X : Y;
+}
+
+// vector condition and matching scalar operands
+float2 ptest06(int2 C, float X, float Y)
+{
+ return C ? X : Y;
+}
+
+// vector condition and mixed scalar operands
+float2 ptest07(int2 C, int X, float Y)
+{
+ return C ? X : Y;
+}
+
+// vector condition and mixed scalar and vector operands
+float2 ptest08(int2 C, int X, float2 Y)
+{
+ return C ? X : Y;
+}
+
+// Actual comparison expression
+float2 ptest09(float2 A, float2 B, float2 C, float2 D)
+{
+ return A < B ? C : D;
+}
+
+// ** Negative tests **
+
+int2 ntest01(char2 C, int X, int Y)
+{
+ return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type (vector of 2 'int' values) do not have elements of the same size}}
+}
+
+int2 ntest02(char2 C, int2 X, int2 Y)
+{
+ return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type 'int2' (vector of 2 'int' values) do not have elements of the same size}}
+}
+
+uchar2 ntest03(int2 C, uchar X, uchar Y)
+{
+ return C ? X : Y; // expected-error {{vector condition type 'int2' (vector of 2 'int' values) and result type (vector of 2 'unsigned char' values) do not have elements of the same size}}
+}
+
+float2 ntest04(int2 C, int2 X, float2 Y)
+{
+ return C ? X : Y; // expected-error {{can't convert between vector values of different size ('int2' (vector of 2 'int' values) and 'float2' (vector of 2 'float' values))}}
+}
+
+float2 ntest05(int2 C, int2 X, float Y)
+{
+ return C ? X : Y; // expected-error {{can't convert between vector values of different size ('int2' (vector of 2 'int' values) and 'float')}}
+}
+
+char2 ntest06(int2 C, char2 X, char2 Y)
+{
+ return C ? X : Y; // expected-error {{vector condition type 'int2' (vector of 2 'int' values) and result type 'char2' (vector of 2 'char' values) do not have elements of the same size}}
+}
+
+float ntest07(float C, float X, float Y)
+{
+ return C ? X : Y; // expected-error {{used type 'float' where floating point type is not allowed}}
+}
+
+float2 ntest08(float2 C, float2 X, float2 Y)
+{
+ return C ? X : Y; // expected-error {{used type 'float2' (vector of 2 'float' values) where floating point type is not allowed}}
+}
+
+// Trying to create a int2 vector out of pointers.
+int2 ntest09(int2 C, global int *X, global int *Y)
+{
+ return C ? X : Y; // expected-error {{used type '__global int *' where integer or floating point type is required}}
+}
+
+char3 ntest10(char C, char3 X, char2 Y)
+{
+ return C ? X : Y; // expected-error {{can't convert between vector values of different size ('char3' (vector of 3 'char' values) and 'char2' (vector of 2 'char' values))}}
+}
+
+char3 ntest11(char2 C, char3 X, char Y)
+{
+ return C ? X : Y; // expected-error {{vector condition type 'char2' (vector of 2 'char' values) and result type 'char3' (vector of 3 'char' values) do not have the same number of elements}}
+}
+
+int foo1(int);
+int foo2(int);
+
+unsigned int ntest12(int2 C)
+{
+ return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}}
+}
diff --git a/test/SemaOpenCL/extension-fp64-cl1.1.cl b/test/SemaOpenCL/extension-fp64-cl1.1.cl
new file mode 100644
index 0000000..7e852ae
--- /dev/null
+++ b/test/SemaOpenCL/extension-fp64-cl1.1.cl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.1
+
+void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+ double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+ (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}}
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}}
+}
diff --git a/test/SemaOpenCL/optional-core-fp64-cl1.2.cl b/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
new file mode 100644
index 0000000..e0f7f1d
--- /dev/null
+++ b/test/SemaOpenCL/optional-core-fp64-cl1.2.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+// expected-no-diagnostics
+
+void f1(double da) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d;
+}
diff --git a/test/SemaOpenCL/optional-core-fp64-cl2.0.cl b/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
new file mode 100644
index 0000000..832529d
--- /dev/null
+++ b/test/SemaOpenCL/optional-core-fp64-cl2.0.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// expected-no-diagnostics
+
+void f1(double da) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+void f2(void) {
+ double d;
+ (void) 1.0;
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : disable
+
+void f3(void) {
+ double d;
+}
diff --git a/test/SemaOpenCL/shifts.cl b/test/SemaOpenCL/shifts.cl
index 5b0c6fb..26f59a5 100644
--- a/test/SemaOpenCL/shifts.cl
+++ b/test/SemaOpenCL/shifts.cl
@@ -1,17 +1,61 @@
-// 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);
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef __attribute__((ext_vector_type(2))) char char2;
+typedef __attribute__((ext_vector_type(3))) char char3;
+
+typedef __attribute__((ext_vector_type(2))) int int2;
+
+typedef __attribute__((ext_vector_type(2))) float float2;
+
+// ** Positive tests **
+
+char2 ptest01(char2 c, char s) {
+ return c << s;
+}
+
+char2 ptest02(char2 c, char2 s) {
+ return c << s;
+}
+
+char2 ptest03(char2 c, int s) {
+ return c << s;
+}
+
+char2 ptest04(char2 c, int2 s) {
+ return c << s;
+}
+
+int2 ptest05(int2 c, char2 s) {
+ return c << s;
+}
+
+char2 ptest06(char2 c) {
+ return c << 1;
+}
+
+void ptest07() {
+ char3 v = {1,1,1};
+ char3 w = {1,2,3};
+
+ v <<= w;
+}
+
+// ** Negative tests **
+
+char2 ntest01(char c, char2 s) {
+ return c << s; // expected-error {{requested shift is a vector of type 'char2' (vector of 2 'char' values) but the first operand is not a vector ('char')}}
+}
+
+char3 ntest02(char3 c, char2 s) {
+ return c << s; // expected-error {{vector operands do not have the same number of elements ('char3' (vector of 3 'char' values) and 'char2' (vector of 2 'char' values))}}
+}
+
+float2 ntest03(float2 c, char s) {
+ return c << s; // expected-error {{used type 'float2' (vector of 2 'float' values) where integer is required}}
+}
+
+int2 ntest04(int2 c, float s) {
+ return c << s; // expected-error {{used type 'float' where integer is required}}
}
OpenPOWER on IntegriCloud