https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114290
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 <cstdio> #include <iostream> struct Node { int x; }; Node f(int A, int B) { if (A < 0) return {0}; return {A / B + (A % B != 0)}; } Node g(int C, int D) { if (C > 0) return {0}; return {C / D + (C % D != 0)}; } int main() { int n; std::cin >> n; f(1, 1); //commenting this line fixes the issue Node t = g(-1, n); std::cout << t.x; } ```