Bug 9797 - [ARM] miscompiles C99-style struct initializers
Summary: [ARM] miscompiles C99-style struct initializers
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 3.4.0
Assignee: Daniel Jacobowitz
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-02-22 00:26 UTC by Daniel Jacobowitz
Modified: 2004-07-17 02:39 UTC (History)
2 users (show)

See Also:
Host: i386-pc-linux-gnu
Target: arm-elf
Build: i386-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Jacobowitz 2003-02-22 00:26:00 UTC
	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;
}
Comment 1 Daniel Jacobowitz 2003-02-22 00:26:00 UTC
Fix:
	Initializing members explicitly (above) works fine.
Comment 2 Daniel Jacobowitz 2003-03-12 16:45:29 UTC
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
 

Comment 3 Daniel Jacobowitz 2003-03-12 16:52:01 UTC
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
 
Comment 4 Daniel Jacobowitz 2003-03-12 17:17:37 UTC
Responsible-Changed-From-To: unassigned->drow
Responsible-Changed-Why: Patch checked in for 3.3, 3.4.  See PR c/9853 for more.
Comment 5 Daniel Jacobowitz 2003-03-12 17:17:37 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Done.
Comment 6 Daniel Jacobowitz 2003-03-24 04:02:24 UTC
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