Compile the testcase below with no options; it will abort. Then, for the really weird part, add only -fstrict-aliasing. The generated code works. Similarly, -O2 works, -O2 -fno-strict-aliasing aborts. Release: 3.2 and 3.4 20030221 Environment: host: i386-pc-linux-gnu build: i386-pc-linux-gnu target: arm-elf How-To-Repeat: extern void abort(); struct huh { int cleanmarker_size; }; struct huh *c; typedef unsigned int uint32_t; typedef unsigned short uint16_t; #define JFFS2_MAGIC_BITMASK 0x1985 #define JFFS2_NODETYPE_CLEANMARKER 0x2003 #define cpu_to_je16(x) ((jint16_t){x}) #define cpu_to_je32(x) ((jint32_t){x}) typedef struct { uint32_t v32; } __attribute__((packed)) jint32_t; typedef struct { uint16_t v16; } __attribute__((packed)) jint16_t; struct jffs2_unknown_node { /* All start like this */ jint16_t magic; jint16_t nodetype; jint32_t totlen; /* So we can skip over nodes we don't grok */ jint32_t hdr_crc; } __attribute__((packed)); void bad() { struct jffs2_unknown_node marker = { .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK), .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER), .totlen = cpu_to_je32(c->cleanmarker_size) }; /* printf("marker magic %x nodetype %x totlen %x\n",marker.magic,marker.nodetype,marker.totlen); */ if (marker.magic.v16 == marker.nodetype.v16) abort(); } int good() { struct jffs2_unknown_node marker; marker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); marker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER); marker.totlen = cpu_to_je32(c->cleanmarker_size); /* printf("marker magic %x nodetype %x totlen %x\n",marker.magic,marker.nodetype,marker.totlen); */ if (marker.magic.v16 == marker.nodetype.v16) abort(); } int main() { struct huh huh; c = &huh; good(); bad(); return 0; }
Fix: Initializing members explicitly (above) works fine.
From: drow@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: target/9797 Date: 12 Mar 2003 16:45:29 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: drow@gcc.gnu.org 2003-03-12 16:45:28 Modified files: gcc : ChangeLog stmt.c Log message: Fix PR target/9797 and PR c/9853. * stmt.c (expand_decl_init): Call push_temp_slots () and pop_temp_slots (). Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.17046&r2=1.17047 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&r1=1.292&r2=1.293
From: drow@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: target/9797 Date: 12 Mar 2003 16:52:01 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: drow@gcc.gnu.org 2003-03-12 16:52:01 Modified files: gcc : ChangeLog stmt.c Log message: Fix PR target/9797 and PR c/9853. * stmt.c (expand_decl_init): Call push_temp_slots () and pop_temp_slots (). 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.289&r2=1.16114.2.290 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.276.2.3&r2=1.276.2.4
Responsible-Changed-From-To: unassigned->drow Responsible-Changed-Why: Patch checked in for 3.3, 3.4. See PR c/9853 for more.
State-Changed-From-To: open->closed State-Changed-Why: Done.
From: drow@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: target/9797 Date: 24 Mar 2003 04:02:24 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_2-branch Changes by: drow@gcc.gnu.org 2003-03-24 04:02:23 Modified files: gcc : ChangeLog stmt.c Log message: Fix PR target/9797. * stmt.c (expand_decl_init): Call push_temp_slots () and pop_temp_slots (). 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.275&r2=1.13152.2.657.2.276 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.248.2.4.4.3&r2=1.248.2.4.4.4