X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Flocals.c;h=9f4c05088740af5ca6dc55dc8d7d1909b58ea1c6;hb=73dfa23c987d8a7f1154801b85c171f9e01dcd58;hp=5214a85bc9d014a300e9feb4da5aa2a8701af9cf;hpb=7a1a7745eb14df2231f0dc28034d63363d543351;p=cc65 diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 5214a85bc..9f4c05088 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -94,9 +94,16 @@ static unsigned ParseRegisterDecl (Declaration* Decl, unsigned* SC, int Reg) g_defdatalabel (InitLabel); /* Parse the initialization generating a memory image of the - * data in the RODATA segment. + * data in the RODATA segment. The function does return the size + * of the initialization data, which may be greater than the + * actual size of the type, if the type is a structure with a + * flexible array member that has been initialized. Since we must + * know the size of the data in advance for register variables, + * we cannot allow that here. */ - ParseInit (Decl->Type); + if (ParseInit (Decl->Type) != Size) { + Error ("Cannot initialize flexible array members of storage class `register'"); + } /* Generate code to copy this data into the variable space */ g_initregister (InitLabel, Reg, Size); @@ -172,14 +179,6 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC) /* Special handling for compound types */ if (IsCompound) { - /* First reserve space for the variable */ - SymData = F_ReserveLocalSpace (CurrentFunc, Size); - - /* Next, allocate the space on the stack. This means that the - * variable is now located at offset 0 from the current sp. - */ - F_AllocLocalSpace (CurrentFunc); - /* Switch to read only data */ g_userodata (); @@ -188,11 +187,25 @@ static unsigned ParseAutoDecl (Declaration* Decl, unsigned* SC) g_defdatalabel (InitLabel); /* Parse the initialization generating a memory image of the - * data in the RODATA segment. + * data in the RODATA segment. The function will return the + * actual size of the initialization data, which may be + * greater than the size of the variable if it is a struct + * that contains a flexible array member and we're not in + * ANSI mode. */ - ParseInit (Decl->Type); + Size = ParseInit (Decl->Type); - /* Generate code to copy this data into the variable space */ + /* Now reserve space for the variable on the stack */ + SymData = F_ReserveLocalSpace (CurrentFunc, Size); + + /* Next, allocate the space on the stack. This means that the + * variable is now located at offset 0 from the current sp. + */ + F_AllocLocalSpace (CurrentFunc); + + /* Generate code to copy the initialization data into the + * variable space + */ g_initauto (InitLabel, Size); } else {