@@ -19,28 +19,30 @@ use trans::common::{self, Block, Result};
19
19
use trans:: debuginfo:: DebugLoc ;
20
20
use trans:: declare;
21
21
use trans:: expr;
22
+ use trans:: adt;
22
23
use trans:: machine;
23
24
use trans:: type_:: Type ;
24
25
use trans:: type_of;
25
26
use trans:: tvec;
26
27
27
28
use super :: MirContext ;
28
29
use super :: operand:: { OperandRef , OperandValue } ;
30
+ use super :: lvalue:: LvalueRef ;
29
31
30
32
impl < ' bcx , ' tcx > MirContext < ' bcx , ' tcx > {
31
33
pub fn trans_rvalue ( & mut self ,
32
34
bcx : Block < ' bcx , ' tcx > ,
33
- lldest : ValueRef ,
35
+ dest : LvalueRef < ' tcx > ,
34
36
rvalue : & mir:: Rvalue < ' tcx > )
35
37
-> Block < ' bcx , ' tcx >
36
38
{
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 ) ,
39
41
rvalue) ;
40
42
41
43
match * rvalue {
42
44
mir:: Rvalue :: Use ( ref operand) => {
43
- self . trans_operand_into ( bcx, lldest , operand) ;
45
+ self . trans_operand_into ( bcx, dest . llval , operand) ;
44
46
bcx
45
47
}
46
48
@@ -49,7 +51,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
49
51
// into-coerce of a thin pointer to a fat pointer - just
50
52
// use the operand path.
51
53
let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
52
- self . store_operand ( bcx, lldest , temp) ;
54
+ self . store_operand ( bcx, dest . llval , temp) ;
53
55
return bcx;
54
56
}
55
57
@@ -72,12 +74,12 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
72
74
base:: store_ty ( bcx, llval, lltemp, operand. ty ) ;
73
75
base:: coerce_unsized_into ( bcx,
74
76
lltemp, operand. ty ,
75
- lldest , cast_ty) ;
77
+ dest . llval , cast_ty) ;
76
78
}
77
79
OperandValue :: Ref ( llref) => {
78
80
base:: coerce_unsized_into ( bcx,
79
81
llref, operand. ty ,
80
- lldest , cast_ty) ;
82
+ dest . llval , cast_ty) ;
81
83
}
82
84
}
83
85
bcx
@@ -86,20 +88,31 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
86
88
mir:: Rvalue :: Repeat ( ref elem, ref count) => {
87
89
let elem = self . trans_operand ( bcx, elem) ;
88
90
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 ) ;
90
92
tvec:: iter_vec_raw ( bcx, base, elem. ty , size, |bcx, llslot, _| {
91
93
self . store_operand ( bcx, llslot, elem) ;
92
94
bcx
93
95
} )
94
96
}
95
97
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
+ }
103
116
}
104
117
bcx
105
118
}
@@ -113,9 +126,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
113
126
let llbase1 = build:: GEPi ( bcx, llbase, & [ from_start] ) ;
114
127
let adj = common:: C_uint ( ccx, from_start + from_end) ;
115
128
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 ) ;
117
130
build:: Store ( bcx, llbase1, lladdrdest) ;
118
- let llmetadest = expr:: get_meta ( bcx, lldest ) ;
131
+ let llmetadest = expr:: get_meta ( bcx, dest . llval ) ;
119
132
build:: Store ( bcx, lllen1, llmetadest) ;
120
133
bcx
121
134
}
@@ -127,7 +140,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
127
140
_ => {
128
141
assert ! ( rvalue_creates_operand( rvalue) ) ;
129
142
let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
130
- self . store_operand ( bcx, lldest , temp) ;
143
+ self . store_operand ( bcx, dest . llval , temp) ;
131
144
bcx
132
145
}
133
146
}
0 commit comments