public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/6985: GCC-3.x incorrectly initializes local arrays
@ 2002-06-10 20:26 Andrew Pinski
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Pinski @ 2002-06-10 20:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR optimization/6985; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: lucho@haemimont.bg
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: optimization/6985: GCC-3.x incorrectly initializes local arrays
Date: Mon, 10 Jun 2002 21:22:47 -0400
This is not a bug but your code violates ISO C's aliasing rules
(C89, ANSI C).
To work around this use an union or use the option
`-fno-strict-aliasing'.
Thanks,
Andrew Pinski
On Monday, June 10, 2002, at 08:48 , lucho@haemimont.bg wrote:
> /*
> * GCC-3.1 bug
> * compile with -O2 to let the bug to appear.
> *
> * The test should output (and does so when compiled with -O1 or less):
> *
> * aaaaa
> * a=13
> *
> * but when compiled with -O2 or higher, instead it outputs:
> *
> * aaaaa
> * a=0
> *
> *
> * I've tested this on 2.95.2, 3.0, 3.0.4 and 3.1.
> * 2.95.2 doesn't have this bug and all 3.x have it.
> */
>
> unsigned a = 13, b = 17;
>
> int main()
> {
> unsigned char buf[18] = {0};
> *(unsigned short *)(buf + 12) = a;
> *(unsigned short *)(buf + 14) = b;
> printf("aaaaa\n");
> printf("a=%i\n", *(unsigned short *)(buf + 12));
> return 0;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
* optimization/6985: GCC-3.x incorrectly initializes local arrays
@ 2002-06-10 17:56 lucho
0 siblings, 0 replies; 2+ messages in thread
From: lucho @ 2002-06-10 17:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 6985
>Category: optimization
>Synopsis: GCC-3.x incorrectly initializes local arrays
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Jun 10 17:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Luchezar Belev
>Release: GCC-3.1
>Organization:
>Environment:
linux-2.4.18 pc-i686 glibc-2.1 gcc-3.1
>Description:
It seems that the compiler reorders the initialization-to-zero
with the following assignment operation so that the initialization comes last.
>How-To-Repeat:
/*
* GCC-3.1 bug
* compile with -O2 to let the bug to appear.
*
* The test should output (and does so when compiled with -O1 or less):
*
* aaaaa
* a=13
*
* but when compiled with -O2 or higher, instead it outputs:
*
* aaaaa
* a=0
*
*
* I've tested this on 2.95.2, 3.0, 3.0.4 and 3.1.
* 2.95.2 doesn't have this bug and all 3.x have it.
*/
unsigned a = 13, b = 17;
int main()
{
unsigned char buf[18] = {0};
*(unsigned short *)(buf + 12) = a;
*(unsigned short *)(buf + 14) = b;
printf("aaaaa\n");
printf("a=%i\n", *(unsigned short *)(buf + 12));
return 0;
}
>Fix:
To work around: make little changes to the source and the compiler won't confuse anymore.
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-06-11 3:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-10 20:26 optimization/6985: GCC-3.x incorrectly initializes local arrays Andrew Pinski
-- strict thread matches above, loose matches on Subject: below --
2002-06-10 17:56 lucho
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).