From patchwork Mon May 14 15:37:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 913049 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-477654-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="d1URpmZP"; 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 40l4ZX6mNbz9rxs for ; Tue, 15 May 2018 01:37:24 +1000 (AEST) 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=sNuyRb9kmtjDvTKm8RiTr7QSViWPIvwBAquWHQYtY3DNJyYpik h//rtWoid3/KeA+NmLF2EHG+wNLQCFBxgqdNyW5em/WjKmtUME1Aw0EjtoR63S9E aqLMUPwnw/Id+hI3eiDbSY8I/3CH6tSf/4lctuaK8XJ7H+m5HFercDEEk= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=yzFCwBLQig7fankCouG1Q8c+s5Q=; b=d1URpmZP5DLaA3K2FmWZ 4g2q00ZmUOgTifK98ZMcECkhpFvd5pLoYTndfZjrMlYoP6zTdPQbFtcEJpG+rWR5 3m8zVdzOlfXy/XeIbZa1QzlndZuOVELj7hZU9Ozcxxi1KhdkdpWFobuSPd9PTWan 8QY2FC7vJ5ZV7BeEAQjtMXY= Received: (qmail 56004 invoked by alias); 14 May 2018 15:37:17 -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 55986 invoked by uid 89); 14 May 2018 15:37:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Mon, 14 May 2018 15:37:15 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA44730BEEE1; Mon, 14 May 2018 15:37:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 579AE5D6B4; Mon, 14 May 2018 15:37:14 +0000 (UTC) Date: Mon, 14 May 2018 16:37:13 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Gabriel Dos Reis Subject: [PATCH] Add __attribute__((malloc) to allocator and remove unused code Message-ID: <20180514153713.GA4320@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) As discussed at https://gcc.gnu.org/ml/libstdc++/2018-01/msg00073.html we can simplify the allocator function for valarray memory. I also noticed that the _Array(size_t) constructor is never used. * include/bits/valarray_array.h (__valarray_get_memory): Remove. (__valarray_get_storage): Call operator new directly. Remove ignored top-level restrict qualifier and add malloc attribute instead. (_Array<_Tp>::_Array(size_t)): Remove unused constructor. Tested powerpc64le-linux, committed to trunk. commit 71983b7d0901159af2bca65af783460721fc0a76 Author: Jonathan Wakely Date: Mon May 14 16:02:18 2018 +0100 Add __attribute__((malloc) to allocator and remove unused code * include/bits/valarray_array.h (__valarray_get_memory): Remove. (__valarray_get_storage): Call operator new directly. Remove ignored top-level restrict qualifier and add malloc attribute instead. (_Array<_Tp>::_Array(size_t)): Remove unused constructor. diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 07f38ed03ed..6759d6003e9 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -47,18 +47,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Helper functions on raw pointers // - // We get memory by the old fashion way - inline void* - __valarray_get_memory(size_t __n) - { return operator new(__n); } + // We get memory the old fashioned way + template + _Tp* + __valarray_get_storage(size_t) __attribute__((__malloc__)); template - inline _Tp*__restrict__ + inline _Tp* __valarray_get_storage(size_t __n) - { - return static_cast<_Tp*__restrict__> - (std::__valarray_get_memory(__n * sizeof(_Tp))); - } + { return static_cast<_Tp*>(operator new(__n * sizeof(_Tp))); } // Return memory to the system inline void @@ -410,7 +407,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct _Array { - explicit _Array(size_t); explicit _Array(_Tp* const __restrict__); explicit _Array(const valarray<_Tp>&); _Array(const _Tp* __restrict__, size_t); @@ -503,12 +499,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __dst._M_data, __j._M_data); } - template - inline - _Array<_Tp>::_Array(size_t __n) - : _M_data(__valarray_get_storage<_Tp>(__n)) - { std::__valarray_default_construct(_M_data, _M_data + __n); } - template inline _Array<_Tp>::_Array(_Tp* const __restrict__ __p)