From patchwork Thu Jul 13 20:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 120104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2079448vqm; Thu, 13 Jul 2023 13:49:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlE8eib8wC5ghhzX3j/9Rs+mmCmZLJDaSlcetQ12YEsM7cScFq38Z/pgZBqs+yI+wmWW0BWG X-Received: by 2002:ac2:4d8c:0:b0:4fb:89c1:c209 with SMTP id g12-20020ac24d8c000000b004fb89c1c209mr2146006lfe.62.1689281369227; Thu, 13 Jul 2023 13:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689281369; cv=none; d=google.com; s=arc-20160816; b=lNGWBaGvLIymuvRSqqyiS9WUJpbICSgQM8fqZBU5mTbS7r0T/y6HIPLU2cCltBxfev lU/DKd3/ESAD6ZyTiUTtSZqzUCIw5WuCp+LiTJ+JTcE9vF2/sJOCzjtQwXDxVeekX1Hl /XdCXa3qM1BuJ3lFWTX4c8iSoEvm5C4OV9BMPMTaKfnfb5z352neRHQLvO410oDJW3rl /QMJS47kUJyEFiaL3kUM9GdZUNkdKViDaoKdpzdpIZX6bMnPilfS9rG5CZqd1zQHYYlh hVBlWtJlxz4LqV5fA/E7C0J0PWs8XvbeD5wdyQ/aVwOWxf/Q//rJMF9LUn2V6j81kF68 tqPg== 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=0Xqtpp/4GNkUosnHca9FfieNUsZIPsxpvDBDnElW3Oc=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=qN7rvFzp96zwyGac7iBeVWTBCQAnG9iU0emDiyFsMx5fLmAVyUwQhsVzLaOoB1akrR eou4qy9YS/x+3nLikyN6Bc6Jjighr2F8aOoGUxdxhFxC/D1YUAc46EMNRi7YNK3yGmtU hD0AXqKIdHfLPIQQWZ+Af4n8IwYX2u4mH4MwnXmqCDt2/jtxzXkxVDWj060+2riw8fVi tK9Wc/I6mHYo9fzL4MP3fS115gwbZI1qPuYKANxCE5mxVuZY4namk53gZSx2/ffAqwSM CRsHbSrPjcoieewpqWi4Tpkiz7dWyk9Xq34HVr6LEEw5ypL2BSp/cjuSZrUGP/PMpJ1m ce8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EfcFuigJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g15-20020a50ee0f000000b0051ddf3cc9e1si7423775eds.609.2023.07.13.13.49.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 13:49:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EfcFuigJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 6AADE3858C74 for ; Thu, 13 Jul 2023 20:49:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AADE3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689281366; bh=0Xqtpp/4GNkUosnHca9FfieNUsZIPsxpvDBDnElW3Oc=; 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=EfcFuigJFd6xvw7hPmMrc/kqTUxr3b9WIZALnlkhFF9I8cqqQXy2J74FqetTgr4zw Iy+qnpIK+NS0bvLSib7Og8dkiGoqhe+Kuq5eJZtxXrh817njX6U7O6EhwwmrNhu/2r rlN08+I11We2SRTFGOWiFQJR/lOTZCPtiaW72b0M= 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 AC9643858D1E; Thu, 13 Jul 2023 20:48:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC9643858D1E Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36DKiJ9I005026; Thu, 13 Jul 2023 20:48:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rtpwh95a2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 20:48:36 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36DKmQuY006398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jul 2023 13:48:26 -0700 X-Auth-Received: from localhost.localdomain ([10.18.194.223]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 36DKmPnR010934 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 13 Jul 2023 13:48:26 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v6 1/2] c++, libstdc++: Implement __is_pointer built-in trait Date: Thu, 13 Jul 2023 13:48:22 -0700 Message-ID: <20230713204823.22303-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713031901.18162-2-kmatsui@gcc.gnu.org> References: <20230713031901.18162-2-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Zz3vi4f3JhqnA0oBw9sDjnYw7y_HR9UJ X-Proofpoint-ORIG-GUID: Zz3vi4f3JhqnA0oBw9sDjnYw7y_HR9UJ 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-13_09,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1034 spamscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307130183 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: 1771339901388467255 X-GMAIL-MSGID: 1771339901388467255 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. * g++.dg/tm/pr46567.C (__is_pointer): Rename to ... (__is_ptr): ... this. * g++.dg/torture/20070621-1.C: Likewise. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Rename to ... (__is_ptr): ... this. * include/bits/deque.tcc: Use __is_ptr instead. * include/bits/stl_algobase.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 +++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 22 ++++----- gcc/testsuite/g++.dg/torture/20070621-1.C | 4 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 6 +-- libstdc++-v3/include/bits/deque.tcc | 6 +-- libstdc++-v3/include/bits/stl_algobase.h | 6 +-- 11 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8cf0f2d0974..30266204eb5 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..b7c263e9a77 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) /* FIXME Added space to avoid direct usage in GCC 13. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8fb47fd179e..68f8a4fe85b 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_POINTER: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..9dace5cbd48 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -146,3 +146,6 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..f08bbf6fd7b 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -192,13 +192,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -226,7 +226,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char @@ -1202,8 +1202,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; const bool __simple = (__is_pod(_ValueTypeI) - && __is_pointer<_II>::__value - && __is_pointer<_OI>::__value + && __is_ptr<_II>::__value + && __is_ptr<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); return std::__copy_move<_IsMove, __simple, _Category>::__copy_m(__first, __last, __result); @@ -1294,8 +1294,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; const bool __simple = (__is_pod(_ValueType1) - && __is_pointer<_BI1>::__value - && __is_pointer<_BI2>::__value + && __is_ptr<_BI1>::__value + && __is_ptr<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__copy_move_backward<_IsMove, __simple, _Category>::__copy_move_b(__first, @@ -1426,8 +1426,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_integer<_ValueType1>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1515,8 +1515,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value); + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, __first2, __last2); } diff --git a/gcc/testsuite/g++.dg/torture/20070621-1.C b/gcc/testsuite/g++.dg/torture/20070621-1.C index d8a6a76b6b0..b05136163e8 100644 --- a/gcc/testsuite/g++.dg/torture/20070621-1.C +++ b/gcc/testsuite/g++.dg/torture/20070621-1.C @@ -18,7 +18,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -49,7 +49,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { template inline bool __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); + const bool __simple = (__is_integer<_ValueType1>::__value && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } template inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..be0689096fb 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -17,7 +17,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { + template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..3711e4be526 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -364,14 +364,14 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // Pointer types // template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -390,7 +390,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index a212b8a6940..08d888ee8af 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1273,7 +1273,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr>::__value + && __is_ptr<_Ptr>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with @@ -1329,8 +1329,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr1>::__value - && __is_pointer<_Ptr2>::__value + && __is_ptr<_Ptr1>::__value + && __is_ptr<_Ptr2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index dd95e94f7e9..cf21611fa5c 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1214,7 +1214,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple = ((__is_integer<_ValueType1>::__value - || __is_pointer<_ValueType1>::__value) + || __is_ptr<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1377,8 +1377,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with From patchwork Thu Jul 13 20:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 120105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2080356vqm; Thu, 13 Jul 2023 13:51:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlHikwKx0rlCvGegiJFSdC+8c5MVaw5K6ZyXgPYzo2Q7zjEwK6KsNIXDkDnSbxunSZMznUFo X-Received: by 2002:a17:906:ce23:b0:974:326b:f9b2 with SMTP id sd3-20020a170906ce2300b00974326bf9b2mr2228386ejb.66.1689281500539; Thu, 13 Jul 2023 13:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689281500; cv=none; d=google.com; s=arc-20160816; b=nO9xNj78zvJUWM12wz3orIoR8ZXyX4J5cuRwALyxjWWjZFoBkk9cGg84sUR0f7AEuj 4rlb7fKMMaVx/MQ+B/LH2yGPjFcernmX9D1INAfJHraWfBVnlawbzoj2zWbRXp566hQn xk7brRJpq6Ebj0beSBg7Omg9zJtz7feo2CiJnGP0iVM6m4bds1H5ZOLoPFTJTxTYoIKe M1m5uoJcgKQ9yIKCpP1HiaTKHrnTwsjvPCthx3BV/D8YJf+LdafpcluK/CaIsAgA+ulU 0issZR4EBEj0i094Qp3eprXwsNmJVqPXpmOlgPsRR0XdDz5uSMN6j3LVNubah2v+csVo qxew== 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=LRn73fohQ1RJZn+WK56vrwY81LRwG+KHRjcuWgbuMNY=; fh=M//N9MeL0zdGdUiFLCZuagaGP3m/uSH9HFSbPEk5yxc=; b=biYsH1wIRcP8NGu2ididE3Nxq4QTq6nExlT2CXvZydR9zXApHVAgKdJsnjMOXqYaTE anMgyreyS5xT4HsyRwBN7Ans0XmNVBmGcr1CoiJ2ZS2PizUnKq2aiD59UiX1gPSt02eq 8dF/TBONrE7hwk0wN1t1RiBWsKJo9fsdVOzvEMjOkh/JT0ltS7OGGVROpH6qv+2BVXwD X2qADhYPJ82pvyf2w94iKfvMFKDwJiGh7UFbYLsknGZVspMd5fv8SO1wblmSr1k8tm1y XHG13rM2xoOXeBvfO+vIwKKn722SFJKk8TNcc8cSq8bw5osObTAPxAwz86o6sw7FUqPl 2/qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jlliz53B; 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 k20-20020a17090627d400b00992b55d152esi8552097ejc.242.2023.07.13.13.51.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 13:51:40 -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=jlliz53B; 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 3CFA7385AF8D for ; Thu, 13 Jul 2023 20:50:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CFA7385AF8D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689281418; bh=LRn73fohQ1RJZn+WK56vrwY81LRwG+KHRjcuWgbuMNY=; 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=jlliz53BjmrbYBz0ikRf4QXNHt28uAbNgsz7SbZayo9sVnWBkODQ5H7K0cKLhuiK6 4q6wgG6GwLhyp7J+d8h2spIW4gLl0fa/ME/NJUlWLSvaij/i8oyQjHzDKrr4naaoH7 WJw2CQgaM34New9XAUb63OBywGUFa08IuBW+656s= 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 6D6B8385783F; Thu, 13 Jul 2023 20:49:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D6B8385783F Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36DKjxcG008445; Thu, 13 Jul 2023 20:49:27 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rtpwqh32r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 20:49:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36DKnKOf021297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Jul 2023 13:49:20 -0700 X-Auth-Received: from localhost.localdomain ([10.18.194.223]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 36DKmPnS010934 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 13 Jul 2023 13:49:20 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v6 2/2] libstdc++: Use new built-in trait __is_pointer Date: Thu, 13 Jul 2023 13:48:23 -0700 Message-ID: <20230713204823.22303-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713204823.22303-1-kmatsui@gcc.gnu.org> References: <20230713031901.18162-2-kmatsui@gcc.gnu.org> <20230713204823.22303-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: iDf_Deiny4HvfRAe1WcDlpJGlvhYZOzb X-Proofpoint-ORIG-GUID: iDf_Deiny4HvfRAe1WcDlpJGlvhYZOzb 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-13_09,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxscore=0 bulkscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 spamscore=0 malwarescore=0 mlxlogscore=649 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307130183 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: 1771340038616802403 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. Co-authored-by: Jonathan Wakely 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