[{"id":3687014,"web_url":"http://patchwork.ozlabs.org/comment/3687014/","msgid":"<CAKvuMXD+Hju_=+cOPedAkkS8Gjq4nt+Ka_+cqDZ86jcBP-h2UQ@mail.gmail.com>","list_archive_url":null,"date":"2026-05-06T12:02:38","subject":"Re: [PATCH v2 2/3] libstdc++: Simplify std::shared_ptr internals","submitter":{"id":90409,"url":"http://patchwork.ozlabs.org/api/people/90409/","name":"Tomasz Kamiński","email":"tkaminsk@redhat.com"},"content":"On Wed, May 6, 2026 at 12:14 PM Jonathan Wakely <jwakely@redhat.com> wrote:\n\n> Now that we don't use the EBO we can flatten the class layout by\n> removing some _Impl classes.\n>\n> libstdc++-v3/ChangeLog:\n>\n>         * include/bits/out_ptr.h (out_ptr_t::_Impl::~_Impl): Adjust\n>         access to shared_ptr internals.\n>         * include/bits/shared_ptr_base.h (_Sp_counted_deleter): Remove\n>         _Impl class and replace _M_impl with the data members it\n>         contained.\n>         (_Sp_counted_ptr_inplace): Likewise.\n> ---\n>\n> v2: Use the attribute on the _M_del and _M_alloc members.\n>\nLGTM. I see now why you want [[no_unique_address(cond)]], because\nwith that we could simply have _M_alloc member of type _Alloc.\n\n>\n> Tested x86_64-linux.\n>\n>  libstdc++-v3/include/bits/out_ptr.h         |  2 +-\n>  libstdc++-v3/include/bits/shared_ptr_base.h | 60 ++++++---------------\n>  2 files changed, 18 insertions(+), 44 deletions(-)\n>\n> diff --git a/libstdc++-v3/include/bits/out_ptr.h\n> b/libstdc++-v3/include/bits/out_ptr.h\n> index cc5a8a3adacb..f5fdc6cf910f 100644\n> --- a/libstdc++-v3/include/bits/out_ptr.h\n> +++ b/libstdc++-v3/include/bits/out_ptr.h\n> @@ -257,7 +257,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>             auto& __pi = _M_smart._M_refcount._M_pi;\n>\n>             if (_Sp __ptr = _M_smart.get())\n> -             static_cast<_Scd*>(__pi)->_M_impl._M_ptr = __ptr;\n> +             static_cast<_Scd*>(__pi)->_M_ptr = __ptr;\n>             else // Destroy the control block manually without invoking\n> deleter.\n>               std::__exchange(__pi, nullptr)->_M_destroy();\n>           }\n> diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h\n> b/libstdc++-v3/include/bits/shared_ptr_base.h\n> index 3ab73f6e4a0d..01fd57180ecc 100644\n> --- a/libstdc++-v3/include/bits/shared_ptr_base.h\n> +++ b/libstdc++-v3/include/bits/shared_ptr_base.h\n> @@ -547,32 +547,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>    template<typename _Ptr, typename _Deleter, typename _Alloc,\n> _Lock_policy _Lp>\n>      class _Sp_counted_deleter final : public _Sp_counted_base<_Lp>\n>      {\n> -      class _Impl\n> -      {\n> -       [[__no_unique_address__]] _Sp_ebo_helper<_Deleter> _M_d;\n> -       [[__no_unique_address__]] _Sp_ebo_helper<_Alloc>   _M_a;\n> -\n> -      public:\n> -       _Impl(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept\n> -       : _M_d{std::move(__d)}, _M_a{__a}, _M_ptr(__p)\n> -       { }\n> -\n> -       _Deleter& _M_del() noexcept { return _M_d._M_obj; }\n> -       _Alloc& _M_alloc() noexcept { return _M_a._M_obj; }\n> -\n> -       _Ptr _M_ptr;\n> -      };\n> -\n>      public:\n>        using __allocator_type = __alloc_rebind<_Alloc,\n> _Sp_counted_deleter>;\n>\n>        // __d(__p) must not throw.\n>        _Sp_counted_deleter(_Ptr __p, _Deleter __d) noexcept\n> -      : _M_impl(__p, std::move(__d), _Alloc()) { }\n> +      : _M_del{std::move(__d)}, _M_alloc{}, _M_ptr(__p) { }\n>\n>        // __d(__p) must not throw.\n>        _Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a)\n> noexcept\n> -      : _M_impl(__p, std::move(__d), __a) { }\n> +      : _M_del{std::move(__d)}, _M_alloc{__a}, _M_ptr(__p) { }\n>\n>  #pragma GCC diagnostic push // PR tree-optimization/122197\n>  #pragma GCC diagnostic ignored \"-Wfree-nonheap-object\"\n> @@ -582,12 +566,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>\n>        virtual void\n>        _M_dispose() noexcept\n> -      { _M_impl._M_del()(_M_impl._M_ptr); }\n> +      { _M_del._M_obj(_M_ptr); }\n>\n>        virtual void\n>        _M_destroy() noexcept\n>        {\n> -       __allocator_type __a(_M_impl._M_alloc());\n> +       __allocator_type __a(_M_alloc._M_obj);\n>         __allocated_ptr<__allocator_type> __guard_ptr{ __a, this };\n>         this->~_Sp_counted_deleter();\n>        }\n> @@ -598,19 +582,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>  #if __cpp_rtti\n>         // _GLIBCXX_RESOLVE_LIB_DEFECTS\n>         // 2400. shared_ptr's get_deleter() should use addressof()\n> -        return __ti == typeid(_Deleter)\n> -         ? std::__addressof(_M_impl._M_del())\n> -         : nullptr;\n> -#else\n> -        return nullptr;\n> +       if (__ti == typeid(_Deleter))\n> +         return std::__addressof(_M_del._M_obj);\n>  #endif\n> +       return nullptr;\n>        }\n>\n>      private:\n>  #ifdef __glibcxx_out_ptr\n>        template<typename, typename, typename...> friend class out_ptr_t;\n>  #endif\n> -      _Impl _M_impl;\n> +\n> +      [[__no_unique_address__]] _Sp_ebo_helper<_Deleter> _M_del;\n> +      [[__no_unique_address__]] _Sp_ebo_helper<_Alloc>   _M_alloc;\n> +      _Ptr _M_ptr;\n>      };\n>\n>    // helpers for make_shared / allocate_shared\n> @@ -640,25 +625,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>    template<typename _Tp, typename _Alloc, _Lock_policy _Lp>\n>      class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp>\n>      {\n> -      class _Impl\n> -      {\n> -       [[__no_unique_address__]] _Sp_ebo_helper<_Alloc> _M_a;\n> -\n> -      public:\n> -       explicit _Impl(_Alloc __a) noexcept : _M_a{std::move(__a)} { }\n> -\n> -       _Alloc& _M_alloc() noexcept { return _M_a._M_obj; }\n> -\n> -       __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage;\n> -      };\n> -\n>      public:\n>        using __allocator_type = __alloc_rebind<_Alloc,\n> _Sp_counted_ptr_inplace>;\n>\n>        // Alloc parameter is not a reference so doesn't alias anything in\n> __args\n>        template<typename... _Args>\n>         _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)\n> -       : _M_impl(__a)\n> +       : _M_alloc{__a}\n>         {\n>           // _GLIBCXX_RESOLVE_LIB_DEFECTS\n>           // 2070.  allocate_shared should use\n> allocator_traits<A>::construct\n> @@ -674,14 +647,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>        virtual void\n>        _M_dispose() noexcept\n>        {\n> -       allocator_traits<_Alloc>::destroy(_M_impl._M_alloc(), _M_ptr());\n> +       allocator_traits<_Alloc>::destroy(_M_alloc._M_obj, _M_ptr());\n>        }\n>\n>        // Override because the allocator needs to know the dynamic type\n>        virtual void\n>        _M_destroy() noexcept\n>        {\n> -       __allocator_type __a(_M_impl._M_alloc());\n> +       __allocator_type __a(_M_alloc._M_obj);\n>         __allocated_ptr<__allocator_type> __guard_ptr{ __a, this };\n>         this->~_Sp_counted_ptr_inplace();\n>        }\n> @@ -711,9 +684,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n>        }\n>\n>        __remove_cv_t<_Tp>*\n> -      _M_ptr() noexcept { return _M_impl._M_storage._M_ptr(); }\n> +      _M_ptr() noexcept { return _M_storage._M_ptr(); }\n>\n> -      _Impl _M_impl;\n> +      [[__no_unique_address__]] _Sp_ebo_helper<_Alloc> _M_alloc;\n> +      __gnu_cxx::__aligned_buffer<__remove_cv_t<_Tp>> _M_storage;\n>      };\n>\n>  #ifdef __glibcxx_smart_ptr_for_overwrite // C++ >= 20 && HOSTED\n> --\n> 2.54.0\n>\n>","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=czhr3fLT;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=czhr3fLT","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","sourceware.org; arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9YvG0ldJz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 22:03:52 +1000 (AEST)","from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id 700824BA79A1\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 12:03:50 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 1DF034BA7987\n for <gcc-patches@gcc.gnu.org>; Wed,  6 May 2026 12:02:54 +0000 (GMT)","from mail-yw1-f197.google.com (mail-yw1-f197.google.com\n [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-455-pyY19iKbNUmK5i46gmbibQ-1; Wed, 06 May 2026 08:02:52 -0400","by mail-yw1-f197.google.com with SMTP id\n 00721157ae682-799001d7289so50029867b3.1\n for <gcc-patches@gcc.gnu.org>; Wed, 06 May 2026 05:02:52 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 700824BA79A1","OpenDKIM Filter v2.11.0 sourceware.org 1DF034BA7987"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 1DF034BA7987","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 1DF034BA7987","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778068974; cv=none;\n b=NZeCKD5rZK6Q4iIl8Q+VPpI5AyAGAAk5x/Zmgk8TC1VDjaCOzURLDMW9nASoc6IwitenKbMdXJ/6FdVsAbszQgJLXtaMjld7/HWkou1KI8M1o6zsmCzE36n26bwXqTU26vCA9983PHHtrH/+Oey+SskfnPkrps6GDhnJHeY3bqI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778068974; c=relaxed/simple;\n bh=dqpayccImx2opQ3QLzwC/Dkuhe0HHfSspU/uklhpwRM=;\n h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;\n b=UFG/b+YIMDx8tJWl76SRGoAj0SQhTVm1UxcgDiHEFyEfzNrwwrzXacoyU/Lj9keOZI2B+hxSWsCCLhXp4lBoP2agsDifBx/Bi1Exqsra/HhF9T2AhJBAsTofewOIYQGCGVVnHMEAujDbxuGtt8n8dPEaxQejXTbCmHfoxpJbDWw=","ARC-Authentication-Results":"i=1; sourceware.org;\n dkim=pass (1024-bit key, unprotected)\n header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=czhr3fLT","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1778068973;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=3dOLxXTtKjWyUuQ6UsQe6RsaWhg/R0Cv0kgstwgV6aw=;\n b=czhr3fLTb8bjQS9g3BPBG4kO/4rc0UL1o3oe2PYn/BTwbiqxJDrLK/v6MeLw/vl+E313d6\n ACGi7xC7nPb9tMQUnYz4mUN61ZwjZlr9sk13IpPhPZaZgKhu6LKFi7+iyZspg0nl1XKhKu\n N+Vh8pCWYS/85v2PQnR3pKjoWVoMddY=","X-MC-Unique":"pyY19iKbNUmK5i46gmbibQ-1","X-Mimecast-MFC-AGG-ID":"pyY19iKbNUmK5i46gmbibQ_1778068971","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778068971; x=1778673771;\n h=cc:to:subject:message-id:date:from:in-reply-to:references\n :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=3dOLxXTtKjWyUuQ6UsQe6RsaWhg/R0Cv0kgstwgV6aw=;\n b=ekU8KHjqa42c6DoyqW9UmpQRnsJt6kWNkz7MgYsihTxEoD3+/NVGn8+mTUpukOD5IO\n RK25pg3c6JvgFqpoXr4gXFbW6fuYyyy/Bjq6t4OwoodUwz9+zfvh5wyy7nKCAg+5oqv1\n 3qZTvztFDUfZoUCS+uLXxjqL2yVkBPw1K8HsFxlfz5JDTMAZlCJ8iXa03+Ha9lhTFe66\n AKW1B4UvDUaEgZWdT7NWud54J0rXtZP3eNCA1e+MOI7ura+2snkkV0JfTVV+3BeBot97\n TCePTiIQkYbfLJrw0mx44SOxVIUpwf/VpH0QYLFEhakbjbk9AGPA3nrpFm3/mw8xgXZX\n orag==","X-Gm-Message-State":"AOJu0Yw2Ji1O76waQZE1w/Gy9nYBV1sannDpJ9k1IXEstCpKhiHty11i\n 7P2fMdjtTobKX+GVismK+7I/1yAhEuPqOqLrLK0lZEkogfO8Wr0AQODWWIL2CzFB7e+vKXLO6ZU\n b3FCcUljMNKhYaK5IrJuXSjI2fqEIUjRmv7CdlQZOlvNCFuXSeHhTEB8iG4dYQ23rH15UdBAObf\n IGvXxUweTz7CLXN4TflB1u7lHghGAj8G/VSA==","X-Gm-Gg":"AeBDietnbttyVb8nYWLhkUZj7jron+5G5vSWUBGyp9/y3Y5FBkg6m6chjnOQbyMt/Oh\n zGj/bC9UXh69NVwQuvjIRJUfgVvK8jhSQxWS7PSM27QjFW2v6nvc82nRF8E5gbAkvFAIfVvyft3\n zb0LUV5+Al+EOgpfaWJ68dRXwv25bMLj1JidgYMLPdYHVZO9MYHjtMsTa92V0uceRhRGO554PPp\n s+Bmn0KSpcbusub5Ct80VQk9E/BEPs7NGM5N1HADo5cy3OyO4yRMb9pUY8hT0pNey4Di5EyjBDQ\n /jE=","X-Received":["by 2002:a05:690c:f06:b0:7bb:712:a74f with SMTP id\n 00721157ae682-7bdf5dd244dmr36195167b3.17.1778068971237;\n Wed, 06 May 2026 05:02:51 -0700 (PDT)","by 2002:a05:690c:f06:b0:7bb:712:a74f with SMTP id\n 00721157ae682-7bdf5dd244dmr36194597b3.17.1778068970439; Wed, 06 May 2026\n 05:02:50 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260506085339.325517-1-jwakely@redhat.com>\n <20260506085339.325517-2-jwakely@redhat.com>","In-Reply-To":"<20260506085339.325517-2-jwakely@redhat.com>","From":"Tomasz Kaminski <tkaminsk@redhat.com>","Date":"Wed, 6 May 2026 14:02:38 +0200","X-Gm-Features":"AVHnY4L-F2ZJvDWX6XWB9Y-7ErIU_-WQKDzdYIVKNlW8uannWPzy1jgdkVi70uY","Message-ID":"\n <CAKvuMXD+Hju_=+cOPedAkkS8Gjq4nt+Ka_+cqDZ86jcBP-h2UQ@mail.gmail.com>","Subject":"Re: [PATCH v2 2/3] libstdc++: Simplify std::shared_ptr internals","To":"Jonathan Wakely <jwakely@redhat.com>","Cc":"gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"wzrPIM-wpzx1fhicy7w6kPX-G9PDBq0zBMf40XvczY8_1778068971","X-Mimecast-Originator":"redhat.com","Content-Type":"multipart/alternative; boundary=\"0000000000005ea82e065124f1be\"","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]