@@ -115,16 +115,18 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
115
115
self . context . new_function_pointer_type ( None , return_type, params, false )
116
116
}
117
117
118
- fn type_struct ( & self , fields : & [ Type < ' gcc > ] , _packed : bool ) -> Type < ' gcc > {
118
+ fn type_struct ( & self , fields : & [ Type < ' gcc > ] , packed : bool ) -> Type < ' gcc > {
119
119
let types = fields. to_vec ( ) ;
120
120
if let Some ( typ) = self . struct_types . borrow ( ) . get ( fields) {
121
121
return typ. clone ( ) ;
122
122
}
123
123
let fields: Vec < _ > = fields. iter ( ) . enumerate ( )
124
124
. map ( |( index, field) | self . context . new_field ( None , * field, & format ! ( "field{}_TODO" , index) ) )
125
125
. collect ( ) ;
126
- // TODO(antoyo): use packed.
127
126
let typ = self . context . new_struct_type ( None , "struct" , & fields) . as_type ( ) ;
127
+ if packed {
128
+ typ. set_packed ( ) ;
129
+ }
128
130
self . struct_types . borrow_mut ( ) . insert ( types, typ) ;
129
131
typ
130
132
}
@@ -209,12 +211,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
209
211
self . type_array ( self . type_from_integer ( unit) , size / unit_size)
210
212
}
211
213
212
- pub fn set_struct_body ( & self , typ : Struct < ' gcc > , fields : & [ Type < ' gcc > ] , _packed : bool ) {
213
- // TODO(antoyo): use packed.
214
+ pub fn set_struct_body ( & self , typ : Struct < ' gcc > , fields : & [ Type < ' gcc > ] , packed : bool ) {
214
215
let fields: Vec < _ > = fields. iter ( ) . enumerate ( )
215
216
. map ( |( index, field) | self . context . new_field ( None , * field, & format ! ( "field_{}" , index) ) )
216
217
. collect ( ) ;
217
218
typ. set_fields ( None , & fields) ;
219
+ if packed {
220
+ typ. as_type ( ) . set_packed ( ) ;
221
+ }
218
222
}
219
223
220
224
pub fn type_named_struct ( & self , name : & str ) -> Struct < ' gcc > {
0 commit comments