From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6B89E388E82A; Thu, 4 Feb 2021 14:03:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B89E388E82A 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 14:03:51 +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: cc 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 14:03:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98465 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |redi at gcc dot gnu.org --- Comment #18 from Jakub Jelinek --- So, if adding some attribute or whatever to std::string etc. members doesn't look doable/desirable, can't we e.g. implement _M_disjunct using some built= in that would allow gcc to optimize it better (and later fold it into how it is implemented now)? It is currently: // True if _Rep and source do not overlap. bool _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT { return (less()(__s, _M_data()) || less()(_M_data() + this->size(), __s)); } and when std::basic_string uses the normal allocators, _M_dataplus._M_p can point either to some heap allocated object or to _M_local_buf inside of *this. So, can some template stuff ensure that the builtin would be only used when using a standard allocator and not something that can say have a global: char buffer[0x10000000]; and allocate from that? Pass to the builtin all the needed info (e.g. return __builtin_whatever_disjunct (_M_data(), this->size(), _M_local_data(= ), __s); ) and let it use points to info to fold it to false if the last pointer can= 't point to either _M_local_data() pointed object or heap memory, otherwise fo= ld into pointer sized casts of the pointers and integral comparisons as before= ?=