@@ -12,7 +12,6 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
12
12
use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
13
13
use rustc_middle:: ty:: { self , adjustment:: PointerCast , Instance , Ty , TyCtxt } ;
14
14
use rustc_span:: source_map:: { Span , DUMMY_SP } ;
15
- use rustc_target:: abi:: { Abi , Int , Variants } ;
16
15
17
16
impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
18
17
#[ instrument( level = "debug" , skip( self , bx) ) ]
@@ -283,74 +282,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
283
282
CastTy :: from_ty ( operand. layout . ty ) . expect ( "bad input type for cast" ) ;
284
283
let r_t_out = CastTy :: from_ty ( cast. ty ) . expect ( "bad output type for cast" ) ;
285
284
let ll_t_in = bx. cx ( ) . immediate_backend_type ( operand. layout ) ;
286
- match operand. layout . variants {
287
- Variants :: Single { index } => {
288
- if let Some ( discr) =
289
- operand. layout . ty . discriminant_for_variant ( bx. tcx ( ) , index)
290
- {
291
- let discr_layout = bx. cx ( ) . layout_of ( discr. ty ) ;
292
- let discr_t = bx. cx ( ) . immediate_backend_type ( discr_layout) ;
293
- let discr_val = bx. cx ( ) . const_uint_big ( discr_t, discr. val ) ;
294
- let discr_val =
295
- bx. intcast ( discr_val, ll_t_out, discr. ty . is_signed ( ) ) ;
296
-
297
- return (
298
- bx,
299
- OperandRef {
300
- val : OperandValue :: Immediate ( discr_val) ,
301
- layout : cast,
302
- } ,
303
- ) ;
304
- }
305
- }
306
- Variants :: Multiple { .. } => { }
307
- }
308
285
let llval = operand. immediate ( ) ;
309
286
310
- let mut signed = false ;
311
- if let Abi :: Scalar ( scalar) = operand. layout . abi {
312
- if let Int ( _, s) = scalar. primitive ( ) {
313
- // We use `i1` for bytes that are always `0` or `1`,
314
- // e.g., `#[repr(i8)] enum E { A, B }`, but we can't
315
- // let LLVM interpret the `i1` as signed, because
316
- // then `i1 1` (i.e., E::B) is effectively `i8 -1`.
317
- signed = !scalar. is_bool ( ) && s;
318
-
319
- if !scalar. is_always_valid ( bx. cx ( ) )
320
- && scalar. valid_range ( bx. cx ( ) ) . end
321
- >= scalar. valid_range ( bx. cx ( ) ) . start
322
- {
323
- // We want `table[e as usize ± k]` to not
324
- // have bound checks, and this is the most
325
- // convenient place to put the `assume`s.
326
- if scalar. valid_range ( bx. cx ( ) ) . start > 0 {
327
- let enum_value_lower_bound = bx. cx ( ) . const_uint_big (
328
- ll_t_in,
329
- scalar. valid_range ( bx. cx ( ) ) . start ,
330
- ) ;
331
- let cmp_start = bx. icmp (
332
- IntPredicate :: IntUGE ,
333
- llval,
334
- enum_value_lower_bound,
335
- ) ;
336
- bx. assume ( cmp_start) ;
337
- }
338
-
339
- let enum_value_upper_bound = bx
340
- . cx ( )
341
- . const_uint_big ( ll_t_in, scalar. valid_range ( bx. cx ( ) ) . end ) ;
342
- let cmp_end = bx. icmp (
343
- IntPredicate :: IntULE ,
344
- llval,
345
- enum_value_upper_bound,
346
- ) ;
347
- bx. assume ( cmp_end) ;
348
- }
349
- }
350
- }
351
-
352
287
let newval = match ( r_t_in, r_t_out) {
353
- ( CastTy :: Int ( _) , CastTy :: Int ( _) ) => bx. intcast ( llval, ll_t_out, signed) ,
288
+ ( CastTy :: Int ( i) , CastTy :: Int ( _) ) => {
289
+ bx. intcast ( llval, ll_t_out, matches ! ( i, IntTy :: I ) )
290
+ }
354
291
( CastTy :: Float , CastTy :: Float ) => {
355
292
let srcsz = bx. cx ( ) . float_width ( ll_t_in) ;
356
293
let dstsz = bx. cx ( ) . float_width ( ll_t_out) ;
@@ -362,8 +299,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
362
299
llval
363
300
}
364
301
}
365
- ( CastTy :: Int ( _ ) , CastTy :: Float ) => {
366
- if signed {
302
+ ( CastTy :: Int ( i ) , CastTy :: Float ) => {
303
+ if matches ! ( i , IntTy :: I ) {
367
304
bx. sitofp ( llval, ll_t_out)
368
305
} else {
369
306
bx. uitofp ( llval, ll_t_out)
@@ -372,8 +309,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
372
309
( CastTy :: Ptr ( _) | CastTy :: FnPtr , CastTy :: Ptr ( _) ) => {
373
310
bx. pointercast ( llval, ll_t_out)
374
311
}
375
- ( CastTy :: Int ( _) , CastTy :: Ptr ( _) ) => {
376
- let usize_llval = bx. intcast ( llval, bx. cx ( ) . type_isize ( ) , signed) ;
312
+ ( CastTy :: Int ( i) , CastTy :: Ptr ( _) ) => {
313
+ let usize_llval =
314
+ bx. intcast ( llval, bx. cx ( ) . type_isize ( ) , matches ! ( i, IntTy :: I ) ) ;
377
315
bx. inttoptr ( usize_llval, ll_t_out)
378
316
}
379
317
( CastTy :: Float , CastTy :: Int ( IntTy :: I ) ) => {
0 commit comments