From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id AC0753858C32; Thu, 2 May 2024 16:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC0753858C32 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC0753858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666596; cv=none; b=p9L5WwYPLs/WUmgrPjuvwaJOBMEKQU0bIPU+Ldiub1/i5ira9K94nDIIjLIoQOeNL9CNyv093faaINpkg6jo5mx03NzfVfldpkFfqSFJbC7j+kwO1x4apMn2oiYfsEK4lmWZ0F+5Ll08d74jFm+35fqM0/Zh7Flpmt8zxvwqtBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714666596; c=relaxed/simple; bh=Ht4iGkd9Jd/wJls3RQxjEKBpzMdvBPE/eznRkT/z3Ow=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LYcbjDTTjH9vJMfOeoY52Gs9rPiQmMxOyajGj8ue8aib4TkA2qfp4Ng+X6TPyJVhPvWZER/GJvNEcg8PFZKUwO6E5R7MbtHRjjCRdYzlhE+6LGzGdc8m6srVI7AE3fwzeL1O3TDkXkmlMR5DSEjf4lxZBIBH/F0Ap8KW+7iYXOg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442GE8ip010122; Thu, 2 May 2024 16:16:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xv4e23sxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 16:16:32 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442GGGD5003507 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 09:16:16 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442GGFoo023119 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 09:16:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v16 11/26] c++: Implement __builtin_remove_extent trait Date: Thu, 2 May 2024 09:13:37 -0700 Message-ID: <20240502161614.3705912-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502161614.3705912-1-kmatsui@gcc.gnu.org> References: <20240228192843.188979-1-kmatsui@gcc.gnu.org> <20240502161614.3705912-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: -_e8ZPsvB0ee56awL-Td_ZSSHoMhdHfS X-Proofpoint-ORIG-GUID: -_e8ZPsvB0ee56awL-Td_ZSSHoMhdHfS X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_08,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 mlxlogscore=489 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020106 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_MSPIKE_H2,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_extent. gcc/cp/ChangeLog: * cp-trait.def: Define __builtin_remove_extent. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_EXTENT. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __builtin_remove_extent. * g++.dg/ext/remove_extent.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 +++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/remove_extent.C | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_extent.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 7847ce748f6..56b706a6127 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -100,6 +100,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_EXTENT, "__builtin_remove_extent", 1) DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 29c1dbe2a85..383259fca56 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12938,6 +12938,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_EXTENT: + if (TREE_CODE (type1) == ARRAY_TYPE) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_POINTER: if (TYPE_PTR_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 509cd4294f6..d2f91862c03 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -35,6 +35,9 @@ #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_remove_extent) +# error "__has_builtin (__builtin_remove_extent) failed" +#endif #if !__has_builtin (__builtin_source_location) # error "__has_builtin (__builtin_source_location) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_extent.C b/gcc/testsuite/g++.dg/ext/remove_extent.C new file mode 100644 index 00000000000..70c6bc3d84d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_extent.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__builtin_remove_extent(int), int)); +SA(__is_same(__builtin_remove_extent(int[2]), int)); +SA(__is_same(__builtin_remove_extent(int[2][3]), int[3])); +SA(__is_same(__builtin_remove_extent(int[][3]), int[3])); +SA(__is_same(__builtin_remove_extent(const int[2]), const int)); +SA(__is_same(__builtin_remove_extent(ClassType), ClassType)); +SA(__is_same(__builtin_remove_extent(ClassType[2]), ClassType)); +SA(__is_same(__builtin_remove_extent(ClassType[2][3]), ClassType[3])); +SA(__is_same(__builtin_remove_extent(ClassType[][3]), ClassType[3])); +SA(__is_same(__builtin_remove_extent(const ClassType[2]), const ClassType)); -- 2.44.0