From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22500 invoked by alias); 11 Jun 2002 03:26:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 22468 invoked by uid 71); 11 Jun 2002 03:26:03 -0000 Date: Mon, 10 Jun 2002 20:26:00 -0000 Message-ID: <20020611032602.22467.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Andrew Pinski Subject: Re: optimization/6985: GCC-3.x incorrectly initializes local arrays Reply-To: Andrew Pinski X-SW-Source: 2002-06/txt/msg00234.txt.bz2 List-Id: The following reply was made to PR optimization/6985; it has been noted by GNATS. From: Andrew Pinski 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; > }