diff options
| author | Sameer Sahasrabuddhe <sameer.sahasrabuddhe@amd.com> | 2015-02-06 05:44:55 +0000 |
|---|---|---|
| committer | Sameer Sahasrabuddhe <sameer.sahasrabuddhe@amd.com> | 2015-02-06 05:44:55 +0000 |
| commit | c65605d008dd409afd768328fe0250bb33ff0e3b (patch) | |
| tree | 5dcc2ae23f3eb1e05329e168a142b54a9a8a358c /clang/test/SemaOpenCL | |
| parent | fa9eec2e6b6bacc2d5e4aa906c3681ccceaa532c (diff) | |
| download | bcm5719-llvm-c65605d008dd409afd768328fe0250bb33ff0e3b.tar.gz bcm5719-llvm-c65605d008dd409afd768328fe0250bb33ff0e3b.zip | |
OpenCL: handle shift operator with vector operands
Introduce a number of checks:
1. If LHS is a scalar, then RHS cannot be a vector.
2. Operands must be of integer type.
3. If both are vectors, then the number of elements must match.
Relax the requirement for "usual arithmetic conversions":
When LHS is a vector, a scalar RHS can simply be expanded into a
vector; OpenCL does not require that its rank be lower than the LHS.
For example, the following code is not an error even if the implicit
type of the constant literal is "int".
char2 foo(char2 v) { return v << 1; }
Consolidate existing tests under CodeGenOpenCL, and add more tests
under SemaOpenCL.
llvm-svn: 228382
Diffstat (limited to 'clang/test/SemaOpenCL')
| -rw-r--r-- | clang/test/SemaOpenCL/shifts.cl | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/clang/test/SemaOpenCL/shifts.cl b/clang/test/SemaOpenCL/shifts.cl index 5b0c6fbc844..dba140046c6 100644 --- a/clang/test/SemaOpenCL/shifts.cl +++ b/clang/test/SemaOpenCL/shifts.cl @@ -1,17 +1,54 @@ -// 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; +} + +// ** 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}} } |

