From patchwork Tue May 16 13:16:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 763002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wRyfM27bPz9s3w for ; Tue, 16 May 2017 23:17:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QvAkPP98"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=ANBvsd/9APtYTvwUuGKhPCsSK6+D7+ +0QQ59fRvwouP3103NZErJlQpFxpeOh+kRVFa57DZ4/q9ZZOLHhgef7FhmUe/8Vx JJq+rQujd7bT4WzyszisIeLyfgVsbpfu+cwslAcgAZuJkqkhmW8OVNYqZCY40FCi +Y8KnqlCOqUVk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=sK8ooXBMk6JWyc3l/nX4pZFEeTk=; b=QvAk PP98q6usSFlTigmDLmGeFGlqhwK388kzsS+l/b00gTA5T/gNnnsGvhAJt8tPTDmR +FOVAEvEUjWi1ef2FHCyc72WsQGtykxeQAz6pxPfM984til28wN/0F2d0KJkOi0p TYVYhIbnXDBd4aSS7RCxpLyHDTRXs39e/SpRsSI= Received: (qmail 76571 invoked by alias); 16 May 2017 13:16:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 76542 invoked by uid 89); 16 May 2017 13:16:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=bookkeeping, Hx-languages-length:2522 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 May 2017 13:16:49 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAA695D688; Tue, 16 May 2017 13:16:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EAA695D688 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@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EAA695D688 Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D8747E5B1; Tue, 16 May 2017 13:16:45 +0000 (UTC) Date: Tue, 16 May 2017 14:16:44 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] PR libstdc++/80285 optimize std::make_shared for -fno-rtti Message-ID: <20170516131644.GR5109@redhat.com> References: <20170511141910.GA28678@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170511141910.GA28678@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.8.0 (2017-02-23) 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 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