From patchwork Thu Feb 15 15:20:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 201540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp473036dyb; Thu, 15 Feb 2024 07:23:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVWYbt7AFxy9hudwUa7nVz75YfyGThQDpect3SH/SHOqc4z1KlvAUL7T3oNSrgTfdLJoCJhby53FYdFvB6JjloIEsj7ug== X-Google-Smtp-Source: AGHT+IHWiTKn9usipUH/i4DPkc9BJZrAkOAtEW1eTHUy/ckUv/VRN5SJ59C/Ne4SdtrH40q6fuFA X-Received: by 2002:a05:620a:3956:b0:787:2201:547e with SMTP id qs22-20020a05620a395600b007872201547emr2410449qkn.33.1708010590720; Thu, 15 Feb 2024 07:23:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708010590; cv=pass; d=google.com; s=arc-20160816; b=aGvlgsRxPp27JDDeIO5RuLz8FM6CV9EtFXzdl/FYzh3xfX7GLLBSorOryPbTzNRa6I o2N2r7ljRkjhz29PP2Ghco2iL+UVYAM2hUCt53LbIDbEROheH+7FdCErenSsuqkfo+xo NUyMVmwfkKU8E05gBHIWxHoz+3bu3E1F8/VxlKYzZ1ohWS3N7d8OrV41D6G+mDrEnNGk +MN0odPxoSUmbZnQLuqY46BS5S+Bhs1uqf69vd0/gh3owy2/pItWGn4+lhpeEgZsM2J8 6RLg9tWBxS3DOMjJadPNCNbyLL9MFHWrQVOq+9CEKjfLiU6NLYRnrvZpWn0bwGldd4jZ jJNQ== 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=tj2rKYE9UzdK+64LglCUW3DGuYonjTQTzQtiiIXKs0Y=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=maLh1WQamYP9gevIODK+VLqOH1iXdJpJb41PBLLa0LBJMrDhMItA5xKNlsr0nGGUbF 8dXPLSrkqTgj28Tk9/8h89zxPaEPdWcMU3d4hnFOGsgzElqZoPYWUokCgHiZGegHNdm0 NVE869a2xOVs1I/XFNHt0hcGL8dJgamk9wIV4aPJz+/cswTPydNqz3A2mkReYW9KOuoW QNPMbCANrzjtkk7JF86Xfy5ivZJNCKEIHWdiiozPshjNO/E9WBzn0ho/QLK5jbIUFYXv yzBlCM2H9TILMbd0wg7gxVymsztqJ2lVc6QkNBrlpreUxrs8Mk42UJdjXaC9nKFVXvvt kLhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="kIHBHx/C"; arc=pass (i=1); 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 z20-20020a05620a101400b00785be029f54si1675091qkj.326.2024.02.15.07.23.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:23:10 -0800 (PST) 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="kIHBHx/C"; arc=pass (i=1); 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 5FA14384CB97 for ; Thu, 15 Feb 2024 15:23:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FA14384CB97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708010590; bh=tj2rKYE9UzdK+64LglCUW3DGuYonjTQTzQtiiIXKs0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=kIHBHx/CCuqK534oC4B772Zxk7d9MN+Eo6Uq3yxn/6JM4zwrzQEHL8Fhxd28eEM/H 7vL8dHq0gNN4crhoYjiaKw+gZCy289JzprUBAnG3ySUYWQgCvv2nsxfTs5ak1DWHyr ybK7FPlZnA2FDhuN+8T5d72GdYyX+AbW+b55I6CM= 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 CDAD83865C36; Thu, 15 Feb 2024 15:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDAD83865C36 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 CDAD83865C36 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=1708010469; cv=none; b=EhP1pqc8ykPgGTWn6aXIXB0e3OC8CpvuMehAs00Royaj1+6Hpx524etjVXq0tC84qMfhIeouS3YNtAfYrQiKJJ2uVP7QfmP15dW6UFaeO37kz4nlmlrJaAVeX/lQbmwVhFhiqUnl9KPTN1pFwigeBoPYEqR1L981Ypn6RnQ4CIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708010469; c=relaxed/simple; bh=Tur/wSh7aOg2ht3cQZi0Ui58OA2Bp2aaNfEvLoG8zs4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=g/RVRLra/wKO7jcVruE9488ukW43cdFjse3Sd+2W57LS36b3/6drD4vbsPi05w0HeNmeS4CButWXOMEhb3vGX1Iz5vr+0RGSkv89v67K1ko/voL+xa5JKWZa4i9LWZTBNuX2GRhpsNhmAz3irpYxtY2eNKrhOJRzkLPfbchxZVk= ARC-Authentication-Results: i=1; server2.sourceware.org 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 41FFKhYu012664; Thu, 15 Feb 2024 15:21:00 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3w98pqbbdm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 15:21:00 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41FFKlXV031785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 07:20:47 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.143]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41FFKkgn029956 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 07:20:46 -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 v5 03/14] c++: Implement __remove_extent built-in trait Date: Thu, 15 Feb 2024 07:20:26 -0800 Message-ID: <20240215152037.720162-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215152037.720162-1-kmatsui@gcc.gnu.org> References: <20240215045258.3025806-1-kmatsui@gcc.gnu.org> <20240215152037.720162-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jTFEaL3obB5Sr8yTPGC9tckI-VxHWryR X-Proofpoint-GUID: jTFEaL3obB5Sr8yTPGC9tckI-VxHWryR 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-15_14,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 priorityscore=1501 phishscore=0 mlxlogscore=464 malwarescore=0 clxscore=1034 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150123 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_H3, RCVD_IN_MSPIKE_WL, 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: 1790978912895798117 X-GMAIL-MSGID: 1790978912895798117 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 cec385ee501..3ff5611b60e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -96,6 +96,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 8dc975495a8..6ab054b106a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12777,6 +12777,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 56e8db7ac32..4f1094befb9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -170,6 +170,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));