From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6FEBB395C419; Fri, 13 May 2022 17:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FEBB395C419 From: "greenfoo at u92 dot eu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105598] New: Flag -O2 causes code to misbehave Date: Fri, 13 May 2022 17:49:33 +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: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: greenfoo at u92 dot eu 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: Fri, 13 May 2022 17:49:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105598 Bug ID: 105598 Summary: Flag -O2 causes code to misbehave Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: greenfoo at u92 dot eu Target Milestone: --- Created attachment 52974 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52974&action=3Dedit Small example that triggers the issue when using -O2 in gcc 11.x I found a situation where the "-O2" flag was causing trouble at least in x86_64. The attached file "example.c" code is expected to print "4" when compiled a= nd executed, but it would print "2" when compiled with "-02". This happens with gcc 11.1, 11.2 and 11.3, but works correctly with gcc 10.3 and 12.1: > $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:10.3 gcc= -o example example.c && ./example > 4=20 > $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.1 gcc= -o example example.c && ./example > 2 > $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.2 gcc= -o example example.c && ./example > 2 > $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.3 gcc= -o example example.c && ./example > 2 > $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:12.1 gcc= -o example example.c && ./example > 4 I don't know if this deserves further investigation. If not, please feel fr= ee to discard this bug report. Thanks!=