[Bug c++/64724] C++ loop with -O3 optimization produces segfault while -O2 is fine

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 22 07:38:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64724

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The fact that the CPU handles it has nothing to do whether it is undefined
behavior or not.
And i?86/x86_64 hw is actually hybrid in the alignment case, some instructions
don't require strict alignment, while others do.
You can try -fsanitize=undefined and it will diagnose this at runtime:
$ g++ -fsanitize=undefined -o pr64724 pr64724.ii 
$ ./pr64724
a.cc:21:19: runtime error: load of misaligned address 0x0000025bd011 for type
'double', which requires 8 byte alignment
0x0000025bd011: note: pointer points here
 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
00 00  00 00 00 00 00
              ^ 
a.cc:21:20: runtime error: store to misaligned address 0x0000025bd5a1 for type
'double', which requires 8 byte alignment
0x0000025bd5a1: note: pointer points here
 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
00 00  00 00 00 00 00
              ^



More information about the Gcc-bugs mailing list