From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 353073858CDB; Fri, 31 Mar 2023 12:43:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 353073858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680266624; bh=5GUFIO3pfD5rIMAX/ZWIcfWQn4QrSg7xBQws/hO8X5o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hdu7hhef9X0CKNGMsuLsa0scS8j9QUOq17xnVZrgCdeTOSQIdrqVx3zrEbV1R3Jhx dBnylOcPpPgGX4K0k9eUn9k3edmdxm4onugDen/9hAfVSbAT+e011gjpEAGZdaKfG2 CZXaXjt5/HL1l8ardurTLE2tOLajF5Tp4M0nw0Lc= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107087] [12/13 Regression] bits/stl_algobase.h:431: warning: 'void* __builtin_memcpy(void*, const void*, unsigned int)' reading between 8 and 2147483644 bytes from a region of size 4 [-Wstringop-overread] Date: Fri, 31 Mar 2023 12:43:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107087 --- Comment #10 from Jonathan Wakely --- I wonder if some other hints about properties of the empty rep would help codegen: --- a/libstdc++-v3/include/bits/cow_string.h +++ b/libstdc++-v3/include/bits/cow_string.h @@ -204,6 +204,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_is_leaked() const _GLIBCXX_NOEXCEPT { +#if _GLIBCXX_FULLY_DYNAMIC_STRING =3D=3D 0 && __OPTIMIZE__ + if (_S_empty_rep()._M_refcount !=3D 0) + __builtin_unreachable(); +#endif + #if defined(__GTHREADS) // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, // so we need to use an atomic load. However, _M_is_leaked @@ -218,6 +223,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_is_shared() const _GLIBCXX_NOEXCEPT { +#if _GLIBCXX_FULLY_DYNAMIC_STRING =3D=3D 0 && __OPTIMIZE__ + if (_S_empty_rep()._M_refcount !=3D 0) + __builtin_unreachable(); +#endif + #if defined(__GTHREADS) // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, // so we need to use an atomic load. Another thread can drop last @@ -907,17 +917,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: // Capacity: + /// Returns the number of characters in the string, not including a= ny /// null-termination. size_type size() const _GLIBCXX_NOEXCEPT - { return _M_rep()->_M_length; } + { +#if _GLIBCXX_FULLY_DYNAMIC_STRING =3D=3D 0 && __OPTIMIZE__ + if (_S_empty_rep()._M_length !=3D 0) + __builtin_unreachable(); +#endif + return _M_rep()->_M_length; + } /// Returns the number of characters in the string, not including a= ny /// null-termination. size_type length() const _GLIBCXX_NOEXCEPT - { return _M_rep()->_M_length; } + { return size(); } /// Returns the size() of the largest possible %string. size_type=