This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

target/9797: ARM structure initialization bug


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]