@@ -95,7 +95,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
95
95
| "bitreverse" => {
96
96
let ty = substs. type_at ( 0 ) ;
97
97
let layout_of = self . layout_of ( ty) ?;
98
- let bits = self . read_scalar ( args[ 0 ] ) ?. to_bits ( layout_of. size ) ?;
98
+ let val = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
99
+ let bits = self . force_bits ( val, layout_of. size ) ?;
99
100
let kind = match layout_of. abi {
100
101
ty:: layout:: Abi :: Scalar ( ref scalar) => scalar. value ,
101
102
_ => throw_unsup ! ( TypeNotPrimitive ( ty) ) ,
@@ -149,7 +150,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
149
150
// term since the sign of the second term can be inferred from this and
150
151
// the fact that the operation has overflowed (if either is 0 no
151
152
// overflow can occur)
152
- let first_term: u128 = l. to_scalar ( ) ?. to_bits ( l. layout . size ) ?;
153
+ let first_term: u128 = self . force_bits ( l. to_scalar ( ) ?, l. layout . size ) ?;
153
154
let first_term_positive = first_term & ( 1 << ( num_bits-1 ) ) == 0 ;
154
155
if first_term_positive {
155
156
// Negative overflow not possible since the positive first term
@@ -187,7 +188,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
187
188
let ( val, overflowed, _ty) = self . overflowing_binary_op ( bin_op, l, r) ?;
188
189
if overflowed {
189
190
let layout = self . layout_of ( substs. type_at ( 0 ) ) ?;
190
- let r_val = r. to_scalar ( ) ?. to_bits ( layout. size ) ?;
191
+ let r_val = self . force_bits ( r. to_scalar ( ) ?, layout. size ) ?;
191
192
throw_ub_format ! ( "Overflowing shift by {} in `{}`" , r_val, intrinsic_name) ;
192
193
}
193
194
self . write_scalar ( val, dest) ?;
@@ -196,8 +197,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
196
197
// rotate_left: (X << (S % BW)) | (X >> ((BW - S) % BW))
197
198
// rotate_right: (X << ((BW - S) % BW)) | (X >> (S % BW))
198
199
let layout = self . layout_of ( substs. type_at ( 0 ) ) ?;
199
- let val_bits = self . read_scalar ( args[ 0 ] ) ?. to_bits ( layout. size ) ?;
200
- let raw_shift_bits = self . read_scalar ( args[ 1 ] ) ?. to_bits ( layout. size ) ?;
200
+ let val = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
201
+ let val_bits = self . force_bits ( val, layout. size ) ?;
202
+ let raw_shift = self . read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
203
+ let raw_shift_bits = self . force_bits ( raw_shift, layout. size ) ?;
201
204
let width_bits = layout. size . bits ( ) as u128 ;
202
205
let shift_bits = raw_shift_bits % width_bits;
203
206
let inv_shift_bits = ( width_bits - shift_bits) % width_bits;
0 commit comments