This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: optimization/6985: GCC-3.x incorrectly initializes local arrays
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 11 Jun 2002 03:26:02 -0000
- Subject: Re: optimization/6985: GCC-3.x incorrectly initializes local arrays
- Reply-to: Andrew Pinski <pinskia at physics dot uc dot edu>
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;
> }