1 // RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -std=c2x -triple=x86_64-unknown-linux -o - | FileCheck %s
3 // Checking that the code generation is using the unextended/untruncated
4 // exponent values and capping the values accordingly
6 // CHECK-LABEL: define{{.*}} i32 @test_left_variable
7 int test_left_variable(unsigned _BitInt(5) b
, unsigned _BitInt(2) e
) {
9 // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i2]]
10 // CHECK: icmp ule [[E_SIZE]] [[E_REG]], -1,
14 // CHECK-LABEL: define{{.*}} i32 @test_right_variable
15 int test_right_variable(unsigned _BitInt(2) b
, unsigned _BitInt(3) e
) {
17 // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i3]]
18 // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1,
22 // Old code generation would give false positives on left shifts when:
23 // value(e) > (width(b) - 1 % 2 ** width(e))
24 // CHECK-LABEL: define{{.*}} i32 @test_left_literal
25 int test_left_literal(unsigned _BitInt(5) b
) {
26 // CHECK-NOT: br i1 false, label %cont, label %handler.shift_out_of_bounds
27 // CHECK: br i1 true, label %cont, label %handler.shift_out_of_bounds
31 // Old code generation would give false positives on right shifts when:
32 // (value(e) % 2 ** width(b)) < width(b)
33 // CHECK-LABEL: define{{.*}} i32 @test_right_literal
34 int test_right_literal(unsigned _BitInt(2) b
) {
35 // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds
36 // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds
40 // CHECK-LABEL: define{{.*}} i32 @test_signed_left_variable
41 int test_signed_left_variable(unsigned _BitInt(15) b
, _BitInt(2) e
) {
43 // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i2]]
44 // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1,
48 // CHECK-LABEL: define{{.*}} i32 @test_signed_right_variable
49 int test_signed_right_variable(unsigned _BitInt(32) b
, _BitInt(4) e
) {
51 // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i4]]
52 // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 7,
56 // CHECK-LABEL: define{{.*}} i32 @test_signed_left_literal
57 int test_signed_left_literal(unsigned _BitInt(16) b
) {
58 // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds
59 // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds
60 return b
<< (_BitInt(4))-2wb
;
63 // CHECK-LABEL: define{{.*}} i32 @test_signed_right_literal
64 int test_signed_right_literal(unsigned _BitInt(16) b
) {
65 // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds
66 // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds
67 return b
>> (_BitInt(4))-8wb
;