This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[solved] optimization/8302: -fno-strict-aliasing was missing
- From: Yaacov Akiba Slama <ya at slamail dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: Noam Lampert <noaml at mainsoft dot com>
- Date: Wed, 23 Oct 2002 17:10:26 +0200
- Subject: [solved] optimization/8302: -fno-strict-aliasing was missing
- Reply-to: Yaacov Akiba Slama <ya at slamail dot org>
Hello,
The following code aborts if "-fstrict-aliasing" is set (and this seems
to be implied by "-O2") with gcc-3.2 (and newer versions also).
This seems to be the right behavior.
This solves the bug 8302.
// This sample crashes with -fstrict-aliasing (or -O2) but returns 0
with -fno-strict-aliasing
unsigned char *p;
unsigned char * aux(unsigned char **pBuffer) {
return *pBuffer + 1;
}
int
test(int a2, unsigned char a3)
{
unsigned char *Buffer;
unsigned char * t1;
unsigned char * t2;
p = Buffer = (unsigned char *) malloc(30);
aux(&Buffer);
*(*(( int * * )&Buffer))++ = a2;
t1 = Buffer;
*Buffer = a3;
t2 = Buffer; // t2 == t1 when OK.
return t1-t2; //0 if OK.
}
int main()
{
int d;
d = test(0x41414141,'a');
if (d != 0)
abort();
return 0;
}