https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78558
Bug ID: 78558
Summary: Incorrect loop optimization leads to crash
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Anton.Grichina at harmonicinc dot com
Target Milestone: ---
Created attachment 40172
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40172&action=edit
main.cpp
GCC optimizes loop using SSE instructions (in this case "movdqa"), but for some
reason memory alignment is wrong and application crashes in run-time.
I attached the code. It crashes in "copy_stats" and "copy_stats1".
Compiled with: g++ -o main -O3 -std=c++11 main.cpp
(compiling with -fno-strict-aliasing -fwrapv and -Wall -Wextra does not change
behavior or show anything useful)
Target: x86_64-linux-gnu
I`ve ran it in gdb to see what happens:
(gdb) run
Starting program: /home/agrichin/test/align_bug/main
Program received signal SIGSEGV, Segmentation fault.
0x00000000004004e8 in main ()
In asm layout I see:
0x4004e8 <main+40> movdqa (%rax),%xmm0
And this is content of rax:
(gdb) info registers
rax 0x6010d8 6295768
Memory aligned to 8, not to 16.
This bug reproducible with O3 on GCC 5.4 . On GCC 4.8.4 it is not reproducible.
Workarounds to overcome this bug:
1. Remove/reorder fields in Session structure
2. Remove "copy_stats" function from source
3. Compile with O2
4. Use older compiler, it is not reproducible with 4.8.4