From patchwork Thu Jul 13 03:19:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1562461vqm; Wed, 12 Jul 2023 20:22:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQ+g9bvx5d0YtHDmQDIN1sp8SULAmqcg3UcNYDlJk/MpmlvDNQErazQkdHPWODXnH1hnez X-Received: by 2002:a17:907:969f:b0:988:565f:bf46 with SMTP id hd31-20020a170907969f00b00988565fbf46mr5425275ejc.32.1689218575392; Wed, 12 Jul 2023 20:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689218575; cv=none; d=google.com; s=arc-20160816; b=Ll15znLyJtSvu3kcAn2/0FLgMzhDVjkQuw9mHE//ADAl++TyZSIn5BqLyCEO4ivwoZ SH3zXk7xUTZEhJhxwatAFwLiXaYVn3bdmKR9Pg4vx+ESbx0Go5OD1+Sqa+br4xbNBFN9 Jmy8IhAqzYtUJwBGor4sjvlJI5vb0X5sH2HgL3tv8IG16fA2cl+pqsymId21PtKrUsET og1Mh7oD7h4y2S/jqbl3pc/c9Z/AEEDDyQjF+v29G65Dw4BssUvbUA8rBjk9o0/vNZl/ 7HDeZA9+RxI14Wrj2GESBd5yRis4Zm+KFMKfenww7lvHRRg3GRr/DgTIpVUG7v3rd6ub DfGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=7dwCTc03qBJANlMdgZX4L7u7iUIpyCoCvWbfs7fPHz4=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=qzJfHo8QGPPzU6y9oNZ8LD6gilvuoYqN147J/8orTYQoGJA4W/kCdFAO7uCcrmunLc Ts91hsIjbzCNrJSvCbFXORQVBADawWfkHIEL/ra+An+y2B1ndMouM4AfoxXeCYf98ICv wrg+WoiePcFqHE0Gtd3dd5Pq1vM+O0qS2B+3OUUVnmlPfW+IY9z8Ns4JgFP+cwx7Mzfl g61Xparz5jRkEgsEMMuMo+Xo9T1UrSUmNyvXgeD/OT2qvS9f20uChihRxHv+7v70xlX6 EeyK17rMfBtk7AJ2M4y6A6WmYXKerYxTKFHqPz+gRHACZH6Ft9Zk5QbM4kKusockUrwI jmJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Puh06q8n; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c2-20020aa7c982000000b0051a1d9c1974si5947937edt.107.2023.07.12.20.22.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 20:22:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Puh06q8n; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F2193857728 for ; Thu, 13 Jul 2023 03:21:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F2193857728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689218470; bh=7dwCTc03qBJANlMdgZX4L7u7iUIpyCoCvWbfs7fPHz4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Puh06q8n5rVEOANFON3h1vBSL9pEp+rOgpNtoxrZ8Zjs4pHVIqs3VZ9RvQq4XxYXo gdHjvCKcgQyTiHfuUWN09ETd+zDXRcjxqOb8dcHIo9MGtOMtWYEz1+HqeDrl3fpRBK Yg/U1huCyRJcZPHIrh6S+OZbeYuDsIEBTlpJme7o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 063E53854E95; Thu, 13 Jul 2023 03:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 063E53854E95 Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D3HOw7009499; Thu, 13 Jul 2023 03:20:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt2sj2hjq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 03:20:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D3Jj3e019426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 20:19:45 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.234]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 36D3J2jx014223 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 20:19:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v5 2/2] libstdc++: Use new built-in trait __is_pointer Date: Wed, 12 Jul 2023 20:19:01 -0700 Message-ID: <20230713031901.18162-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713031901.18162-1-kmatsui@gcc.gnu.org> References: <20230713031601.17787-1-kmatsui@gcc.gnu.org> <20230713031901.18162-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pBQzG8tbaAz7R5cDCx6yFIixBpxAqhGQ X-Proofpoint-ORIG-GUID: pBQzG8tbaAz7R5cDCx6yFIixBpxAqhGQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_17,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=568 clxscore=1034 malwarescore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130028 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771266095205163215 X-GMAIL-MSGID: 1771274057284100997 This patch lets libstdc++ use new built-in trait __is_pointer. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_ptr): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 3711e4be526..4da1e7c407c 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_ptr : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_ptr { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0e7a9c9c7f3..16b2f6de536 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -515,19 +515,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_array<_Tp[]> : public true_type { }; - template - struct __is_pointer_helper + /// is_pointer +#if __has_builtin(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3168,8 +3182,22 @@ template template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#if __has_builtin(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template