This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] PR libstdc++/80285 optimize std::make_shared for -fno-rtti
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 16 May 2017 14:16:44 +0100
- Subject: Re: [PATCH] PR libstdc++/80285 optimize std::make_shared for -fno-rtti
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EAA695D688
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EAA695D688
- References: <20170511141910.GA28678@redhat.com>
On 11/05/17 15:19 +0100, Jonathan Wakely wrote:
std::make_shared didn't support embedding the object within the
shared_ptr bookkeeping structure when -fno-rtti was used. This was
because the trick I use for getting the address of the embedded
object relied on typeid, so without RTTI it just creating the object
separately on the heap.
This removes the alternative code path for -fno-rtti and simply forms
a fake std::type_info& reference using reinterpret_cast. This allows
us to embed the object and get its address without typeid, so we avoid
the second allocation even when -fno-rtti is used.
PR libstdc++/80285
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti): Define
function to get unique fake std::type_info reference.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Compare to
_S_ti() fake reference.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Share
single implementation with or without RTTI enable.
[!__cpp_rtti]: Pass fake reference to _M_get_deleter.
* testsuite/20_util/shared_ptr/creation/alloc.cc: Change expected
allocation and deallocation counts.
* testsuite/20_util/shared_ptr/creation/single_allocation.cc: New.
* testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc:
New.
Tested powerpc64le-linux, committed to trunk.
This fix is needed for gnu-versioned-namespace builds, because
std::type_info should not be declared inside the versioned namespace.
Tested x86_64-linux, comitted to trunk.
commit e14f89bd9e529b3343c0b8c5fce3377394f6cbc7
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue May 16 14:13:40 2017 +0100
Fix forward declaration of std::type_info for versioned-namespace
PR libstdc++/80285
* include/bits/shared_ptr_base.h [!__cpp_rtti] (type_info): Declare
outside versioned namespace.
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 6918579..b4a5edf 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -59,6 +59,10 @@
namespace std _GLIBCXX_VISIBILITY(default)
{
+#if !__cpp_rtti
+ class type_info;
+#endif
+
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#if _GLIBCXX_USE_DEPRECATED
@@ -68,10 +72,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#pragma GCC diagnostic pop
#endif
-#if !__cpp_rtti
- class type_info;
-#endif
-
/**
* @brief Exception possibly thrown by @c shared_ptr.
* @ingroup exceptions