From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 007023850431; Tue, 3 May 2022 19:58:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 007023850431 From: "remi.coulom at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105469] New: "execution reached an unreachable program point" with -flto Date: Tue, 03 May 2022 19:58:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: remi.coulom at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2022 19:58:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105469 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=3D52926&action=3Dedit 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). Als= o 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=3Dunreachable -o repro re= pro.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=3Dunreachable -o re= pro repro.ii $ ./repro -> repro.cpp:1345:24: runtime error: execution reached an unreachable progr= am point I added some trace to the code, that shows a little more information. I tri= ed to reduce the size of the code as much pas possible, but it was very diffic= ult because many changes can make the problem appear or disappear. In particula= r, 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 sear= ched 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 s= ome 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 th= at needs fixing rather than a good optimization opportunity.=