@@ -538,11 +538,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
538
538
}
539
539
540
540
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
- }
546
541
let expected_return_type = self . current_func ( ) . get_return_type ( ) ;
547
542
if !expected_return_type. is_compatible_with ( value. get_type ( ) ) {
548
543
// 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> {
700
695
let a = self . gcc_int_cast ( a, a_type) ;
701
696
let b_type = b. get_type ( ) . to_unsigned ( self ) ;
702
697
let b = self . gcc_int_cast ( b, b_type) ;
703
- a / b
698
+ self . gcc_udiv ( a , b )
704
699
}
705
700
706
701
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> {
712
707
// FIXME(antoyo): rustc_codegen_ssa::mir::intrinsic uses different types for a and b but they
713
708
// should be the same.
714
709
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 )
717
712
}
718
713
719
714
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> {
1119
1114
// TODO(antoyo)
1120
1115
}
1121
1116
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 > {
1129
1118
self . store_with_flags ( val, ptr, align, MemFlags :: empty ( ) )
1130
1119
}
1131
1120
@@ -1508,16 +1497,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
1508
1497
element. get_address ( self . location )
1509
1498
} else if value_type. dyncast_vector ( ) . is_some ( ) {
1510
1499
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
- }
1521
1500
} else if let Some ( struct_type) = value_type. is_struct ( ) {
1522
1501
aggregate_value
1523
1502
. 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> {
1537
1516
assert_eq ! ( idx as usize as u64 , idx) ;
1538
1517
let value_type = aggregate_value. get_type ( ) ;
1539
1518
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
+
1540
1522
let lvalue = if value_type. dyncast_array ( ) . is_some ( ) {
1541
1523
let index = self
1542
1524
. context
1543
1525
. 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)
1545
1527
} else if value_type. dyncast_vector ( ) . is_some ( ) {
1546
1528
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 ) )
1555
1531
} else {
1556
1532
panic ! ( "Unexpected type {:?}" , value_type) ;
1557
1533
} ;
@@ -1568,7 +1544,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
1568
1544
1569
1545
self . llbb ( ) . add_assignment ( self . location , lvalue, value) ;
1570
1546
1571
- aggregate_value
1547
+ new_val . to_rvalue ( )
1572
1548
}
1573
1549
1574
1550
fn set_personality_fn ( & mut self , _personality : Function < ' gcc > ) {
0 commit comments