@@ -538,11 +538,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
538538 }
539539
540540 fn ret ( & mut self , mut value : RValue < ' gcc > ) {
541- if self . structs_as_pointer . borrow ( ) . contains ( & value) {
542- // NOTE: hack to workaround a limitation of the rustc API: see comment on
543- // CodegenCx.structs_as_pointer
544- value = value. dereference ( self . location ) . to_rvalue ( ) ;
545- }
546541 let expected_return_type = self . current_func ( ) . get_return_type ( ) ;
547542 if !expected_return_type. is_compatible_with ( value. get_type ( ) ) {
548543 // NOTE: due to opaque pointers now being used, we need to cast here.
@@ -700,7 +695,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
700695 let a = self . gcc_int_cast ( a, a_type) ;
701696 let b_type = b. get_type ( ) . to_unsigned ( self ) ;
702697 let b = self . gcc_int_cast ( b, b_type) ;
703- a / b
698+ self . gcc_udiv ( a , b )
704699 }
705700
706701 fn sdiv ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -712,8 +707,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
712707 // FIXME(antoyo): rustc_codegen_ssa::mir::intrinsic uses different types for a and b but they
713708 // should be the same.
714709 let typ = a. get_type ( ) . to_signed ( self ) ;
715- let b = self . context . new_cast ( self . location , b, typ) ;
716- a / b
710+ let b = self . gcc_int_cast ( b, typ) ;
711+ self . gcc_sdiv ( a , b )
717712 }
718713
719714 fn fdiv ( & mut self , a : RValue < ' gcc > , b : RValue < ' gcc > ) -> RValue < ' gcc > {
@@ -1119,13 +1114,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11191114 // TODO(antoyo)
11201115 }
11211116
1122- fn store ( & mut self , mut val : RValue < ' gcc > , ptr : RValue < ' gcc > , align : Align ) -> RValue < ' gcc > {
1123- if self . structs_as_pointer . borrow ( ) . contains ( & val) {
1124- // NOTE: hack to workaround a limitation of the rustc API: see comment on
1125- // CodegenCx.structs_as_pointer
1126- val = val. dereference ( self . location ) . to_rvalue ( ) ;
1127- }
1128-
1117+ fn store ( & mut self , val : RValue < ' gcc > , ptr : RValue < ' gcc > , align : Align ) -> RValue < ' gcc > {
11291118 self . store_with_flags ( val, ptr, align, MemFlags :: empty ( ) )
11301119 }
11311120
@@ -1508,16 +1497,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15081497 element. get_address ( self . location )
15091498 } else if value_type. dyncast_vector ( ) . is_some ( ) {
15101499 panic ! ( ) ;
1511- } else if let Some ( pointer_type) = value_type. get_pointee ( ) {
1512- if let Some ( struct_type) = pointer_type. is_struct ( ) {
1513- // NOTE: hack to workaround a limitation of the rustc API: see comment on
1514- // CodegenCx.structs_as_pointer
1515- aggregate_value
1516- . dereference_field ( self . location , struct_type. get_field ( idx as i32 ) )
1517- . to_rvalue ( )
1518- } else {
1519- panic ! ( "Unexpected type {:?}" , value_type) ;
1520- }
15211500 } else if let Some ( struct_type) = value_type. is_struct ( ) {
15221501 aggregate_value
15231502 . access_field ( self . location , struct_type. get_field ( idx as i32 ) )
@@ -1537,21 +1516,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15371516 assert_eq ! ( idx as usize as u64 , idx) ;
15381517 let value_type = aggregate_value. get_type ( ) ;
15391518
1519+ let new_val = self . current_func ( ) . new_local ( None , value_type, "aggregate_value" ) ;
1520+ self . block . add_assignment ( None , new_val, aggregate_value) ;
1521+
15401522 let lvalue = if value_type. dyncast_array ( ) . is_some ( ) {
15411523 let index = self
15421524 . context
15431525 . new_rvalue_from_long ( self . u64_type , i64:: try_from ( idx) . expect ( "i64::try_from" ) ) ;
1544- self . context . new_array_access ( self . location , aggregate_value , index)
1526+ self . context . new_array_access ( self . location , new_val , index)
15451527 } else if value_type. dyncast_vector ( ) . is_some ( ) {
15461528 panic ! ( ) ;
1547- } else if let Some ( pointer_type) = value_type. get_pointee ( ) {
1548- if let Some ( struct_type) = pointer_type. is_struct ( ) {
1549- // NOTE: hack to workaround a limitation of the rustc API: see comment on
1550- // CodegenCx.structs_as_pointer
1551- aggregate_value. dereference_field ( self . location , struct_type. get_field ( idx as i32 ) )
1552- } else {
1553- panic ! ( "Unexpected type {:?}" , value_type) ;
1554- }
1529+ } else if let Some ( struct_type) = value_type. is_struct ( ) {
1530+ new_val. access_field ( None , struct_type. get_field ( idx as i32 ) )
15551531 } else {
15561532 panic ! ( "Unexpected type {:?}" , value_type) ;
15571533 } ;
@@ -1568,7 +1544,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15681544
15691545 self . llbb ( ) . add_assignment ( self . location , lvalue, value) ;
15701546
1571- aggregate_value
1547+ new_val . to_rvalue ( )
15721548 }
15731549
15741550 fn set_personality_fn ( & mut self , _personality : Function < ' gcc > ) {
0 commit comments