From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 19BB439D00DD; Thu, 4 Feb 2021 15:25:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19BB439D00DD From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98465] [11 Regression] Bogus -Wstringop-overread with -std=gnu++20 -O2 and std::string::insert Date: Thu, 04 Feb 2021 15:25:52 +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, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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: Thu, 04 Feb 2021 15:25:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 --- Comment #20 from Jakub Jelinek --- What I meant this as was a variant to Martin's the https://gcc.gnu.org/pipermail/gcc/2021-January/234641.html idea. Or perhaps add an attribute on _M_dataplus._M_p member that would tell the compiler about this special behavior (the containing class owns the pointer, and it can point either to a heap allocated memory that is owned by the cla= ss, or can point into a local buffer within the same object as the pointer, and let have the new *disjunct builtin be for now the only consumer of that attribute. It could then handle both the case where the _M_replace __s poi= nts to a variable that clearly can't be owned by the string object, but perhaps also when passed pointers to other string objects (it would see, the other pointer is loaded from _M_dataplus._M_p that has this new magic attribute, = so the containing object owns that pointer, and if points-to analysis finds ou= t it can't alias with the other owning object, it could fold the disjunct builti= n to false too. The problem is that the else part in if (_M_disjunct(...)) { ... } else { .= .. } is large, complicated and prone to these false positive warnings, so it is desirable to fold _M_disjunct to compile time false as much as possible. I have really no idea how often in real-world code people actually pass par= ts of the destination string as the source (i.e. how often _M_disjunct returns true). Maybe if it is very rare another alternative would be avoid inlining that (either by moving it into a separate method with noinline, cold attributes = or perhaps to a helper function in libstdc++ library.=