From: Andrew Haley <aph@redhat.com>
To: Fuxin Zhang <fxzhang@ict.ac.cn>
Cc: MAKE FUN PRANK CALLS <linux-mips@linux-mips.org>, gcc@gcc.gnu.org
Subject: GCC -O2 failure for mipsel
Date: Thu, 1 May 2003 09:27:44 +0100 [thread overview]
Message-ID: <16048.55936.346808.522687@cuddles.redhat.com> (raw)
In-Reply-To: <3EB0B329.9030603@ict.ac.cn>
Fuxin Zhang writes:
> Hello,
> I've met a case where mipsel-linux-gcc -O2 fails,for both
> 2.96 and the fresh new 3.2.3. Maybe someone can tell me
> what's wrong.
Your code is incorrect.
> I've reduced the problem to the test case below,compile it
> with mipsel-linux-gcc -O2(FROM H.J.Lu's redhat miniport,all version,
> and 3.2.3 is tested too)
>
>
> #define PUT_CODE(x,code) ((x)->code = (code))
> union test_union {
> struct test *t;
> int a;
> };
>
> struct test {
> unsigned short code;
> union test_union u[1];
> };
>
> char memory[2000];
>
> struct test *test_alloc(int code)
> {
> struct test *t;
> int length=sizeof(struct test);
>
> t = (struct test*)memory;
> length = (sizeof(struct test) - sizeof(union test_union)-1)/sizeof(int);
> for (;length>=0;length--)
This is the errant line:
> ((int*)t)[length] = 0;
You have declared t as a pointer to struct test, but you're using it
as a pointer to int. If you look at Pointers, Section 6.2.2.3 in ISO
9899-1990 you'll see that this results in undefined behaviour.
-fno-strict-aliasing should generate the code you want, but it's
better to fix your source. If you want to use a pointer as a
different type, put it in a union.
Andrew.
next prev parent reply other threads:[~2003-05-01 8:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-01 5:39 GCC -O2 failure for mipsel Fuxin Zhang
2003-05-01 8:27 ` Andrew Haley [this message]
2003-05-01 8:41 ` Fuxin Zhang
2003-05-01 8:46 ` Andrew Haley
2003-05-01 8:50 ` Greg Lindahl
2003-05-09 2:05 ` Problem of cross-mipsel-compiler GLIBC-2.3.X smills_ho
2003-05-09 2:05 ` smills_ho
2003-05-09 7:21 ` Eric Christopher
2003-05-09 7:29 ` Kumba
2003-05-09 8:15 ` smills_ho
2003-05-09 8:15 ` smills_ho
2003-05-09 8:30 ` Kumba
2003-05-09 9:40 ` smills_ho
2003-05-09 9:40 ` smills_ho
2003-05-09 11:20 ` Guido Guenther
2003-05-09 8:10 ` smills_ho
2003-05-09 8:10 ` smills_ho
2003-05-09 17:13 ` Eric Christopher
2003-05-01 11:00 ` GCC -O2 failure for mipsel Andrew Pinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16048.55936.346808.522687@cuddles.redhat.com \
--to=aph@redhat.com \
--cc=fxzhang@ict.ac.cn \
--cc=gcc@gcc.gnu.org \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox