@@ -12,7 +12,6 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
1212use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
1313use rustc_middle:: ty:: { self , adjustment:: PointerCast , Instance , Ty , TyCtxt } ;
1414use rustc_span:: source_map:: { Span , DUMMY_SP } ;
15- use rustc_target:: abi:: { Abi , Int , Variants } ;
1615
1716impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
1817 #[ instrument( level = "debug" , skip( self , bx) ) ]
@@ -283,74 +282,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
283282 CastTy :: from_ty ( operand. layout . ty ) . expect ( "bad input type for cast" ) ;
284283 let r_t_out = CastTy :: from_ty ( cast. ty ) . expect ( "bad output type for cast" ) ;
285284 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- }
308285 let llval = operand. immediate ( ) ;
309286
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-
352287 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+ }
354291 ( CastTy :: Float , CastTy :: Float ) => {
355292 let srcsz = bx. cx ( ) . float_width ( ll_t_in) ;
356293 let dstsz = bx. cx ( ) . float_width ( ll_t_out) ;
@@ -362,8 +299,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
362299 llval
363300 }
364301 }
365- ( CastTy :: Int ( _ ) , CastTy :: Float ) => {
366- if signed {
302+ ( CastTy :: Int ( i ) , CastTy :: Float ) => {
303+ if matches ! ( i , IntTy :: I ) {
367304 bx. sitofp ( llval, ll_t_out)
368305 } else {
369306 bx. uitofp ( llval, ll_t_out)
@@ -372,8 +309,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
372309 ( CastTy :: Ptr ( _) | CastTy :: FnPtr , CastTy :: Ptr ( _) ) => {
373310 bx. pointercast ( llval, ll_t_out)
374311 }
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 ) ) ;
377315 bx. inttoptr ( usize_llval, ll_t_out)
378316 }
379317 ( CastTy :: Float , CastTy :: Int ( IntTy :: I ) ) => {
0 commit comments