From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0EA323858D3C; Tue, 25 Apr 2023 07:15:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0EA323858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682406906; bh=nf6wNX897Kes4qcQy9C9TiuqhtQZG4Enjw+0bj1+bo4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ULWanHm5SW0cPa2vVhV8UG4zud3MaJlxNN3nEdGKKy3aGO9u6pEKt1qNMIRtrfYxy iz1KYBe32oG0CX537+PXc//MgA5AL8qSl9IRpn7xn+wx+hpGUAcYOyZXwzZ8JmYjQx gTnuoQKxuBKQFc6A+xrtwaR/nZVP4mINL8GERNJ4= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109609] [12/13/14 Regression] tail call for function even when passing a ptr which references a local array still Date: Tue, 25 Apr 2023 07:15:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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=3D109609 --- Comment #11 from Richard Biener --- (In reply to Richard Biener from comment #10) > On the first testcase reverting the offending rev. shows that it causes >=20 > [local count: 137085152]: > - MEM[(char *)&buf + 12B] =3D 0; > - _19 =3D *id_8(D); > - if (_19 !=3D 0) > + _18 =3D *id_7(D); > + if (_18 !=3D 0) >=20 > thus we DSE the store to the end. >=20 > The issue is that the fnspec we have for strncpy says the access size > is specified by argument 3 but what it specified there is the _maximum_ > size read, not the actual size. So instead of "1cO313" it should be > "1cO31 " ('1' is somewhat odd then, it says we copy 'src' to 'dst' > but we only say the 'dst' write covers arg 3 size - I guess that's OK > for points-to analysis, the additional zeros written do not have pointers, > but if we use it differently it might be a wrong spec?) >=20 > I'm scanning other builtins for similar issues. Note a different fix would be to re-interpret the case of reads and say the size is _up to_ the specified length, thus use ao_ref_init_from_ptr_and_range instead of _and_size. strncat, stpncpy, strncmp, strnlen, strndup are affected similarly. for functions like memchr I'm not sure if we can assume all 'n' bytes are read (thus if that would cause known overread -> undefined behavior). Honza? Any opinion? Fix for the testcase, but incomplete as noted above: diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 0e06fa5b2e0..133707c1617 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -11562,11 +11562,12 @@ builtin_fnspec (tree callee) case BUILT_IN_STPCPY_CHK: return ".cO 1 "; case BUILT_IN_STRNCPY: + case BUILT_IN_STRNCPY_CHK: + return "1cO31 "; case BUILT_IN_MEMCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_TM_MEMCPY: case BUILT_IN_TM_MEMMOVE: - case BUILT_IN_STRNCPY_CHK: case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMMOVE_CHK: return "1cO313";=