@@ -26,6 +26,7 @@ use rustc_codegen_ssa::traits::{
2626use rustc_data_structures:: fx:: FxHashSet ;
2727use rustc_middle:: bug;
2828use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
29+ use rustc_middle:: mir:: Rvalue ;
2930use rustc_middle:: ty:: { ParamEnv , Ty , TyCtxt } ;
3031use rustc_middle:: ty:: layout:: { FnAbiError , FnAbiOfHelpers , FnAbiRequest , HasParamEnv , HasTyCtxt , LayoutError , LayoutOfHelpers , TyAndLayout } ;
3132use rustc_span:: Span ;
@@ -398,6 +399,16 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
398399 type DIVariable = <CodegenCx < ' gcc , ' tcx > as BackendTypes >:: DIVariable ;
399400}
400401
402+ pub fn set_rval_location < ' a , ' gcc , ' tcx > ( bx : & mut Builder < ' a , ' gcc , ' tcx > , r : RValue < ' gcc > ) -> RValue < ' gcc > {
403+ if bx. loc . is_some ( ) {
404+ unsafe {
405+ r. set_location ( bx. loc . unwrap ( ) ) ;
406+ }
407+ }
408+ r
409+
410+ }
411+
401412impl < ' a , ' gcc , ' tcx > BuilderMethods < ' a , ' tcx > for Builder < ' a , ' gcc , ' tcx > {
402413 fn build ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Builder < ' a , ' gcc , ' tcx > {
403414 Builder :: with_cx ( cx, block)
@@ -612,7 +623,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
612623 // FIXME(antoyo): this seems to produce the wrong result.
613624 return self . context . new_call ( self . loc , fmodf, & [ a, b] ) ;
614625 }
615- else if let Some ( vector_type) = a_type_unqualified. dyncast_vector ( ) {
626+ if let Some ( vector_type) = a_type_unqualified. dyncast_vector ( ) {
616627 assert_eq ! ( a_type_unqualified, b. get_type( ) . unqualified( ) ) ;
617628
618629 let num_units = vector_type. get_num_units ( ) ;
@@ -630,7 +641,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
630641 assert_eq ! ( a_type_unqualified, self . cx. double_type) ;
631642
632643 let fmod = self . context . get_builtin_function ( "fmod" ) ;
633- return self . context . new_call ( self . loc , fmod, & [ a, b] ) ;
644+ self . context . new_call ( self . loc , fmod, & [ a, b] )
634645 }
635646
636647 fn shl ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -652,73 +663,80 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
652663 }
653664
654665 fn or ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
655- self . cx . gcc_or ( a, b)
666+ let ret = self . cx . gcc_or ( a, b, self . loc ) ;
667+
668+ if self . loc . is_some ( ) {
669+ unsafe { ret. set_location ( self . loc . unwrap ( ) ) ; }
670+ }
671+ ret
656672 }
657673
658674 fn xor ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
659- self . gcc_xor ( a, b)
675+ set_rval_location ( self , self . gcc_xor ( a, b) )
660676 }
661677
662678 fn neg ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
663- self . gcc_neg ( a)
679+ set_rval_location ( self , self . gcc_neg ( a) )
664680 }
665681
666682 fn fneg ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
667- self . cx . context . new_unary_op ( self . loc , UnaryOp :: Minus , a. get_type ( ) , a)
683+ set_rval_location ( self , self . cx . context . new_unary_op ( self . loc , UnaryOp :: Minus , a. get_type ( ) , a) )
668684 }
669685
670686 fn not ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
671- self . gcc_not ( a)
687+ set_rval_location ( self , self . gcc_not ( a) )
672688 }
673689
674690 fn unchecked_sadd ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
675- self . gcc_add ( a, b)
691+ set_rval_location ( self , self . gcc_add ( a, b) )
676692 }
677693
678694 fn unchecked_uadd ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
679- self . gcc_add ( a, b)
695+ set_rval_location ( self , self . gcc_add ( a, b) )
680696 }
681697
682698 fn unchecked_ssub ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
683- self . gcc_sub ( a, b)
699+ set_rval_location ( self , self . gcc_sub ( a, b) )
684700 }
685701
686702 fn unchecked_usub ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
687703 // TODO(antoyo): should generate poison value?
688- self . gcc_sub ( a, b)
704+ set_rval_location ( self , self . gcc_sub ( a, b) )
689705 }
690706
691707 fn unchecked_smul ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
692- self . gcc_mul ( a, b)
708+ set_rval_location ( self , self . gcc_mul ( a, b) )
693709 }
694710
695711 fn unchecked_umul ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
696- self . gcc_mul ( a, b)
712+ set_rval_location ( self , self . gcc_mul ( a, b) )
697713 }
698714
699715 fn fadd_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
700716 // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
701- lhs + rhs
717+ set_rval_location ( self , lhs + rhs)
702718 }
703719
704720 fn fsub_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
705721 // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
706- lhs - rhs
722+ set_rval_location ( self , lhs - rhs)
707723 }
708724
709725 fn fmul_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
710726 // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
711- lhs * rhs
727+ set_rval_location ( self , lhs * rhs)
712728 }
713729
714730 fn fdiv_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
715731 // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
716- lhs / rhs
732+ set_rval_location ( self , lhs / rhs)
717733 }
718734
719735 fn frem_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
720736 // NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
721- self . frem ( lhs, rhs)
737+ let i = self . frem ( lhs, rhs) ;
738+ set_rval_location ( self , i) ;
739+ i
722740 }
723741
724742 fn checked_binop ( & mut self , oop : OverflowOp , typ : Ty < ' _ > , lhs : Self :: Value , rhs : Self :: Value ) -> ( Self :: Value , Self :: Value ) {
@@ -1005,33 +1023,33 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10051023 }
10061024
10071025 fn fptoui ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1008- self . gcc_float_to_uint_cast ( value, dest_ty)
1026+ set_rval_location ( self , self . gcc_float_to_uint_cast ( value, dest_ty) )
10091027 }
10101028
10111029 fn fptosi ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1012- self . gcc_float_to_int_cast ( value, dest_ty)
1030+ set_rval_location ( self , self . gcc_float_to_int_cast ( value, dest_ty) )
10131031 }
10141032
10151033 fn uitofp ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1016- self . gcc_uint_to_float_cast ( value, dest_ty)
1034+ set_rval_location ( self , self . gcc_uint_to_float_cast ( value, dest_ty) )
10171035 }
10181036
10191037 fn sitofp ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1020- self . gcc_int_to_float_cast ( value, dest_ty)
1038+ set_rval_location ( self , self . gcc_int_to_float_cast ( value, dest_ty) )
10211039 }
10221040
10231041 fn fptrunc ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
10241042 // TODO(antoyo): make sure it truncates.
1025- self . context . new_cast ( self . loc , value, dest_ty)
1043+ set_rval_location ( self , self . context . new_cast ( self . loc , value, dest_ty) )
10261044 }
10271045
10281046 fn fpext ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1029- self . context . new_cast ( self . loc , value, dest_ty)
1047+ set_rval_location ( self , self . context . new_cast ( self . loc , value, dest_ty) )
10301048 }
10311049
10321050 fn ptrtoint ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
10331051 let usize_value = self . cx . const_bitcast ( value, self . cx . type_isize ( ) ) ;
1034- self . intcast ( usize_value, dest_ty, false )
1052+ self . intcast ( usize_value, dest_ty, false )
10351053 }
10361054
10371055 fn inttoptr ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
0 commit comments