@@ -88,6 +88,7 @@ pub enum Repr {
8888struct Struct {
8989 size : u64 ,
9090 align : u64 ,
91+ packed : bool ,
9192 fields : ~[ ty:: t ]
9293}
9394
@@ -109,17 +110,18 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
109110 }
110111 let repr = @match ty:: get ( t) . sty {
111112 ty:: ty_tup( ref elems) => {
112- Univariant ( mk_struct ( cx, * elems) , false )
113+ Univariant ( mk_struct ( cx, * elems, false ) , false )
113114 }
114115 ty:: ty_struct( def_id, ref substs) => {
115116 let fields = ty:: lookup_struct_fields ( cx. tcx , def_id) ;
116117 let ftys = do fields. map |field| {
117118 ty:: lookup_field_type ( cx. tcx , def_id, field. id , substs)
118119 } ;
120+ let packed = ty:: lookup_packed ( cx. tcx , def_id) ;
119121 let dtor = ty:: ty_dtor ( cx. tcx , def_id) . is_present ( ) ;
120122 let ftys =
121123 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)
123125 }
124126 ty:: ty_enum( def_id, ref substs) => {
125127 struct Case { discr : int , tys : ~[ ty:: t ] } ;
@@ -132,15 +134,15 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
132134 } ;
133135 if cases. len ( ) == 0 {
134136 // Uninhabitable; represent as unit
135- Univariant ( mk_struct ( cx, ~[ ] ) , false )
137+ Univariant ( mk_struct ( cx, ~[ ] , false ) , false )
136138 } else if cases. all ( |c| c. tys . len ( ) == 0 ) {
137139 // All bodies empty -> intlike
138140 let discrs = cases. map ( |c| c. discr ) ;
139141 CEnum ( discrs. min ( ) , discrs. max ( ) )
140142 } else if cases. len ( ) == 1 {
141143 // Equivalent to a struct/tuple/newtype.
142144 assert ! ( cases[ 0 ] . discr == 0 ) ;
143- Univariant ( mk_struct ( cx, cases[ 0 ] . tys ) , false )
145+ Univariant ( mk_struct ( cx, cases[ 0 ] . tys , false ) , false )
144146 } else {
145147 // The general case. Since there's at least one
146148 // non-empty body, explicit discriminants should have
@@ -151,7 +153,7 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
151153 ty:: item_path_str( cx. tcx, def_id) ) )
152154 }
153155 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 ) ) )
155157 }
156158 }
157159 _ => 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 {
160162 return repr;
161163}
162164
163- fn mk_struct ( cx : @CrateContext , tys : & [ ty:: t ] ) -> Struct {
165+ fn mk_struct ( cx : @CrateContext , tys : & [ ty:: t ] , packed : bool ) -> Struct {
164166 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 ) ;
166168 Struct {
167169 size : machine:: llsize_of_alloc ( cx, llty_rec) /*bad*/ as u64 ,
168170 align : machine:: llalign_of_min ( cx, llty_rec) /*bad*/ as u64 ,
171+ packed : packed,
169172 fields : vec:: from_slice ( tys)
170173 }
171174}
@@ -358,7 +361,8 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
358361
359362 let val = if needs_cast {
360363 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 ) ;
362366 PointerCast ( bcx, val, T_ptr ( real_llty) )
363367 } else {
364368 val
0 commit comments