From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B7BB8385B50C; Thu, 9 Feb 2023 07:44:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7BB8385B50C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675928666; bh=a/md9e3erP/QgrIOK8Q6H8widsEFi9mHWoqphowkVuw=; h=From:To:Subject:Date:From; b=CNY5Vra6nKrmjfpfRY2KLPRw/fgp0TQyqOdAkU57AyI5jYEEFVUDi5OM/E9qOVv+S 2qnfwydipHSx10PsD2SzZn2PmaMUOnZ+Z/0v0GZv2XcOfBJf+POR1IPOFjNADMtyuq TA4wCugAln4Qy9/ETpA970K8wBHMI+uVpEM07yzI= From: "njs at pobox dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108737] New: Apparent miscompile of infinite loop on gcc trunk in cddce2 pass Date: Thu, 09 Feb 2023 07:44:26 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: njs at pobox 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108737 Bug ID: 108737 Summary: Apparent miscompile of infinite loop on gcc trunk in cddce2 pass Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: njs at pobox dot com Target Milestone: --- There's a meme going around about strange compilation outputs caused infinite-loop-related UB, and while discussing it a friend stumbled on this weird behavior: https://godbolt.org/z/qfj1jabMW C++ code is: extern int foo(); void blah() { int x =3D foo(); while (1) { if(x) foo(); } } When compiled with whatever "gcc trunk" means on compiler explorer, and with -O3 (but not -O2), as C++ (but not C), then gcc reduces this to a single ca= ll to `foo()` followed by an empty infinite loop: blah(): sub rsp, 8 call foo() .L2: jmp .L2 As far as I can tell, there's no UB here -- 'foo' being extern means it mig= ht do anything, and infinite loops with side-effects are well-defined in C++. = So this seems like a straight-up optimizer bug? Poking through the pass analysis in CE, it looks like the output of "unroll= jam (tree)" is still correct, but then the output of the next pass "cddce2 (tre= e)" has deleted everything. Somehow it concludes that the hoisted `if` can be eliminated? idgi.=