Bug 8032 - [3.2/3.3 regression] GCC >= 3.0 incorrectly initializes static structs in the presence of flexible arrays
[3.2/3.3 regression] GCC >= 3.0 incorrectly initializes static structs in the...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c
3.1
: P3 normal
: ---
Assigned To: Eric Botcazou
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-09-25 03:56 UTC by wolfgang.thaller
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
PR8032.c (143 bytes, application/octet-stream)
2003-05-21 15:16 UTC, wolfgang.thaller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wolfgang.thaller 2002-09-25 03:56:00 UTC
GCC incorrectly initializes a global struct if its initializer contains an initializer for a zero-length array. The struct is set to all-zeroes instead of the proper values for the other fields.

Release:
3.0.2 and Apple-GCC version 1161, based on gcc version 3.1 20020420

Environment:
Observed on MacOS X 10.2 with Apple's GCC 3.1, and with GCC 3.0.2 cross-compiling to AVR

How-To-Repeat:
// compile this and look at the assembly:
typedef struct x_
{
    int a;
    int b;
    int z[0]
} X;

const X xxx = { b: 40, z:{} };
Comment 1 wolfgang.thaller 2002-09-25 03:56:00 UTC
Fix:
Omit the (useless) initializer z:{} or give the array z a non-zero size.
Comment 2 Volker Reichelt 2002-11-24 15:37:36 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
    
    This also affects 3.0.x, 3.2-branch and mainlineon
    i686-pc-linux-gnu. With gcc 2.95.3 the code compiles fine.
    I added an updated testcase as attachment.
Comment 3 Eric Botcazou 2002-11-25 07:04:29 UTC
Responsible-Changed-From-To: unassigned->ebotcazou
Responsible-Changed-Why: Working on a fix.
Comment 4 Eric Botcazou 2003-01-09 01:39:05 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed.
Comment 5 Eric Botcazou 2003-01-09 09:18:53 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8032
Date: 9 Jan 2003 09:18:53 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	ebotcazou@gcc.gnu.org	2003-01-09 01:18:53
 
 Modified files:
 	gcc            : ChangeLog c-typeck.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20030109-1.c 
 
 Log message:
 	PR c/8032
 	* c-typeck.c (process_init_element) [RECORD_TYPE]: For
 	an empty element, do not advance the pointer to unfilled
 	fields if there are pending initializers.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.16302&r2=1.16303
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.214&r2=1.215
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2329&r2=1.2330
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030109-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
 

Comment 6 Eric Botcazou 2003-01-09 09:27:03 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8032
Date: 9 Jan 2003 09:27:03 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	ebotcazou@gcc.gnu.org	2003-01-09 01:27:02
 
 Modified files:
 	gcc            : ChangeLog c-typeck.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20030109-1.c 
 
 Log message:
 	PR c/8032
 	* c-typeck.c (process_init_element) [RECORD_TYPE]: For
 	an empty element, do not advance the pointer to unfilled
 	fields if there are pending initializers.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.49&r2=1.16114.2.50
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.213&r2=1.213.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.15&r2=1.2261.2.16
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030109-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
 

Comment 7 Eric Botcazou 2003-01-09 09:33:04 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c/8032
Date: 9 Jan 2003 09:33:04 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	ebotcazou@gcc.gnu.org	2003-01-09 01:33:04
 
 Modified files:
 	gcc            : ChangeLog c-typeck.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20030109-1.c 
 
 Log message:
 	PR c/8032
 	* c-typeck.c (process_init_element) [RECORD_TYPE]: For
 	an empty element, do not advance the pointer to unfilled
 	fields if there are pending initializers.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.172&r2=1.13152.2.657.2.173
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.180.2.2.4.3&r2=1.180.2.2.4.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.77&r2=1.1672.2.166.2.78
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030109-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.4.1