From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 000133855011; Mon, 19 Jul 2021 10:25:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 000133855011 From: "pnarsing at mathworks dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101508] New: Possible undefined behaviour in cpp program using "unsigned" type starting from GCC 9 Date: Mon, 19 Jul 2021 10:25:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 10.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pnarsing at mathworks 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 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: Mon, 19 Jul 2021 10:25:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101508 Bug ID: 101508 Summary: Possible undefined behaviour in cpp program using "unsigned" type starting from GCC 9 Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pnarsing at mathworks dot com Target Milestone: --- Hi Team, I'm observing an optimization issue while compiling with GCC 10.3 . On investigating figured that issue is reproducible in GCC 9 as well . This can be reproduced by simple test code mentioned below : ------------------------------------------------------ using int_type =3D unsigned int; // works without "unsigned" int_type constexpr start{0}; // works if >=3D 1 int_type constexpr stop{3}; // works if <=3D 2 int_type constexpr mult{2}; // works if !=3D 2 int main() { int result =3D 0; for(int_type aa =3D start; aa < stop; ++aa) { int_type const bb =3D aa * mult; // works if volatile if (aa > bb) { return 99; } ++result; } return result; // should be =3D=3D stop } ---------------------------------------------------------------- This code snippet returns 99 instead of 3 . You can check the following link to see the issue reproducibility: https://godbolt.org/z/zd79PPKfn Modifying compiler option to -O1 and -Og avoids the issue.=