From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 42B0F3858C3A; Thu, 9 Dec 2021 19:46:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42B0F3858C3A From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103637] New: [12 Regression] missing warning writing past the end of one of multiple elements of the same array Date: Thu, 09 Dec 2021 19:46:05 +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: msebor at gcc dot gnu.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 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: Thu, 09 Dec 2021 19:46:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103637 Bug ID: 103637 Summary: [12 Regression] missing warning writing past the end of one of multiple elements of the same array Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The fix for pr103215 is too conservative and causes false negatives for past the end accesses to array elements like in gcc.dg/warn-strnlen-no-nul.c. A simple test case that shows the problem is below. The dump shows that both strcpy calls are plainly out of bounds and both could and should be diagnos= ed. $ cat y.c && gcc -O2 -S -Wall -fdump-tree-optimized=3D/dev/stdout y.c extern int x; extern char b[5][7]; void f (const char *s) { __builtin_strncpy (b[3], s, 9); // warning (good) } void g (int i, const char *s) { char *d =3D i ? b[3] : b[4]; __builtin_strncpy (d, s, 9); // warning in GCC 11, missing in 12 } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1980, cgraph_uid=3D1, symbol_o= rder=3D0) void f (const char * s) { [local count: 1073741824]: __builtin_strncpy (&b[3], s_2(D), 9); [tail call] return; } y.c: In function =E2=80=98f=E2=80=99: y.c:7:3: warning: =E2=80=98__builtin_strncpy=E2=80=99 writing 9 bytes into = a region of size 7 overflows the destination [-Wstringop-overflow=3D] 7 | __builtin_strncpy (b[3], s, 9); // warning (good) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ y.c:3:13: note: at offset 21 into destination object =E2=80=98b=E2=80=99 of= size 28 3 | extern char b[5][7]; | ^ ;; Function g (g, funcdef_no=3D1, decl_uid=3D1984, cgraph_uid=3D2, symbol_o= rder=3D1) Removing basic block 3 void g (int i, const char * s) { char * iftmp.0_1; [local count: 1073741824]: if (i_2(D) !=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 536870912]: [local count: 1073741824]: # iftmp.0_1 =3D PHI <&b[3](2), &b[4](3)> __builtin_strncpy (iftmp.0_1, s_4(D), 9); [tail call] return; }=