From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1548 invoked by alias); 29 Jul 2002 01:46:04 -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 1525 invoked by uid 71); 29 Jul 2002 01:46:03 -0000 Date: Sun, 28 Jul 2002 18:46:00 -0000 Message-ID: <20020729014603.1522.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Andrew Pinski Subject: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) Reply-To: Andrew Pinski X-SW-Source: 2002-07/txt/msg00753.txt.bz2 List-Id: The following reply was made to PR optimization/7427; it has been noted by GNATS. From: Andrew Pinski To: Makoto Fujiwara Cc: gcc-gnats@gcc.gnu.org Subject: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc) Date: Sun, 28 Jul 2002 21:38:09 -0400 C aliasing rules say that variables with two different types do not belong to the same alias set (except for char* and void*). The correct way to fix the problem is using an union: #include struct buf { =A0 =A0 =A0 =A0 int data; }; union buf1 { struct buf buf1; unsigned short m[sizeof(struct buf)/sizeof(short)]; }; bug(m) =A0 =A0 =A0 =A0 struct buf *m; { =A0 =A0 =A0 =A0 int sum =3D 0; =A0 =A0 =A0 =A0 union buf1 w; =A0 =A0 =A0 =A0 bzero(&w.buf1, sizeof tmp); =A0 =A0 =A0 =A0 w.buf1 =3D m->data; =A0 =A0 =A0 =A0 sum +=3D w.m[0]; =A0 =A0 =A0 =A0 sum +=3D w.m[1]; =A0 =A0 =A0 =A0 printf("sum =3D 0x%x\n", sum); =A0 =A0 =A0 =A0 return 0; } main() { =A0 =A0 =A0 =A0 struct buf m; =A0 =A0 =A0 =A0 m.data =3D 0x12345678; =A0 =A0 =A0 =A0 bug(&m); } Thanks, Andrew Pinski