From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 45A46393C84B; Wed, 13 Jan 2021 19:30:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45A46393C84B From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98465] Bogus warning stringop-overread wuth -std=gnu++20 -O2 and std::string::insert Date: Wed, 13 Jan 2021 19:30:57 +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: 11.0 X-Bugzilla-Keywords: alias, diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 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 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: Wed, 13 Jan 2021 19:30:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 --- Comment #14 from Martin Sebor --- Smallish test case independent of libstdc++ that reproduces both the false positive (due to the missing aliasing constraint) and its absence (due to a bug/limitation in tree_inlined_location). With -Wsystem-headers GCC issues= two instances of the false positive, one for f() and the other for g(): $ cat pr98465.C && gcc -O2 -S -Wall -Wextra pr98465.C # 1 "pr98465.h" 1 3 typedef __SIZE_TYPE__ size_type; typedef __UINTPTR_TYPE__ uintptr_t; struct S { char *dta; size_type cap, siz; bool _M_disjunct (const char *s) const { return ((uintptr_t)s < (uintptr_t)dta || (uintptr_t)dta + siz < (uintptr_t)s); } void assign (const char *s, size_type n) { assign2 (s, n); } void assign2 (const char *s, size_type n) { _M_replace (0, siz, s, n); } void _M_replace (size_type pos, size_type len1, const char* s, const size_type len2) { const size_type old_size =3D siz; const size_type new_size =3D old_size + len2 - len1; if (new_size <=3D cap) { char *p =3D dta + pos; const size_type how_much =3D old_size - pos - len1; if (_M_disjunct (s)) { if (how_much && len1 !=3D len2) __builtin_memmove (p + len2, p + len1, how_much); if (len2) __builtin_memcpy (p, s, len2); } else { if (len2 && len2 <=3D len1) __builtin_memmove (p, s, len2); if (how_much && len1 !=3D len2) __builtin_memmove (p + len2, p + len1, how_much); if (len2 > len1) { if (s + len2 <=3D p + len1) __builtin_memmove (p, s, len2); else if (s >=3D p + len1) __builtin_memcpy (p, s + len2 - len1, len2); else { const size_type nleft =3D (p + len1) - s; __builtin_memmove (p, s, nleft); __builtin_memcpy (p + nleft, p + len2, len2 - nleft); } } } } } }; # 1 "pr98465.C" const char a[] =3D { 1, 2 }; void f (S &s) { s.assign (a, 2); // no warning } const char b[] =3D { 2, 3 }; void g (S &s) { s.assign2 (b, 2); // bogus -Wstringop-overread } In file included from pr98465.C:1: In member function =E2=80=98void S::_M_replace(size_type, size_type, const = char*, size_type)=E2=80=99, inlined from =E2=80=98void S::assign2(const char*, size_type)=E2=80=99 = at pr98465.h:19:16, inlined from =E2=80=98void g(S&)=E2=80=99 at pr98465.C:13:13: pr98465.h:50:24: warning: =E2=80=98void* __builtin_memcpy(void*, const void= *, long unsigned int)=E2=80=99 reading 2 bytes from a region of size 1 [-Wstringop-= overread] In file included from pr98465.C:1: pr98465.C: In function =E2=80=98void g(S&)=E2=80=99: pr98465.C:9:12: note: at offset [1, 2] into source object =E2=80=98b=E2=80= =99 of size 2 9 |=20 | ^=