@@ -26,6 +26,7 @@ use rustc_codegen_ssa::traits::{
26
26
use rustc_data_structures:: fx:: FxHashSet ;
27
27
use rustc_middle:: bug;
28
28
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
29
+ use rustc_middle:: mir:: Rvalue ;
29
30
use rustc_middle:: ty:: { ParamEnv , Ty , TyCtxt } ;
30
31
use rustc_middle:: ty:: layout:: { FnAbiError , FnAbiOfHelpers , FnAbiRequest , HasParamEnv , HasTyCtxt , LayoutError , LayoutOfHelpers , TyAndLayout } ;
31
32
use rustc_span:: Span ;
@@ -398,6 +399,16 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
398
399
type DIVariable = <CodegenCx < ' gcc , ' tcx > as BackendTypes >:: DIVariable ;
399
400
}
400
401
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
+
401
412
impl < ' a , ' gcc , ' tcx > BuilderMethods < ' a , ' tcx > for Builder < ' a , ' gcc , ' tcx > {
402
413
fn build ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Builder < ' a , ' gcc , ' tcx > {
403
414
Builder :: with_cx ( cx, block)
@@ -612,7 +623,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
612
623
// FIXME(antoyo): this seems to produce the wrong result.
613
624
return self . context . new_call ( self . loc , fmodf, & [ a, b] ) ;
614
625
}
615
- else if let Some ( vector_type) = a_type_unqualified. dyncast_vector ( ) {
626
+ if let Some ( vector_type) = a_type_unqualified. dyncast_vector ( ) {
616
627
assert_eq ! ( a_type_unqualified, b. get_type( ) . unqualified( ) ) ;
617
628
618
629
let num_units = vector_type. get_num_units ( ) ;
@@ -630,7 +641,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
630
641
assert_eq ! ( a_type_unqualified, self . cx. double_type) ;
631
642
632
643
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] )
634
645
}
635
646
636
647
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> {
652
663
}
653
664
654
665
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
656
672
}
657
673
658
674
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) )
660
676
}
661
677
662
678
fn neg ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
663
- self . gcc_neg ( a)
679
+ set_rval_location ( self , self . gcc_neg ( a) )
664
680
}
665
681
666
682
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) )
668
684
}
669
685
670
686
fn not ( & mut self , a : RValue < ' gcc > ) -> RValue < ' gcc > {
671
- self . gcc_not ( a)
687
+ set_rval_location ( self , self . gcc_not ( a) )
672
688
}
673
689
674
690
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) )
676
692
}
677
693
678
694
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) )
680
696
}
681
697
682
698
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) )
684
700
}
685
701
686
702
fn unchecked_usub ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
687
703
// TODO(antoyo): should generate poison value?
688
- self . gcc_sub ( a, b)
704
+ set_rval_location ( self , self . gcc_sub ( a, b) )
689
705
}
690
706
691
707
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) )
693
709
}
694
710
695
711
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) )
697
713
}
698
714
699
715
fn fadd_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
700
716
// 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)
702
718
}
703
719
704
720
fn fsub_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
705
721
// 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)
707
723
}
708
724
709
725
fn fmul_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
710
726
// 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)
712
728
}
713
729
714
730
fn fdiv_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
715
731
// 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)
717
733
}
718
734
719
735
fn frem_fast ( & mut self , lhs : RValue < ' gcc > , rhs : RValue < ' gcc > ) -> RValue < ' gcc > {
720
736
// 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
722
740
}
723
741
724
742
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> {
1005
1023
}
1006
1024
1007
1025
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) )
1009
1027
}
1010
1028
1011
1029
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) )
1013
1031
}
1014
1032
1015
1033
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) )
1017
1035
}
1018
1036
1019
1037
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) )
1021
1039
}
1022
1040
1023
1041
fn fptrunc ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1024
1042
// 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) )
1026
1044
}
1027
1045
1028
1046
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) )
1030
1048
}
1031
1049
1032
1050
fn ptrtoint ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
1033
1051
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 )
1035
1053
}
1036
1054
1037
1055
fn inttoptr ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
0 commit comments