@@ -19,28 +19,30 @@ use trans::common::{self, Block, Result};
1919use trans:: debuginfo:: DebugLoc ;
2020use trans:: declare;
2121use trans:: expr;
22+ use trans:: adt;
2223use trans:: machine;
2324use trans:: type_:: Type ;
2425use trans:: type_of;
2526use trans:: tvec;
2627
2728use super :: MirContext ;
2829use super :: operand:: { OperandRef , OperandValue } ;
30+ use super :: lvalue:: LvalueRef ;
2931
3032impl < ' bcx , ' tcx > MirContext < ' bcx , ' tcx > {
3133 pub fn trans_rvalue ( & mut self ,
3234 bcx : Block < ' bcx , ' tcx > ,
33- lldest : ValueRef ,
35+ dest : LvalueRef < ' tcx > ,
3436 rvalue : & mir:: Rvalue < ' tcx > )
3537 -> Block < ' bcx , ' tcx >
3638 {
37- debug ! ( "trans_rvalue(lldest ={}, rvalue={:?})" ,
38- bcx. val_to_string( lldest ) ,
39+ debug ! ( "trans_rvalue(dest.llval ={}, rvalue={:?})" ,
40+ bcx. val_to_string( dest . llval ) ,
3941 rvalue) ;
4042
4143 match * rvalue {
4244 mir:: Rvalue :: Use ( ref operand) => {
43- self . trans_operand_into ( bcx, lldest , operand) ;
45+ self . trans_operand_into ( bcx, dest . llval , operand) ;
4446 bcx
4547 }
4648
@@ -49,7 +51,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4951 // into-coerce of a thin pointer to a fat pointer - just
5052 // use the operand path.
5153 let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
52- self . store_operand ( bcx, lldest , temp) ;
54+ self . store_operand ( bcx, dest . llval , temp) ;
5355 return bcx;
5456 }
5557
@@ -72,12 +74,12 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
7274 base:: store_ty ( bcx, llval, lltemp, operand. ty ) ;
7375 base:: coerce_unsized_into ( bcx,
7476 lltemp, operand. ty ,
75- lldest , cast_ty) ;
77+ dest . llval , cast_ty) ;
7678 }
7779 OperandValue :: Ref ( llref) => {
7880 base:: coerce_unsized_into ( bcx,
7981 llref, operand. ty ,
80- lldest , cast_ty) ;
82+ dest . llval , cast_ty) ;
8183 }
8284 }
8385 bcx
@@ -86,20 +88,31 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
8688 mir:: Rvalue :: Repeat ( ref elem, ref count) => {
8789 let elem = self . trans_operand ( bcx, elem) ;
8890 let size = self . trans_constant ( bcx, count) . immediate ( ) ;
89- let base = expr:: get_dataptr ( bcx, lldest ) ;
91+ let base = expr:: get_dataptr ( bcx, dest . llval ) ;
9092 tvec:: iter_vec_raw ( bcx, base, elem. ty , size, |bcx, llslot, _| {
9193 self . store_operand ( bcx, llslot, elem) ;
9294 bcx
9395 } )
9496 }
9597
96- mir:: Rvalue :: Aggregate ( _, ref operands) => {
97- for ( i, operand) in operands. iter ( ) . enumerate ( ) {
98- // Note: perhaps this should be StructGep, but
99- // note that in some cases the values here will
100- // not be structs but arrays.
101- let lldest_i = build:: GEPi ( bcx, lldest, & [ 0 , i] ) ;
102- self . trans_operand_into ( bcx, lldest_i, operand) ;
98+ mir:: Rvalue :: Aggregate ( ref kind, ref operands) => {
99+ match * kind {
100+ // Unit struct, which is translated very differently compared to any other
101+ // aggregate
102+ mir:: AggregateKind :: Adt ( adt_def, 0 , _)
103+ if adt_def. struct_variant ( ) . kind ( ) == ty:: VariantKind :: Unit => {
104+ let repr = adt:: represent_type ( bcx. ccx ( ) , dest. ty . to_ty ( bcx. tcx ( ) ) ) ;
105+ adt:: trans_set_discr ( bcx, & * repr, dest. llval , 0 ) ;
106+ } ,
107+ _ => {
108+ for ( i, operand) in operands. iter ( ) . enumerate ( ) {
109+ // Note: perhaps this should be StructGep, but
110+ // note that in some cases the values here will
111+ // not be structs but arrays.
112+ let lldest_i = build:: GEPi ( bcx, dest. llval , & [ 0 , i] ) ;
113+ self . trans_operand_into ( bcx, lldest_i, operand) ;
114+ }
115+ }
103116 }
104117 bcx
105118 }
@@ -113,9 +126,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
113126 let llbase1 = build:: GEPi ( bcx, llbase, & [ from_start] ) ;
114127 let adj = common:: C_uint ( ccx, from_start + from_end) ;
115128 let lllen1 = build:: Sub ( bcx, lllen, adj, DebugLoc :: None ) ;
116- let lladdrdest = expr:: get_dataptr ( bcx, lldest ) ;
129+ let lladdrdest = expr:: get_dataptr ( bcx, dest . llval ) ;
117130 build:: Store ( bcx, llbase1, lladdrdest) ;
118- let llmetadest = expr:: get_meta ( bcx, lldest ) ;
131+ let llmetadest = expr:: get_meta ( bcx, dest . llval ) ;
119132 build:: Store ( bcx, lllen1, llmetadest) ;
120133 bcx
121134 }
@@ -127,7 +140,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
127140 _ => {
128141 assert ! ( rvalue_creates_operand( rvalue) ) ;
129142 let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
130- self . store_operand ( bcx, lldest , temp) ;
143+ self . store_operand ( bcx, dest . llval , temp) ;
131144 bcx
132145 }
133146 }
0 commit comments