1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsanitize=unsigned-shift-base,shift-exponent %s -emit-llvm -o - | FileCheck %s
3 // CHECK-LABEL: lsh_overflow(
4 unsigned lsh_overflow(unsigned a
, unsigned b
) {
5 // CHECK: %[[RHS_INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31
6 // CHECK-NEXT: br i1 %[[RHS_INBOUNDS]], label %[[CHECK_BB:.*]], label %[[CONT_BB:.*]],
8 // CHECK: [[CHECK_BB]]:
9 // CHECK-NEXT: %[[SHIFTED_OUT_WIDTH:.*]] = sub nuw nsw i32 31, %[[RHS]]
10 // CHECK-NEXT: %[[SHIFTED_OUT:.*]] = lshr i32 %[[LHS:.*]], %[[SHIFTED_OUT_WIDTH]]
12 // CHECK-NEXT: %[[SHIFTED_OUT_NOT_SIGN:.*]] = lshr i32 %[[SHIFTED_OUT]], 1
14 // CHECK-NEXT: %[[NO_OVERFLOW:.*]] = icmp eq i32 %[[SHIFTED_OUT_NOT_SIGN]], 0
15 // CHECK-NEXT: br label %[[CONT_BB]]
17 // CHECK: [[CONT_BB]]:
18 // CHECK-NEXT: %[[VALID_BASE:.*]] = phi i1 [ true, {{.*}} ], [ %[[NO_OVERFLOW]], %[[CHECK_BB]] ]
19 // CHECK-NEXT: %[[VALID:.*]] = and i1 %[[RHS_INBOUNDS]], %[[VALID_BASE]]
20 // CHECK-NEXT: br i1 %[[VALID]]
22 // CHECK: call void @__ubsan_handle_shift_out_of_bounds
23 // CHECK-NOT: call void @__ubsan_handle_shift_out_of_bounds
25 // CHECK: %[[RET:.*]] = shl i32 %[[LHS]], %[[RHS]]
26 // CHECK-NEXT: ret i32 %[[RET]]