@@ -516,7 +516,7 @@ fn mk_union<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
516516
517517 Union {
518518 min_size : min_size,
519- align : align,
519+ align : if packed { 1 } else { align } ,
520520 packed : packed,
521521 fields : tys. to_vec ( ) ,
522522 }
@@ -1176,8 +1176,10 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, r: &Repr<'tcx>, discr
11761176 contents. extend_from_slice ( & [ padding ( ccx, max_sz - case. size ) ] ) ;
11771177 C_struct ( ccx, & contents[ ..] , false )
11781178 }
1179- UntaggedUnion ( ..) => {
1180- unimplemented_unions ! ( ) ;
1179+ UntaggedUnion ( ref un) => {
1180+ assert_eq ! ( discr, Disr ( 0 ) ) ;
1181+ let contents = build_const_union ( ccx, un, vals[ 0 ] ) ;
1182+ C_struct ( ccx, & contents, un. packed )
11811183 }
11821184 Univariant ( ref st) => {
11831185 assert_eq ! ( discr, Disr ( 0 ) ) ;
@@ -1272,6 +1274,21 @@ fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
12721274 cfields
12731275}
12741276
1277+ fn build_const_union < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
1278+ un : & Union < ' tcx > ,
1279+ field_val : ValueRef )
1280+ -> Vec < ValueRef > {
1281+ let mut cfields = vec ! [ field_val] ;
1282+
1283+ let offset = machine:: llsize_of_alloc ( ccx, val_ty ( field_val) ) ;
1284+ let size = roundup ( un. min_size , un. align ) ;
1285+ if offset != size {
1286+ cfields. push ( padding ( ccx, size - offset) ) ;
1287+ }
1288+
1289+ cfields
1290+ }
1291+
12751292fn padding ( ccx : & CrateContext , size : u64 ) -> ValueRef {
12761293 C_undef ( Type :: array ( & Type :: i8 ( ccx) , size) )
12771294}
0 commit comments