Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / ubsan-shift.c
blobbc581e80557b1d46691649633860fe0b8f626c3a
1 // RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent,shift-base -emit-llvm %s -o - | FileCheck %s
3 // CHECK-LABEL: define{{.*}} i32 @f1
4 int f1(int c, int shamt) {
5 // CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
6 // CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
7 return 1 << (c << shamt);
10 // CHECK-LABEL: define{{.*}} i32 @f2
11 int f2(long c, int shamt) {
12 // CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
13 // CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
14 return 1 << (c << shamt);
17 // CHECK-LABEL: define{{.*}} i32 @f3
18 unsigned f3(unsigned c, int shamt) {
19 // CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
20 // CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
21 return 1U << (c << shamt);
24 // CHECK-LABEL: define{{.*}} i32 @f4
25 unsigned f4(unsigned long c, int shamt) {
26 // CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
27 // CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
28 return 1U << (c << shamt);
31 // CHECK-LABEL: define{{.*}} i32 @f5
32 int f5(int c, long long shamt) {
33 // CHECK: icmp ule i64 %{{[0-9]+}}, 31, !nosanitize
35 // CHECK: sub nuw nsw i32 31, %sh_prom, !nosanitize
36 // CHECK: lshr i32 %{{.*}}, %shl.zeros, !nosanitize
37 return c << shamt;
40 // CHECK-LABEL: define{{.*}} i32 @f6
41 int f6(int c, int shamt) {
42 // CHECK: icmp ule i32 %[[WIDTH:.*]], 31, !nosanitize
44 // CHECK: sub nuw nsw i32 31, %[[WIDTH]], !nosanitize
45 // CHECK: lshr i32 %{{.*}}, %shl.zeros, !nosanitize
46 return c << shamt;