Skip to content

Commit

Permalink
[OpenCL] Improve OpenCL operator tests
Browse files Browse the repository at this point in the history
Extend testing of increment/decrement operators and make sure these
operators are tested in only one dedicated test file.

Rename logical-ops.cl to operators.cl, as it was already containing
more than just logical operators.

Add testing for the remainder operator on floating point types.
  • Loading branch information
svenvh committed Jan 13, 2021
1 parent ab57780 commit 7c77b53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion clang/test/SemaOpenCL/invalid-vector-literals.cl
Expand Up @@ -8,7 +8,6 @@ void vector_literals_invalid()
{
int4 a = (int4)(1,2,3); // expected-error{{too few elements}}
int4 b = (int4)(1,2,3,4,5); // expected-error{{excess elements in vector}}
((float4)(1.0f))++; // expected-error{{cannot increment value of type 'float4'}}
int8 d = (int8)(a,(float4)(1)); // expected-error{{initializing 'int' with an expression of incompatible type 'float4'}}
((int4)(0)).x = 8; // expected-error{{expression is not assignable}}
}
Expand Up @@ -36,6 +36,8 @@ kernel void float_ops() {
#if __OPENCL_C_VERSION__ < 120
// expected-error@-2{{invalid argument type}}
#endif
float fcst = 5.5f;
float fremainder = fcst % 2.0f; // expected-error {{invalid operands to binary expression}}
}

kernel void vec_float_ops() {
Expand All @@ -56,6 +58,8 @@ kernel void vec_float_ops() {
#if __OPENCL_C_VERSION__ < 120
// expected-error@-2{{invalid argument type}}
#endif
float4 f4cst = (float4)(5.5f, 5.5f, 5.5f, 5.5f);
float4 f4remainder = f4cst % (float4)(2.0f, 2.0f, 2.0f, 2.0f); // expected-error {{invalid operands to binary expression}}
}

kernel void double_ops() {
Expand Down Expand Up @@ -85,6 +89,8 @@ kernel void double_ops() {
#if __OPENCL_C_VERSION__ < 120
// expected-error@-2{{invalid argument type}}
#endif
double dcst = 5.5;
double dremainder = dcst % 2.0; // expected-error {{invalid operands to binary expression}}
}

kernel void vec_double_ops() {
Expand Down
9 changes: 8 additions & 1 deletion clang/test/SemaOpenCL/vector_inc_dec_ops.cl
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
// expected-no-diagnostics

typedef __attribute__((ext_vector_type(2))) char char2;
typedef __attribute__((ext_vector_type(4))) unsigned int uint4;
typedef __attribute__((ext_vector_type(8))) long long8;
typedef __attribute__((ext_vector_type(4))) float float4;

void vectorIncrementDecrementOps()
{
Expand All @@ -17,3 +17,10 @@ void vectorIncrementDecrementOps()
++B;
C++;
}

void invalidIncrementDecrementOps() {
((float4)(1.0f))++; // expected-error{{cannot increment value of type 'float4'}}
float4 i;
++i; // expected-error{{cannot increment value of type '__private float4'}}
i--; // expected-error{{cannot decrement value of type '__private float4'}}
}

0 comments on commit 7c77b53

Please sign in to comment.