diff --git a/src/int.rs b/src/int.rs index d2df9d2dcb6..c3ed71ff730 100644 --- a/src/int.rs +++ b/src/int.rs @@ -68,14 +68,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { let a_native = self.is_native_int_type(a_type); let b_native = self.is_native_int_type(b_type); if a_native && b_native { - // FIXME(antoyo): remove the casts when libgccjit can shift an unsigned number by an unsigned number. + // FIXME(antoyo): remove the casts when libgccjit can shift an unsigned number by a signed number. // TODO(antoyo): cast to unsigned to do a logical shift if that does not work. - if a_type.is_unsigned(self) && b_type.is_signed(self) { - let a = self.context.new_cast(None, a, b_type); - let result = a >> b; - self.context.new_cast(None, result, a_type) - } - else if a_type.is_signed(self) && b_type.is_unsigned(self) { + if a_type.is_signed(self) != b_type.is_signed(self) { let b = self.context.new_cast(None, b, a_type); a >> b } diff --git a/tests/run/int.rs b/tests/run/int.rs index 7a62fc7d1f7..49376012c40 100644 --- a/tests/run/int.rs +++ b/tests/run/int.rs @@ -71,6 +71,8 @@ fn main(argc: isize, _argv: *const *const u8) -> isize { assert_eq!(var3 << (argc + 62) as u128, 96618259944854013731572476686437974016); assert_eq!(var3 << (argc + 63) as u128, 193236519889708027463144953372875948032); + assert_eq!((2220326408_u32 + argc as u32) >> (32 - 6), 33); + assert_eq!(var >> (argc as u128 - 1), var); assert_eq!(var >> argc as u128, 67108928); assert_eq!(var >> (argc + 32) as u128, 0);