@@ -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 > {
@@ -931,10 +926,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
931926 . get_address ( self . location )
932927 }
933928
934- fn dynamic_alloca ( & mut self , _len : RValue < ' gcc > , _align : Align ) -> RValue < ' gcc > {
935- unimplemented ! ( ) ;
936- }
937-
938929 fn load ( & mut self , pointee_ty : Type < ' gcc > , ptr : RValue < ' gcc > , align : Align ) -> RValue < ' gcc > {
939930 let block = self . llbb ( ) ;
940931 let function = block. get_function ( ) ;
@@ -1119,13 +1110,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11191110 // TODO(antoyo)
11201111 }
11211112
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-
1113+ fn store ( & mut self , val : RValue < ' gcc > , ptr : RValue < ' gcc > , align : Align ) -> RValue < ' gcc > {
11291114 self . store_with_flags ( val, ptr, align, MemFlags :: empty ( ) )
11301115 }
11311116
@@ -1508,16 +1493,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15081493 element. get_address ( self . location )
15091494 } else if value_type. dyncast_vector ( ) . is_some ( ) {
15101495 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- }
15211496 } else if let Some ( struct_type) = value_type. is_struct ( ) {
15221497 aggregate_value
15231498 . access_field ( self . location , struct_type. get_field ( idx as i32 ) )
@@ -1537,21 +1512,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15371512 assert_eq ! ( idx as usize as u64 , idx) ;
15381513 let value_type = aggregate_value. get_type ( ) ;
15391514
1515+ let new_val = self . current_func ( ) . new_local ( None , value_type, "aggregate_value" ) ;
1516+ self . block . add_assignment ( None , new_val, aggregate_value) ;
1517+
15401518 let lvalue = if value_type. dyncast_array ( ) . is_some ( ) {
15411519 let index = self
15421520 . context
15431521 . 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)
1522+ self . context . new_array_access ( self . location , new_val , index)
15451523 } else if value_type. dyncast_vector ( ) . is_some ( ) {
15461524 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- }
1525+ } else if let Some ( struct_type) = value_type. is_struct ( ) {
1526+ new_val. access_field ( None , struct_type. get_field ( idx as i32 ) )
15551527 } else {
15561528 panic ! ( "Unexpected type {:?}" , value_type) ;
15571529 } ;
@@ -1568,7 +1540,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15681540
15691541 self . llbb ( ) . add_assignment ( self . location , lvalue, value) ;
15701542
1571- aggregate_value
1543+ new_val . to_rvalue ( )
15721544 }
15731545
15741546 fn set_personality_fn ( & mut self , _personality : Function < ' gcc > ) {
0 commit comments