[solved] optimization/8302: -fno-strict-aliasing was missing
Yaacov Akiba Slama
ya@slamail.org
Wed Oct 23 09:56:00 GMT 2002
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;
}
More information about the Gcc-bugs
mailing list