brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 9e4ec15 Raw
70 lines · c
1// RUN: %clang_cc1 %s -O0 -fsanitize=shift-exponent -emit-llvm -std=c2x -triple=x86_64-unknown-linux -o - | FileCheck %s2 3// Checking that the code generation is using the unextended/untruncated4// exponent values and capping the values accordingly5 6// CHECK-LABEL: define{{.*}} i32 @test_left_variable7int test_left_variable(unsigned _BitInt(5) b, unsigned _BitInt(2) e) {8  // CHECK: load i89  // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i2]]10  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], -1,11  return b << e;12}13 14// CHECK-LABEL: define{{.*}} i32 @test_right_variable15int test_right_variable(unsigned _BitInt(2) b, unsigned _BitInt(3) e) {16  // CHECK: load i817  // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i3]]18  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1,19  return b >> e;20}21 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_literal25int test_left_literal(unsigned _BitInt(5) b) {26  // CHECK-NOT: br i1 false, label %cont, label %handler.shift_out_of_bounds27  // CHECK: br i1 true, label %cont, label %handler.shift_out_of_bounds28  return b << 3uwb;29}30 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_literal34int test_right_literal(unsigned _BitInt(2) b) {35  // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds36  // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds37  return b >> 4uwb;38}39 40// CHECK-LABEL: define{{.*}} i32 @test_signed_left_variable41int test_signed_left_variable(unsigned _BitInt(15) b, _BitInt(2) e) {42  // CHECK: load i843  // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i2]]44  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 1,45  return b << e;46}47 48// CHECK-LABEL: define{{.*}} i32 @test_signed_right_variable49int test_signed_right_variable(unsigned _BitInt(32) b, _BitInt(4) e) {50  // CHECK: load i851  // CHECK: [[E_REG:%.+]] = trunc i8 {{.*}} to [[E_SIZE:i4]]52  // CHECK: icmp ule [[E_SIZE]] [[E_REG]], 7,53  return b >> e;54}55 56// CHECK-LABEL: define{{.*}} i32 @test_signed_left_literal57int test_signed_left_literal(unsigned _BitInt(16) b) {58  // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds59  // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds60  return b << (_BitInt(4))-2wb;61}62 63// CHECK-LABEL: define{{.*}} i32 @test_signed_right_literal64int test_signed_right_literal(unsigned _BitInt(16) b) {65  // CHECK-NOT: br i1 true, label %cont, label %handler.shift_out_of_bounds66  // CHECK: br i1 false, label %cont, label %handler.shift_out_of_bounds67  return b >> (_BitInt(4))-8wb;68}69 70