public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25805]  New: Incorrect handling of zero-initialized flexible arrays
@ 2006-01-16 10:19 rsandifo at gcc dot gnu dot org
  2006-01-16 10:19 ` [Bug c/25805] " rsandifo at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rsandifo at gcc dot gnu dot org @ 2006-01-16 10:19 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-03-11  3:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-16 10:19 [Bug c/25805] New: Incorrect handling of zero-initialized flexible arrays rsandifo at gcc dot gnu dot org
2006-01-16 10:19 ` [Bug c/25805] " rsandifo at gcc dot gnu dot org
2006-01-16 15:54 ` [Bug c/25805] [3.4/4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-01-19  7:45 ` rsandifo at gcc dot gnu dot org
2006-01-19  7:46 ` rsandifo at gcc dot gnu dot org
2006-01-19  7:48 ` [Bug c/25805] [3.4/4.0 " rsandifo at gcc dot gnu dot org
2006-02-27 20:25 ` mmitchel at gcc dot gnu dot org
2006-03-11  3:19 ` mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).