From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EC1583857828; Wed, 6 Jan 2021 22:38:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC1583857828 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, 06 Jan 2021 22:38:02 +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: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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, 06 Jan 2021 22:38:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 --- Comment #5 from Martin Sebor --- Comparing the code emitted by GCC 10 and the current trunk shows that the former doesn't inline std::string::replace() regardless of the inlining lim= it.=20 The translation unit obtained with the former shows declarations of explicit instantiations of basic_string: $ g++-10 -O2 -E -Wall -g t.C | grep template | grep basic_string template friend class basic_stringbuf; extern template class basic_string; extern template class basic_string; Current trunk doesn't declare them which is what allows std::string::replac= e to be inlined. Removing the declaration of the explicit instantiation from the translation unit lets GCC 10 inline string::replace but the warning is not issued becau= se the location of the call is in a system header. But enabling warning for t= hose via -Wsystem-headers shows the warning even with GCC 10: $ g++-10 -E pr98465.C | sed "/extern template class basic_string/d" > pr98465.ii && g++-10 -O2 -S -Wall -Wsystem-headers pr98465.ii In file included from /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/string:56, from pr98465.C:1: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_st= ring.tcc: In function =E2=80=98void f(std::string&)=E2=80=99: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_st= ring.tcc:456:20: warning: offset =E2=80=982=E2=80=99 outside bounds of constant string [-War= ray-bounds] 456 | this->_S_copy(__p, __s + __len2 - __len1, __len2); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pr98465.C:3:12: note: =E2=80=98constantString=E2=80=99 declared here 3 | const char constantString[] =3D {42, 53}; | ^~~~~~~~~~~~~~ In file included from /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/string:40, from pr98465.C:1: In static member function =E2=80=98static std::char_traits::char_type* std::char_traits::copy(std::char_traits::char_type*, const char_type*, std::size_t)=E2=80=99, inlined from =E2=80=98void f(std::string&)=E2=80=99 at /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_st= ring.h:351:21: /build/gcc-10-branch/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_tra= its.h:395:49: warning: =E2=80=98void* __builtin_memcpy(void*, const void*, long unsigned = int)=E2=80=99 reading 2 bytes from a region of size 0 [-Wstringop-overflow=3D] 395 | return static_cast(__builtin_memcpy(__s1, __s2, __n)); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~=