This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/25805] New: Incorrect handling of zero-initialized flexible arrays
- From: "rsandifo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jan 2006 10:19:18 -0000
- Subject: [Bug c/25805] New: Incorrect handling of zero-initialized flexible arrays
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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