From patchwork Wed Feb 28 19:26:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 207992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3567913dyb; Wed, 28 Feb 2024 11:37:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZsirUsyzZrzy/6MtmeoRn9qcEbC42/jOH11x8NulwJclaQRXInplDypH2JhXQbnMMzLaRh7RuSyj01k2AEBqNEpmuOA== X-Google-Smtp-Source: AGHT+IH6Lw4pa6HaIMSVZFM+9FIujWaQGBkgrCcSAlMcqhPtXvwPnF7L+lVFnguZSy5/G/GYTSUp X-Received: by 2002:ad4:5143:0:b0:690:299:1909 with SMTP id g3-20020ad45143000000b0069002991909mr31253qvq.50.1709149058770; Wed, 28 Feb 2024 11:37:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149058; cv=pass; d=google.com; s=arc-20160816; b=pFGg9GBICqVw29H0/G7/vpZY2m0VFZQd/CgQbNZgZqlZtnHsfVGJeh+qPOw5pp72Wj gZEO8lBs9ivcU+wOiTcKE+YRzcG54Ar4LGu5b6WX+sd+GsBYq3ODI8dGQXWyQ3UHNfgQ pj9PZw2FkSeHc5nv0rTiCfriAUie7rLgU8ylEF3r9AmQo13cYbdKs29n8T+PB0cYe6al aYGdiMDlA8AfvW0dk+H0A+uYcXfiI2jWZu+SR2a4eCN1tDG9W1LamcK59dCj+dPzpnn9 jhatw2wWM/F2+4xXaLD7Wrf5xa2d5QerUBCuIsTbiYPW/k/3EeazQquE1aqTQcOlNxUu KUCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to: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 :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=VCR1fZ5CXHZMm4uAmFxf42twY19+JZcVenK7BHozzMk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yYd3I4NQvj82ho1mBsRYw1BVK+tIIustOheiFMxwAWZwAsuIN77Ls/YLdx81ZHpgtD 4SDOM2DbcsmxXBhJveIU2pz9UblxdFq0G1xjBfxfUu7PXwGWAR8c/7DXDAsSHJJ8Vq9k iZJrFJS8LY0J0QIpLdInOLoHMJ0XsVtvLXsVCXwD2U470GwGQrrrpjOkPzR4BF0u7zen NIOhoYVJirRQK+/2gImeDAvpa3+uxq63tSdHz9muU8iLPTqrRqO2jZHNefllTYanBFWe JmTHAbmKIE0cCOohDW0qUVHhn7ruLMJ3a4YQlUiSGAif9PkKLTZadnO3idhT3vfjV+Z4 Kmaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gkzy7Bdb; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 12-20020a05621420ac00b00690011ff09csi195861qvd.393.2024.02.28.11.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:37:38 -0800 (PST) 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=gkzy7Bdb; arc=pass (i=1); 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 12AF238582B9 for ; Wed, 28 Feb 2024 19:37:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12AF238582B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149058; bh=VCR1fZ5CXHZMm4uAmFxf42twY19+JZcVenK7BHozzMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gkzy7BdbB3DreyjSrDi51LvPE4uYXds4mQPBJNTVdK7nD+nF6UxB+fEi25nPHR9Vi P6aji4Nz+mE4YiJriBtx4M31aGl0MO/M2E5EKpERFUaHkxhbfFMdy3NbAdT326GfCQ AnmHSDBgrbCXS1Xzc7RodSaUnusQhOHwC9KUDy04= 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 A0F413858000; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0F413858000 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 A0F413858000 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=1709148572; cv=none; b=xEGEyCKZNUjz1Z8xDz1dCvE9Tz6XelvbMjfctZ72te14HCI43cgb3XSl9m7Fx9Fs4mOPiQh10VygOP0ZY0JNLzHqXb+mYb4lz6RP27uB3ksAsp95/Ee7Vrj4kuCsi571q+nD1w5xagmuQ7pc+Ujhb9CvQC20teqZjq0McyOCTjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; c=relaxed/simple; bh=VtQnoussf2bSaiJHSc6oXahNbkNP+zD4tnolaN02p84=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tz3LvUXohN5q6wKTiPH8ZTmqEd3Aywr94Rt7ZxvOR5U0r5UZr2p6uO/YqZ3isH/6aCJXb9s1wQqmLrh+XyyH+7vihYYZ0GK1zQbtXvoLZUpfUcB9+R2Jzqid4Sw3ho9ziZUORvqQxf+C3325AE40iZUXSj5X19DkUfVOZcu5eQY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJJloL010615; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj8nusn3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +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+UW24.02) with ESMTP id 41SJSpWM019397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTT015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 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 v14 11/26] c++: Implement __remove_extent built-in trait Date: Wed, 28 Feb 2024 11:26:16 -0800 Message-ID: <20240228192843.188979-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1034 mlxlogscore=464 spamscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791502124479822517 X-GMAIL-MSGID: 1792172683449439914 This patch implements built-in trait for std::remove_extent. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_extent. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_EXTENT. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __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 63f879287ce..577c96d579b 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, "__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 635441a7a90..58696225fc4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,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 9d861398bae..5d5cbe3b019 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -182,6 +182,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_extent) +# error "__has_builtin (__remove_extent) failed" +#endif #if !__has_builtin (__remove_pointer) # error "__has_builtin (__remove_pointer) 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..6183aca5a48 --- /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(__remove_extent(int), int)); +SA(__is_same(__remove_extent(int[2]), int)); +SA(__is_same(__remove_extent(int[2][3]), int[3])); +SA(__is_same(__remove_extent(int[][3]), int[3])); +SA(__is_same(__remove_extent(const int[2]), const int)); +SA(__is_same(__remove_extent(ClassType), ClassType)); +SA(__is_same(__remove_extent(ClassType[2]), ClassType)); +SA(__is_same(__remove_extent(ClassType[2][3]), ClassType[3])); +SA(__is_same(__remove_extent(ClassType[][3]), ClassType[3])); +SA(__is_same(__remove_extent(const ClassType[2]), const ClassType));