From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D5A7F3851C25; Wed, 30 Dec 2020 21:25:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5A7F3851C25 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, 30 Dec 2020 21:25:06 +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, 30 Dec 2020 21:25:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 --- Comment #4 from Martin Sebor --- (In reply to Romain Geissler from comment #2) > There seems to be a strange interaction between -Wsystem-headers and -g in > gcc 11 which I don't understand. Thanks for the -g hint; with it I can see it on my end as well. The differ= ence seems to be in how the inlining information is encoded with -g vs without.= =20 With -g, the algorithm that looks for the location into which the call to s.insert() has been inlined manages to uncover it. Without -g, the algorit= hm fails and falls back on the traditional approach that only considers macro expansion but not inlining. So without -g, the warning is not issued becau= se of a bug or limitation in the new algorithm. (The algorithm was introduced= in r11-6028 to enable -Wfree-nonheap-object and other similar middle-end warni= ngs for invalid uses of C++ standard library functions. The goal is to avoid issuing warnings for deliberate abuses by system headers, but we want to is= sue those for incidental misuses of system functions by user code.) (In reply to Romain Geissler from comment #3) > Why does having a function f2 affects warnings in function f1 ? Because s.insert() is a trivial wrapper around replace(), calls to it end up expanded inline into those to s._M_replace(). When there's just one caller= of s1.insert(), the latter is inlined into it as well. But with two or more callers, because _M_replace() is big, the inliner decides it's better not to expand it inline. That in turn prevents constant propagation from substitu= ting the constant array's address into the code, which then defeats the warning.= =20 The inlining limit is controlled by -finline-limit=3Dn so suitably increasi= ng it will trigger the warning.=