- Subject: Re: optimization/7427: gcc-3.1.1 -O2 problem for checksum calculation (powerpc)
- From: Andrew Pinski <pinskia@physics.uc.edu>
- To: Makoto Fujiwara <makoto@ki.nu>
- Date: Sun, 28 Jul 2002 21:38:09 -0400
- Message-Id: <D64A4716-A293-11D6-8DC8-000393122612@physics.uc.edu>
- In-Reply-To: <yfmwurffi7g.wl@u.ki.nu>
- Cc: gcc-gnats@gcc.gnu.org
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 <stdio.h>
struct buf {
int data;
};
union buf1 {
struct buf buf1;
unsigned short m[sizeof(struct buf)/sizeof(short)];
};
bug(m)
struct buf *m;
{
int sum = 0;
union buf1 w;
bzero(&w.buf1, sizeof tmp);
w.buf1 = m->data;
sum += w.m[0];
sum += w.m[1];
printf("sum = 0x%x\n", sum);
return 0;
}
main()
{
struct buf m;
m.data = 0x12345678;
bug(&m);
}
Thanks,
Andrew Pinski