From patchwork Tue Jan 29 00:47:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1032411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494875-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yXc33dTa"; dkim-atps=neutral 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 43pSXC6BJ4z9sCX for ; Tue, 29 Jan 2019 11:47:53 +1100 (AEDT) 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:mime-version:content-type; q=dns; s= default; b=nr0tIk/8X5mvi0MfruvpHMlwwHSiyluM30EKMgOYmNQn2nlqlVCm1 0ALl+gHmmW6kM8/G6sRMGP/3N67YPHDwpPUgwscKPltrPaFTdHTMrq0nZqBku9gA vlm/VSuJJyL8Z5zayqGxbLNhj29wrslNsd7Tdo6ceoOa9WfA9UtP1k= 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:mime-version:content-type; s= default; bh=JAMTghw8Mkxl+PXXqzZ/8f+UJAc=; b=yXc33dTaDw0UVNXAR7jQ OjL5UutZgwVTUXZKK9Jha0h5xqv1qhyajR/x/2fDMEJDK6geNI0JofE8osfPn84z F/BCHxCPmBs7/NRtH9p6atVM2S0XUbEvjwCZ18ANkJjsKoo8QfXQu9hPiHZifa4B emurK+GTeEse9dRUe4vGE6U= Received: (qmail 86650 invoked by alias); 29 Jan 2019 00:47:37 -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 86623 invoked by uid 89); 29 Jan 2019 00:47:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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, 29 Jan 2019 00:47:32 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2988C04B2F9; Tue, 29 Jan 2019 00:47:31 +0000 (UTC) Received: from localhost (unknown [10.33.36.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F05D690FE; Tue, 29 Jan 2019 00:47:31 +0000 (UTC) Date: Tue, 29 Jan 2019 00:47:30 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Ensure pool resources always use normal mode vector Message-ID: <20190129004730.GA27249@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.10.1 (2018-07-13) The __pool_resource::_M_unpooled member was declared with type std::vector, which means that the type depends on whether debug mode is active or not. Because the non-inline definitions in src/c++17/memory_resource.cc are never compiled with debug mode, the type declared in the header doesn't match the type in the library definitions, leading to undefined behaviour. The solution is to ensure the header always uses the non-debug vector, even when debug mode is active. To make this easier a new alias template is defined: _GLIBCXX_STD_C::pmr::vector. * include/std/memory_resource (__pool_resource::_M_unpooled): Use normal mode vector, even for debug mode. * include/std/vector [_GLIBCXX_DEBUG] (_GLIBCXX_STD_C::pmr::vector): Define alias template for normal mode vector. Tested x86_64-linux, committed to trunk. commit 88ea7aa5bcdfc98ead7f9ab5b01c8c58d482799c Author: Jonathan Wakely Date: Mon Jan 28 23:37:27 2019 +0000 Ensure pool resources always use normal mode vector The __pool_resource::_M_unpooled member was declared with type std::vector, which means that the type depends on whether debug mode is active or not. Because the non-inline definitions in src/c++17/memory_resource.cc are never compiled with debug mode, the type declared in the header doesn't match the type in the library definitions, leading to undefined behaviour. The solution is to ensure the header always uses the non-debug vector, even when debug mode is active. To make this easier a new alias template is defined: _GLIBCXX_STD_C::pmr::vector. * include/std/memory_resource (__pool_resource::_M_unpooled): Use normal mode vector, even for debug mode. * include/std/vector [_GLIBCXX_DEBUG] (_GLIBCXX_STD_C::pmr::vector): Define alias template for normal mode vector. diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource index 5573494b01f..93b2ebd9759 100644 --- a/libstdc++-v3/include/std/memory_resource +++ b/libstdc++-v3/include/std/memory_resource @@ -354,7 +354,7 @@ namespace pmr struct _BigBlock; // Collection of blocks too big for any pool, sorted by address. // This also stores the only copy of the upstream memory resource pointer. - pmr::vector<_BigBlock> _M_unpooled; + _GLIBCXX_STD_C::pmr::vector<_BigBlock> _M_unpooled; const int _M_npools; }; diff --git a/libstdc++-v3/include/std/vector b/libstdc++-v3/include/std/vector index 2c90765b058..e5e13ab3ef7 100644 --- a/libstdc++-v3/include/std/vector +++ b/libstdc++-v3/include/std/vector @@ -89,6 +89,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>; } // namespace pmr +# ifdef _GLIBCXX_DEBUG + namespace _GLIBCXX_STD_C::pmr { + template + using vector + = _GLIBCXX_STD_C::vector<_Tp, std::pmr::polymorphic_allocator<_Tp>>; + } // namespace _GLIBCXX_STD_C::pmr +# endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17