From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3C9E2385840C; Sat, 19 Mar 2022 17:07:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C9E2385840C From: "andres at anarazel dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/104986] New: [12 Regression] bogus writing 1 byte into a region of size 0 with -fwrapv and -O2 -fpeel-loops Date: Sat, 19 Mar 2022 17:07:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andres at anarazel dot de 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: Sat, 19 Mar 2022 17:07:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104986 Bug ID: 104986 Summary: [12 Regression] bogus writing 1 byte into a region of size 0 with -fwrapv and -O2 -fpeel-loops Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: andres at anarazel dot de Target Milestone: --- Hi, recently started seeing bogus warnings using gcc 12 to build postgres. I reduced the problem using cvise with some manual cleanups / improvements afterwards - certainly doesn't quite make sense anymore, but afaics shows a problem. Originally I hit this with -O3, but found that -O2 -fpeel-loops is sufficie= nt to trigger the problem. repro: https://godbolt.org/z/ejK9h6von code: struct inet_struct { char family; char ipaddr[16]; }; void inetnot(struct inet_struct *dst1, struct inet_struct *dst2, struct inet_str= uct *src) { int nb =3D src->family ? 4 : 6; char *psrc =3D src->ipaddr; char *pdst =3D dst1 ? dst1->ipaddr : dst2->ipaddr; while (nb-- > 0) pdst[nb] =3D psrc[nb]; } gcc-12 -fwrapv -O2 -fpeel-loops -c network2.i network2.i: In function =E2=80=98inetnot=E2=80=99: network2.i:12:14: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 12 | pdst[nb] =3D psrc[nb]; | ~~~~~~~~~^~~~~~~~~~ network2.i:3:8: note: at offset -1 into destination object =E2=80=98ipaddr= =E2=80=99 of size 16 3 | char ipaddr[16]; | ^~~~~~ network2.i:3:8: note: at offset -1 into destination object =E2=80=98ipaddr= =E2=80=99 of size 16 which afaics is bogus, because the loop terminates before reaching offset -= 1, the condition is > 0, not >=3D 0. So the post decrement can't lead to -1 be= ing reached. version: gcc version 12.0.1 20220314 (experimental) [master r12-7638-g823b3b79cd2] (Debian 12-20220313-1)=20 Regards, Andres=