summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/catch-undef-behavior.c2
-rw-r--r--clang/test/CodeGenOpenCL/shifts.cl28
-rw-r--r--clang/test/Sema/shiftOpenCL.cl14
3 files changed, 43 insertions, 1 deletions
diff --git a/clang/test/CodeGen/catch-undef-behavior.c b/clang/test/CodeGen/catch-undef-behavior.c
index d0b6d1969bd..9170666d31a 100644
--- a/clang/test/CodeGen/catch-undef-behavior.c
+++ b/clang/test/CodeGen/catch-undef-behavior.c
@@ -99,7 +99,7 @@ int lsh_overflow(int a, int b) {
// CHECK: @rsh_inbounds
int rsh_inbounds(int a, int b) {
- // CHECK: %[[INBOUNDS:.*]] = icmp ult i32 %[[RHS:.*]], 32
+ // CHECK: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31
// CHECK: br i1 %[[INBOUNDS]]
// CHECK: %[[ARG1:.*]] = zext
diff --git a/clang/test/CodeGenOpenCL/shifts.cl b/clang/test/CodeGenOpenCL/shifts.cl
new file mode 100644
index 00000000000..b84ec1eeef3
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/shifts.cl
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -x cl -O1 -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: @positiveShift32
+int positiveShift32(int a,int b) {
+ //CHECK: %shl.mask = and i32 %b, 31
+ //CHECK-NEXT: %shl = shl i32 %a, %shl.mask
+ int c = a<<b;
+ int d = ((int)1)<<33;
+ //CHECK-NEXT: %add = add nsw i32 %shl, 2
+ int e = c + d;
+ //CHECK-NEXT: ret i32 %add
+ return e;
+}
+
+//CHECK: @positiveShift64
+long positiveShift64(long a,long b) {
+ //CHECK: %shr.mask = and i64 %b, 63
+ //CHECK-NEXT: %shr = ashr i64 %a, %shr.mask
+ long c = a>>b;
+ long d = ((long)8)>>65;
+ //CHECK-NEXT: %add = add nsw i64 %shr, 4
+ long e = c + d;
+ //CHECK-NEXT: ret i64 %add
+ return e;
+}
diff --git a/clang/test/Sema/shiftOpenCL.cl b/clang/test/Sema/shiftOpenCL.cl
new file mode 100644
index 00000000000..3bf97187686
--- /dev/null
+++ b/clang/test/Sema/shiftOpenCL.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -x cl -O1 -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: @array0 = common global [256 x i8]
+char array0[((int)1)<<40];
+//CHECK: @array1 = common global [256 x i8]
+char array1[((int)1)<<(-24)];
+
+//CHECK: @negativeShift32
+int negativeShift32(int a,int b) {
+ //CHECK: ret i32 65536
+ return ((int)1)<<(-16);
+}
OpenPOWER on IntegriCloud