This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[solved] optimization/8302: -fno-strict-aliasing was missing


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;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]