From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0010C385E82A; Sat, 9 Mar 2024 09:52:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0010C385E82A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709977952; bh=E+eUdVQQ7/77gcF/0j4D+EG2CpKhU3oXQZoeUS99lVI=; h=From:To:Subject:Date:From; b=KuKb4ziJGh7P4e973zjsok/Eje3QgQsyGsX29XOtM2Fr4kIQdse9UUzCI9awLPz0p tUlWnolLlbcpVe2SeI/LPu/HO8yNCWa2n3VOKyjrWrFRaqrHxkhHn1kZELYYfLNKyp azW2wHO1Ux9C0Jk7svE9BdSAcf1wxKjlJPEcteZk= From: "jlame646 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114290] New: GCC output incorrect output with -O2 Date: Sat, 09 Mar 2024 09:52:30 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jlame646 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 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=3D114290 Bug ID: 114290 Summary: GCC output incorrect output with -O2 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlame646 at gmail dot com Target Milestone: --- The following program gives wrong output `0` with `-O2` for input `2`. When `f(1,1)` is commented out(or removed) it produces correct output. https://godbolt.org/z/3rxah7Grx ``` #include #include struct Node { int x; }; Node f(int A, int B) { if (A < 0) return {0}; return {A / B + (A % B !=3D 0)}; } Node g(int C, int D) { if (C > 0) return {0}; return {C / D + (C % D !=3D 0)}; } int main() { int n; std::cin >> n; f(1, 1); //commenting this line fixes the issue Node t =3D g(-1, n); std::cout << t.x; }=20 ```=