In: extern void abort (void); struct A { int i; int j; int k; int l; }; struct B { struct A a; int r[1]; }; struct C { struct A a; int r[0]; }; struct D { struct A a; int r[]; }; void foo (struct A *x) { if (x->i != 0 || x->j != 5 || x->k != 0 || x->l != 0) abort (); } int main () { struct B b = { .a.j = 5 }; struct C c = { .a.j = 5 }; struct D d = { .a.j = 5 }; foo (&b.a); foo (&c.a); foo (&d.a); return 0; } GCC 4.0/HEAD only zero initialize a.i, a.k and a.l for the b variable, not for c nor d, while 3.4.x and older initialized them for all 3 variables. This causes miscompilation of glibc by GCC 4.0+.
Confirmed, patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-06/msg01103.html>.
Subject: Bug 22043 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: jakub@gcc.gnu.org 2005-06-14 17:08:00 Modified files: gcc : ChangeLog gimplify.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20050613-1.c Log message: PR tree-optimization/22043 * gimplify.c (gimplify_init_constructor): If num_type_elements < 0 for a constant-sized object, set cleared as well. * gcc.c-torture/execute/20050613-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.287&r2=2.7592.2.288 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.113.2.5&r2=2.113.2.6 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.238&r2=1.5084.2.239 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050613-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
Fixed on the 4.0 branch at least.
Jakub, do you plan to fix this bug on mainline as well??
http://gcc.gnu.org/ml/gcc-patches/2005-06/msg01203.html contains the lastest patch.
Subject: Bug 22043 CVSROOT: /cvs/gcc Module name: gcc Changes by: jakub@gcc.gnu.org 2005-08-23 07:28:26 Modified files: gcc : ChangeLog expr.c gimplify.c tree-sra.c tree.h gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20050613-1.c Log message: PR tree-optimization/22043 * tree.h (count_type_elements): Add ALLOW_FLEXARR argument. * expr.c (count_type_elements): Add ALLOW_FLEXARR argument. If ALLOW_FLEXARR, handle types ending with flexible array member. Pass false as second argument to recursive count_type_elements calls. (categorize_ctor_elements_1, mostly_zeros_p): Pass false as second argument to count_type_elements call. * tree-sra.c (decide_block_copy): Likewise. * gimplify.c (gimplify_init_constructor): If num_type_elements < 0 for a constant-sized object, set cleared as well. Pass true as second argument to count_type_elements call. * gcc.c-torture/execute/20050613-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9803&r2=2.9804 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.808&r2=1.809 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.147&r2=2.148 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-sra.c.diff?cvsroot=gcc&r1=2.70&r2=2.71 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.h.diff?cvsroot=gcc&r1=1.753&r2=1.754 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5951&r2=1.5952 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050613-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
Fixed.