@@ -546,7 +546,7 @@ outputInitList(Flexbuf *f, int elemsize, AST *initval, int numelems, Flexbuf *re
546546}
547547
548548int
549- outputInitializer (Flexbuf * f , AST * type , AST * initval , Flexbuf * relocs )
549+ outputInitializer (Flexbuf * f , AST * type , AST * initval , Flexbuf * relocs , int is_packed )
550550{
551551 int elemsize ;
552552 int typealign , typesize ;
@@ -557,7 +557,7 @@ outputInitializer(Flexbuf *f, AST *type, AST *initval, Flexbuf *relocs)
557557 int siz = 0 ;
558558
559559 type = RemoveTypeModifiers (type );
560- typealign = TypeAlign (type );
560+ typealign = is_packed ? 1 : TypeAlign (type );
561561 elemsize = typesize = TypeSize (type );
562562 numelems = 1 ;
563563
@@ -598,7 +598,7 @@ outputInitializer(Flexbuf *f, AST *type, AST *initval, Flexbuf *relocs)
598598 }
599599 while (numelems > 0 && initval ) {
600600 -- numelems ;
601- siz += outputInitializer (f , type , initval -> left , relocs );
601+ siz += outputInitializer (f , type , initval -> left , relocs , is_packed );
602602 initval = initval -> right ;
603603 }
604604 if (numelems > 0 ) {
@@ -612,6 +612,7 @@ outputInitializer(Flexbuf *f, AST *type, AST *initval, Flexbuf *relocs)
612612 case AST_OBJECT : {
613613 P = GetClassPtr (type );
614614 is_union = P -> isUnion ;
615+ is_packed = P -> isPacked ;
615616 varlist = P -> finalvarblock ;
616617 if (initval -> kind != AST_EXPRLIST ) {
617618 initval = NewAST (AST_EXPRLIST , initval , NULL );
@@ -645,7 +646,7 @@ outputInitializer(Flexbuf *f, AST *type, AST *initval, Flexbuf *relocs)
645646 if (subsiz >= LONG_SIZE ) {
646647 subsiz = (subsiz + LONG_SIZE - 1 ) & ~(LONG_SIZE - 1 );
647648 }
648- r = outputInitializer (f , subtype , subinit , relocs );
649+ r = outputInitializer (f , subtype , subinit , relocs , is_packed );
649650 while (r < subsiz ) {
650651 outputByte (f , 0 );
651652 r ++ ;
@@ -2039,7 +2040,7 @@ outputVarDeclare(Flexbuf *f, AST *ast, Flexbuf *relocs)
20392040 }
20402041 typsiz = TypeSize (type );
20412042 AlignPc (f , TypeAlign (type ));
2042- siz = outputInitializer (f , type , initval , relocs );
2043+ siz = outputInitializer (f , type , initval , relocs , 0 );
20432044 if (siz != typsiz ) {
20442045 ERROR (initval , "Bad initialization size: expected %d got %d" , typsiz , siz );
20452046 }
0 commit comments