@@ -88,6 +88,7 @@ pub enum Repr {
88
88
struct Struct {
89
89
size : u64 ,
90
90
align : u64 ,
91
+ packed : bool ,
91
92
fields : ~[ ty:: t ]
92
93
}
93
94
@@ -109,17 +110,18 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
109
110
}
110
111
let repr = @match ty:: get ( t) . sty {
111
112
ty:: ty_tup( ref elems) => {
112
- Univariant ( mk_struct ( cx, * elems) , false )
113
+ Univariant ( mk_struct ( cx, * elems, false ) , false )
113
114
}
114
115
ty:: ty_struct( def_id, ref substs) => {
115
116
let fields = ty:: lookup_struct_fields ( cx. tcx , def_id) ;
116
117
let ftys = do fields. map |field| {
117
118
ty:: lookup_field_type ( cx. tcx , def_id, field. id , substs)
118
119
} ;
120
+ let packed = ty:: lookup_packed ( cx. tcx , def_id) ;
119
121
let dtor = ty:: ty_dtor ( cx. tcx , def_id) . is_present ( ) ;
120
122
let ftys =
121
123
if dtor { ftys + [ ty:: mk_bool ( cx. tcx ) ] } else { ftys } ;
122
- Univariant ( mk_struct ( cx, ftys) , dtor)
124
+ Univariant ( mk_struct ( cx, ftys, packed ) , dtor)
123
125
}
124
126
ty:: ty_enum( def_id, ref substs) => {
125
127
struct Case { discr : int , tys : ~[ ty:: t ] } ;
@@ -132,15 +134,15 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
132
134
} ;
133
135
if cases. len ( ) == 0 {
134
136
// Uninhabitable; represent as unit
135
- Univariant ( mk_struct ( cx, ~[ ] ) , false )
137
+ Univariant ( mk_struct ( cx, ~[ ] , false ) , false )
136
138
} else if cases. all ( |c| c. tys . len ( ) == 0 ) {
137
139
// All bodies empty -> intlike
138
140
let discrs = cases. map ( |c| c. discr ) ;
139
141
CEnum ( discrs. min ( ) , discrs. max ( ) )
140
142
} else if cases. len ( ) == 1 {
141
143
// Equivalent to a struct/tuple/newtype.
142
144
assert ! ( cases[ 0 ] . discr == 0 ) ;
143
- Univariant ( mk_struct ( cx, cases[ 0 ] . tys ) , false )
145
+ Univariant ( mk_struct ( cx, cases[ 0 ] . tys , false ) , false )
144
146
} else {
145
147
// The general case. Since there's at least one
146
148
// non-empty body, explicit discriminants should have
@@ -151,7 +153,7 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
151
153
ty:: item_path_str( cx. tcx, def_id) ) )
152
154
}
153
155
let discr = ~[ ty:: mk_int ( cx. tcx ) ] ;
154
- General ( cases. map ( |c| mk_struct ( cx, discr + c. tys ) ) )
156
+ General ( cases. map ( |c| mk_struct ( cx, discr + c. tys , false ) ) )
155
157
}
156
158
}
157
159
_ => cx. sess . bug ( ~"adt:: represent_type called on non-ADT type")
@@ -160,12 +162,13 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
160
162
return repr;
161
163
}
162
164
163
- fn mk_struct ( cx : @CrateContext , tys : & [ ty:: t ] ) -> Struct {
165
+ fn mk_struct ( cx : @CrateContext , tys : & [ ty:: t ] , packed : bool ) -> Struct {
164
166
let lltys = tys. map ( |& ty| type_of:: sizing_type_of ( cx, ty) ) ;
165
- let llty_rec = T_struct ( lltys) ;
167
+ let llty_rec = T_struct ( lltys, packed ) ;
166
168
Struct {
167
169
size : machine:: llsize_of_alloc ( cx, llty_rec) /*bad*/ as u64 ,
168
170
align : machine:: llalign_of_min ( cx, llty_rec) /*bad*/ as u64 ,
171
+ packed : packed,
169
172
fields : vec:: from_slice ( tys)
170
173
}
171
174
}
@@ -358,7 +361,8 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
358
361
359
362
let val = if needs_cast {
360
363
let real_llty = T_struct ( st. fields . map (
361
- |& ty| type_of:: type_of ( ccx, ty) ) ) ;
364
+ |& ty| type_of:: type_of ( ccx, ty) ) ,
365
+ st. packed ) ;
362
366
PointerCast ( bcx, val, T_ptr ( real_llty) )
363
367
} else {
364
368
val
0 commit comments