public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* target/9797: ARM structure initialization bug
@ 2003-02-22 0:26 drow
0 siblings, 0 replies; only message in thread
From: drow @ 2003-02-22 0:26 UTC (permalink / raw)
To: gcc-gnats
>Number: 9797
>Category: target
>Synopsis: ARM miscompiles C99-style struct initializers
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Feb 22 00:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Daniel Jacobowitz
>Release: 3.2 and 3.4 20030221
>Organization:
MontaVista Software, Inc.
>Environment:
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: arm-elf
>Description:
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.
>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.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-02-22 0:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-22 0:26 target/9797: ARM structure initialization bug drow
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).