https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86108
Bug ID: 86108 Summary: crash during unwinding with -O2 Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: guillaume at morinfr dot org Target Milestone: --- Created attachment 44259 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44259&action=edit reproducer I have a program that crashes very reliably after an exception is thrown. The code source is attached. It's not as small as I would like but trying to simplify it significantly makes the crash go away. It crashes very early in main() though. Compile with "-std=c++17 -O2" on a GNU/Linux amd64 box, then run "-f RYz1q" to reproduce. Starting program: ./repro -f RYz1q Catchpoint 1 (exception thrown), 0x00007ffff7aeaa4d in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (gdb) bt #0 0x00007ffff7aeaa4d in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #1 0x0000000000406371 in RR::RR (this=<optimized out>, _readSize=<optimized out>, maker=<optimized out>, headerCopy=<optimized out>, start=..., end=..., _writer=0x0) at repro.cc:1370 #2 0x0000000000402353 in main () at repro.cc:1550 #3 0x00007ffff71bf2e1 in __libc_start_main (main=0x401bc0 <main>, argc=3, argv=0x7fffffffe018, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe008) at ../csu/libc-start.c:291 #4 0x0000000000402a1a in _start () at repro.cc:1332 (gdb) c Continuing. Program received signal SIGSEGV, Segmentation fault. 0x00007ffff754cdaf in _Unwind_Resume () from /lib/x86_64-linux-gnu/libgcc_s.so.1 (gdb) bt #0 0x00007ffff754cdaf in _Unwind_Resume () from /lib/x86_64-linux-gnu/libgcc_s.so.1 #1 0x000000000040185c in main (argc=<optimized out>, argv=<optimized out>) at repro.cc:1623 #2 0x00007ffff71bf2e1 in __libc_start_main (main=0x401bc0 <main>, argc=3, argv=0x7fffffffe018, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe008) at ../csu/libc-start.c:291 #3 0x0000000000402a1a in _start () at repro.cc:1332 It seems to be a missing null pointer check: ==22653== Command: ./repro -f RYz1q ==22653== ==22653== Invalid read of size 8 ==22653== at 0x54CDDAF: _Unwind_Resume (in /lib/x86_64-linux-gnu/libgcc_s.so.1) ==22653== by 0x40185B: main.cold.131 (repro.cc:1543) ==22653== by 0x56F52E0: (below main) (libc-start.c:291) ==22653== Address 0x40 is not stack'd, malloc'd or (recently) free'd Using g++ 7.x, -O1 or adding "-fno-reorder-blocks-and-partition" makes the code work (the exception is caught and the program prints "CAUGHT EXCEPTION - IT WORKED").