From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id A9DB4382CE58; Tue, 10 Oct 2023 10:10:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9DB4382CE58 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A9klc7023614; Tue, 10 Oct 2023 10:10:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhk6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:10:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA9XF4009671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:09:33 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTW014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:09:33 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 26/39] c++: Implement __remove_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:40 -0700 Message-ID: <20231010095229.3364786-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: mLiwKuhz7w-qZbN4Sg45ru0LDem-5yUo X-Proofpoint-ORIG-GUID: mLiwKuhz7w-qZbN4Sg45ru0LDem-5yUo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=585 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SCC_10_SHORT_WORD_LINES,SCC_5_SHORT_WORD_LINES,SPF_HELO_NONE,SPF_NEUTRAL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 32 +++++++------- gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 6 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index fa79bc0c68c..2add97ae749 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -97,6 +97,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 4fa14de3e90..de3779b6d82 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -78,6 +78,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false "__remove_cv", CPTK_REMOVE_CV, false, false, true "__remove_cvref", CPTK_REMOVE_CVREF, false, false, true +"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true "__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true "__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c53e234f631..503e6804145 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -118,7 +118,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 56, + TOTAL_KEYWORDS = 57, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -127,7 +127,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, @@ -139,17 +139,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, #line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, @@ -237,21 +239,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, false, false, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, - -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 + 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, + 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, + -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, + 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 56 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); -- 2.42.0