[Bug c++/105469] New: "execution reached an unreachable program point" with -flto

remi.coulom at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue May 3 19:58:19 GMT 2022


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

            Bug ID: 105469
           Summary: "execution reached an unreachable program point" with
                    -flto
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: remi.coulom at gmail dot com
  Target Milestone: ---

Created attachment 52926
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52926&action=edit
compressed preprocessed source file that produces the bug

Operating system and compiler versions:

Ubuntu 20.04: tested with g++ version 7.5.0, 8.4.0, 9.4.0, 10.3.0, 11.1.0, and
13.0 (compiled from git repository this week-end with default options). Also in
32-bit cygwin with 11.2.0. All produce the same problem.

Step to reproduce the problem:

The program works well when compiling without -flto:
$ g++ -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -O3 -fsanitize=unreachable -o repro repro.ii
$ ./repro
-> Yeah, no bug!

adding -flto makes it crash:
$ g++ -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -O3 -flto -fsanitize=unreachable -o repro
repro.ii
$ ./repro
-> repro.cpp:1345:24: runtime error: execution reached an unreachable program
point

I added some trace to the code, that shows a little more information. I tried
to reduce the size of the code as much pas possible, but it was very difficult
because many changes can make the problem appear or disappear. In particular,
not catching exceptions in main makes the bug disappear.

I searched the web for this error message, and found this interesting link:
https://deathandthepenguinblog.wordpress.com/2021/02/13/undefined-behaviour-and-nasal-demons-or-do-not-meddle-in-the-affairs-of-optimizers/
What is described there feels similar to what is happening to me. So I searched
hard for undefined behaviour in my code.

I humbly admit that this crash may very well be a bug in my code instead of a
bug in g++, but after several days of struggle, I still really can make no
sense of what is happening.

If g++ detected undefined behavior in my code and is using this to remove some
part of the code or perform optimizations, then I feel it should tell me. I
want to know, because undefined behavior is much more likely to be a bug that
needs fixing rather than a good optimization opportunity.


More information about the Gcc-bugs mailing list