Closed anchor76 closed 7 months ago
Hello, i found a very strange behavior with arithmetic shift if -O2 or -O3 is used. Sample code:
`#include
typedef unsigned int u32; const int _count = 8;
int main(int argc, char argv[]) { u32 _len = _count sizeof(u32); u32 _data = (u32)malloc(_len); memset(_data, 0, _len);
printf("before shift\n"); for (u32 _i = 0; _i < _count; _i++) { printf("i:%d data:%08x\n", _i, _data[_i]); } // do shift for (u32 _i = 0; _i < _count; _i++) { _data[_i] <<= 1; } printf("after shift\n"); for (u32 _i = 0; _i < _count; _i++) { printf("i:%d data:%08x\n", _i, _data[_i]); } free(_data); return 0;
}`
The expected output is zero for all elements, but with -O2 -O3 i see random numbers.
Is it possible to switch off optimization features one by one? Which optimization should i turn off? Any help would be appreciated.
(Note: source code, compiled binaries, and asm outputs attached.)
gcc_test.zip
confirmed. workaround: -fno-peephole2
-fno-peephole2
fix is live in ~1 hour from now, if test builds succeed.
thanks for reporting!
Hello, i found a very strange behavior with arithmetic shift if -O2 or -O3 is used. Sample code:
`#include
include
include
typedef unsigned int u32; const int _count = 8;
int main(int argc, char argv[]) { u32 _len = _count sizeof(u32); u32 _data = (u32)malloc(_len); memset(_data, 0, _len);
}`
The expected output is zero for all elements, but with -O2 -O3 i see random numbers.
Is it possible to switch off optimization features one by one? Which optimization should i turn off? Any help would be appreciated.
(Note: source code, compiled binaries, and asm outputs attached.)
gcc_test.zip