From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 82F033858299; Wed, 29 Nov 2023 18:24:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82F033858299 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701282290; bh=N/InRLybOHqztX4HZBIF6c8x1+cPPyG4K4Fy49KFD2I=; h=From:To:Subject:Date:From; b=SAH0ukpf4uk+xUc5LQRwUWV1LaYiPx878MCMPKzH3rz4FFfF3vlaB7fAO/8RfZJIM i6KK324ljxl6rrujFOjxHHgrjyWyWrr+7j0yjDmvVBv3MBJhCc+UK3g4a7DQsgLmjf C+RXmepG+OB19EgnwzugWy7r3tPNKkjiHcQ/oRuk= From: "sss@li-snyder.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112767] New: [14 regression] spurious -Waggressive-loop-optimizations Date: Wed, 29 Nov 2023 18:24:49 +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: sss@li-snyder.org 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=3D112767 Bug ID: 112767 Summary: [14 regression] spurious -Waggressive-loop-optimizations Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sss@li-snyder.org Target Milestone: --- With a recent checkout of gcc14 (20231129), on a x86_64-pc-linux-gnu host, the following source gives a seemingly bogus -Waggressive-loop-optimizations warning with -O3: -------------------------------------------------------------- double reg_dict[32]; void foo(int); void initialize() { int i=3D8; for (int phi=3D0; phi<8; ++phi) { reg_dict[i]=3D0; int sn =3D 0; if (i < 16) sn =3D 20; foo(sn); ++i; } } -------------------------------------------------------------- $ g++ -c -O3 x.cc x.cc: In function =E2=80=98void initialize()=E2=80=99: x.cc:9:16: warning: iteration 16 invokes undefined behavior [-Waggressive-loop-optimizations] 9 | reg_dict[i]=3D0; | ~~~~~~~~~~~^~ x.cc:8:22: note: within this loop 8 | for (int phi=3D0; phi<8; ++phi) { | ~~~^~ This is a confusing warning, as the containing loop is executed only 8 time= s. Exactly which undefined behavior is meant is also not spelled out. >From the context, i'd guess it to be an out-of-bounds array write, but that's a false positive. The warning happens with -O3 but not with lower optimization levels. It also does not occur with gcc 13.2.1 20230728.=