From patchwork Fri Mar 8 20:16:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 226211 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]) by ozlabs.org (Postfix) with SMTP id 40E822C039E for ; Sat, 9 Mar 2013 07:17:21 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1363378642; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=wACqK68T/sHYyrh2GlnVPG4jTGA=; b=jY3S1ZzTxzLVAtz eFM0l21qWDR/dDEtyh1wxQHOrYvqhBAjfj4M1QBEcbsS6m9Y5rhuKpkuTShnH1M+ jSy2ebMDWHl8FYff66xHlSwGgk48KrEE/OC6E9QcLK94xeFPtnjsVnCxU9M9Y0hV WDIc0btsfdCHghMXY3Y76g46ha08= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=RJUA3aRtxlhISmWd6skKXNa2pCVBZ80FENEiqpc6qlbeorTC7n3mv2RW0Aq6jy 7Se9usQPgoS+l6l73p2a1hEgln6VRcZ18yfeIh3Fg11aVnHpxQDB5YGH/Q3i3yri 58JKYavTQccTRx+R5d65URNyBAmhWtmimBX8AkAZsMYJQ=; Received: (qmail 3022 invoked by alias); 8 Mar 2013 20:17:07 -0000 Received: (qmail 2999 invoked by uid 22791); 8 Mar 2013 20:17:04 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-we0-f179.google.com (HELO mail-we0-f179.google.com) (74.125.82.179) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Mar 2013 20:16:31 +0000 Received: by mail-we0-f179.google.com with SMTP id p43so1527181wea.10 for ; Fri, 08 Mar 2013 12:16:29 -0800 (PST) X-Received: by 10.194.103.72 with SMTP id fu8mr6505165wjb.42.1362773789636; Fri, 08 Mar 2013 12:16:29 -0800 (PST) Received: from localhost.localdomain (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by mx.google.com with ESMTPS id n2sm567500wiy.6.2013.03.08.12.16.27 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Mar 2013 12:16:28 -0800 (PST) Message-ID: <513A471B.3070500@gmail.com> Date: Fri, 08 Mar 2013 21:16:27 +0100 From: =?ISO-8859-1?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120829 Thunderbird/15.0 MIME-Version: 1.0 To: Jonathan Wakely CC: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: Fix vector C++11 allocator bug References: <51390699.9040904@gmail.com> In-Reply-To: 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 On 03/07/2013 11:46 PM, Jonathan Wakely wrote: > As expected it works for vector/swap.cc too. So we definitely need the > bug fix to std::vector::operator= and the testsuite changes to add > elements, but I think I'd prefer to just re-swap the containers in the > non-propagating case. This is indeed better so I applied the patch as you proposed. 2013-03-08 François Dumont * include/bits/vector.tcc (vector<>operator=(const vector<>&): Reset pointers after deallocation when memory can be reused. * testsuite/23_containers/vector/allocator/minimal.cc: Insert elements to really challenge C++11 allocator integration. * testsuite/23_containers/vector/allocator/copy.cc: Likewise. * testsuite/23_containers/vector/allocator/copy_assign.cc: Likewise. * testsuite/23_containers/vector/allocator/move_assign.cc: Likewise. * testsuite/23_containers/vector/allocator/swap.cc: Likewise and swap vector back before checks on memory/personality mapping are performed. * testsuite/23_containers/forward_list/allocator/minimal.cc: Insert element to really challenge C++11 allocator integration. * testsuite/23_containers/forward_list/allocator/copy.cc: Likewise. * testsuite/23_containers/forward_list/allocator/copy_assign.cc: Likewise. * testsuite/23_containers/forward_list/allocator/move_assign.cc: Likewise. * testsuite/23_containers/forward_list/allocator/swap.cc: Likewise and swap forward_list back before checks on memory/personality mapping are performed. Index: include/bits/vector.tcc =================================================================== --- include/bits/vector.tcc (revision 196556) +++ include/bits/vector.tcc (working copy) @@ -173,6 +173,9 @@ _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage - this->_M_impl._M_start); + this->_M_impl._M_start = nullptr; + this->_M_impl._M_finish = nullptr; + this->_M_impl._M_end_of_storage = nullptr; } std::__alloc_on_copy(_M_get_Tp_allocator(), __x._M_get_Tp_allocator()); Index: testsuite/23_containers/forward_list/allocator/copy_assign.cc =================================================================== --- testsuite/23_containers/forward_list/allocator/copy_assign.cc (revision 196556) +++ testsuite/23_containers/forward_list/allocator/copy_assign.cc (working copy) @@ -31,7 +31,9 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); Index: testsuite/23_containers/forward_list/allocator/minimal.cc =================================================================== --- testsuite/23_containers/forward_list/allocator/minimal.cc (revision 196556) +++ testsuite/23_containers/forward_list/allocator/minimal.cc (working copy) @@ -37,6 +37,7 @@ typedef std::allocator_traits traits_type; typedef std::forward_list test_type; test_type v(alloc_type{}); + v.push_front(T()); VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); } Index: testsuite/23_containers/forward_list/allocator/copy.cc =================================================================== --- testsuite/23_containers/forward_list/allocator/copy.cc (revision 196556) +++ testsuite/23_containers/forward_list/allocator/copy.cc (working copy) @@ -31,6 +31,7 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(0 == v2.get_allocator().get_personality()); @@ -42,6 +43,7 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); Index: testsuite/23_containers/forward_list/allocator/move_assign.cc =================================================================== --- testsuite/23_containers/forward_list/allocator/move_assign.cc (revision 196556) +++ testsuite/23_containers/forward_list/allocator/move_assign.cc (working copy) @@ -31,7 +31,9 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = std::move(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = std::move(v1); VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); Index: testsuite/23_containers/forward_list/allocator/swap.cc =================================================================== --- testsuite/23_containers/forward_list/allocator/swap.cc (revision 196556) +++ testsuite/23_containers/forward_list/allocator/swap.cc (working copy) @@ -48,10 +48,14 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); std::swap(v1, v2); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); + // swap back so assertions in uneq_allocator::deallocate don't fail + std::swap(v1, v2); } void test02() @@ -60,7 +64,9 @@ typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); std::swap(v1, v2); VERIFY(2 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); Index: testsuite/23_containers/vector/allocator/minimal.cc =================================================================== --- testsuite/23_containers/vector/allocator/minimal.cc (revision 196556) +++ testsuite/23_containers/vector/allocator/minimal.cc (working copy) @@ -35,6 +35,7 @@ typedef std::allocator_traits traits_type; typedef std::vector test_type; test_type v(alloc_type{}); + v.push_back(T()); VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); } Index: testsuite/23_containers/vector/allocator/copy.cc =================================================================== --- testsuite/23_containers/vector/allocator/copy.cc (revision 196556) +++ testsuite/23_containers/vector/allocator/copy.cc (working copy) @@ -31,6 +31,7 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(0 == v2.get_allocator().get_personality()); @@ -42,6 +43,7 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); Index: testsuite/23_containers/vector/allocator/move_assign.cc =================================================================== --- testsuite/23_containers/vector/allocator/move_assign.cc (revision 196556) +++ testsuite/23_containers/vector/allocator/move_assign.cc (working copy) @@ -31,7 +31,9 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = std::move(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,8 +45,10 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); v2 = std::move(v1); + v2.push_back(T()); VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); } Index: testsuite/23_containers/vector/allocator/swap.cc =================================================================== --- testsuite/23_containers/vector/allocator/swap.cc (revision 196556) +++ testsuite/23_containers/vector/allocator/swap.cc (working copy) @@ -48,10 +48,14 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); std::swap(v1, v2); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); + // swap back so assertions in uneq_allocator::deallocate don't fail + std::swap(v1, v2); } void test02() Index: testsuite/23_containers/vector/allocator/copy_assign.cc =================================================================== --- testsuite/23_containers/vector/allocator/copy_assign.cc (revision 196556) +++ testsuite/23_containers/vector/allocator/copy_assign.cc (working copy) @@ -31,7 +31,9 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());