This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/80285 optimize std::make_shared for -fno-rtti


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]