[Bug c/25805] New: Incorrect handling of zero-initialized flexible arrays
rsandifo at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Jan 16 10:19:00 GMT 2006
A GNU C extension allows you to initialise a flexible array field.
However, if you do this, the DECL_SIZE of the containing object does not
account for the size of the initialised array. DECL_SIZE is simply
CHAR_BIT * sizeof (the structure type). Thus if you have:
struct { int a; int x[]; } d1 = { 0, 0 };
and if -fzero-initialized-in-bss is in effect, we will only allocate
one int for d1, not two:
d1:
.zero 4
A simple executable testcase is:
-------------------------------------------------
struct { int a; int x[]; } d1 = { 0, 0 };
int d2 = 0;
int main ()
{
d2 = 1;
if (d1.x[0] != 0)
abort ();
exit (0);
}
-------------------------------------------------
The testcase passes if compiled with -fno-zero-initialized-in-bss.
--
Summary: Incorrect handling of zero-initialized flexible arrays
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rsandifo at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25805
More information about the Gcc-bugs
mailing list