From patchwork Mon Feb 19 13:51:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296001dyc; Mon, 19 Feb 2024 05:56:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVgTg9Dc/6S9rq5c6ipAQ3HdMllQj9Lgk62+KYr2r/cCD2/Z78nV+LiLKzj0Y4oIL7KrwPrk82yp3xUQEadHpSa2b5y4w== X-Google-Smtp-Source: AGHT+IFIbbyfPLdGEq8CXmCM1xvtEKtCHfVtbfp0VsF77+jV2ZND5d6lA5t8DI7TUN2s3mgGoIHH X-Received: by 2002:ac8:574a:0:b0:42e:13ac:4811 with SMTP id 10-20020ac8574a000000b0042e13ac4811mr2172448qtx.44.1708350980407; Mon, 19 Feb 2024 05:56:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350980; cv=pass; d=google.com; s=arc-20160816; b=KREfA9lUTInd87W9B2EXqs5JOqU0kgnHzsIjdTsfzCRSIbchGf38ATQboLaYFKgCpP O8Gqv6tGl+mkj//W3Mw5SbN4AQwxUyCFlKhVFhvuSO0Ktm25wgtoh3E5K1Z3+NMsHPY8 v9MDnvv2jOR8Bc8Yy05tOCSYRkjx903WpwbMEtACW5va9WTPBLDSF7znwAOBk5lJ229m X1ldKzNEPfpvbD1Q4BQo5Ss7d/PhYM+JFzckD3a7fmDRAf/Z7SWwHAguISM1EduAJLk0 Gg4e3sRVBksTNOw/HcLyLRomXS2B0Oj59XM7fEzdZ6nq2faxLXP2kJSH5U41OV5VBG86 nSDQ== 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=PLx947mGsh6L2rlBlP70855z6dtNG9YsS1CnHXu/qCE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zXZp2cXXxZ1zNLETuG1Hhf2rBeakYBwMx3Gz3C1kaA/jCJFHxGQ1YjLT50ZCEG7KzJ vhulhitAymT32geEYYoVC1w37T5EWLnNTMq+Yt389ZO5cQY7F9Ued555sBeAjr89+Mjm 9NdaUHvez8UBfqoZM5RFer/IizIaktCQJRGx0x1xGfrCKg7FQoBJjuR695ER/+XV5kMI u+/PEki2AB1F0LEUSqiqH5cUeu+9Y3o4jmpack/TYRo+MeHvuiSu1R620rLiPL5/a260 L0QHmw3EcA1+LsCVgdUCGZWhlTE/w+kN7a8FeUBfyZgUANkh3B/Qi8uuXpHR1M8Q7wUH ZGPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ill7rWxl; 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 x10-20020ac8730a000000b0042bf6462ae9si5978361qto.734.2024.02.19.05.56.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:56:20 -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=Ill7rWxl; 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 BC0E2386546B for ; Mon, 19 Feb 2024 13:56:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC0E2386546B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350979; bh=PLx947mGsh6L2rlBlP70855z6dtNG9YsS1CnHXu/qCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ill7rWxl7AwuVG/1/Wbl+aNA08SHS8d54lceWBXjmVaw3s7dcx61UUniJBn7sjGEz Fu1Vu6SVbFFBe/Sbh0+RTxPLEWb6rUC+Ni/hq5H6XCb+EY6jw/rKtsEECT3ae/AgN8 fZ5VLNxg1oyIttTjwtwOXYqxa8J0o8r3ksDCZlY8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 04B34384CBA4; Mon, 19 Feb 2024 13:51:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04B34384CBA4 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 04B34384CBA4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350705; cv=none; b=txmoDpMHtYykGJH2giLLhMzUbClfVc6E17g6f+8PQuSPInsKFu9kJYJCH2wEzziuw30scUkm1eO+JAIL56579F9lrQOj8NVZSvgpDGL0Ud/ZDn9ZBA8WpS/ft38tYvWO+YwEwK6/EFFnbFUs2n+XjI4WpBpM9E8Dpu4Qv8WLMts= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350705; c=relaxed/simple; bh=nKUVydbqBg6b0GDgkJ3LScDBxxip4RdX775RqPtvuWQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Vkn3vPb6KbQjondh1jEPKSZ+iteYTpZMcYZoLlvOB3EY8U/qmx4104H9Lo2sYGLYNsT4sVsOgnRI4UE9BcnFIwDrPRsISAsX9RDujYZh/e0H9zIWo2yEldm2bNmlO1U7qILj3CYPHBSPuTQOPrLxuV4fhoCbirdKE7OZHWcBTeo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDeDko003439; Mon, 19 Feb 2024 13:51:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6y06uak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:42 +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 41JDpZZf031676 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:35 -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 41JDpZRJ001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 01/22] c++: Implement __is_const built-in trait Date: Mon, 19 Feb 2024 05:51:08 -0800 Message-ID: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0Ky0RGVFbcHvZSaW3FYMEVsqG3HCf6Dq X-Proofpoint-GUID: 0Ky0RGVFbcHvZSaW3FYMEVsqG3HCf6Dq 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-19_08,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 bulkscore=0 clxscore=1034 mlxlogscore=719 mlxscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1786112020272549532 X-GMAIL-MSGID: 1791335837762541870 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * cp-trait.def: Define __is_const. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. 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_const.C | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d9569013bd3..8b7833d6cae 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3766,6 +3766,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..36faed9c0b3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -64,6 +64,7 @@ DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 57840176863..0d08900492b 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12446,6 +12446,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12688,6 +12691,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..e3640faeb96 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -71,6 +71,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8a0e8df72a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Mon Feb 19 13:51:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296126dyc; Mon, 19 Feb 2024 05:56:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXwWt7JRg40NOLDnRIvwntm3SrIjrZRSiFvIjGy+v1YLcWG04PGSReqb8VF8QMja5r4EFsynMJQn3URvIK5WUCiWFnoKQ== X-Google-Smtp-Source: AGHT+IGdIFXMw+mDDqWmrbt1F7KvzXFzbviE8oFT9oSGri2xZE7ZzrqN7SYWkKiyONV/pNcrBwQ7 X-Received: by 2002:a05:620a:4507:b0:787:34f7:2498 with SMTP id t7-20020a05620a450700b0078734f72498mr23064654qkp.24.1708350994777; Mon, 19 Feb 2024 05:56:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350994; cv=pass; d=google.com; s=arc-20160816; b=qQOS9nEwzr16ujFzf+kQvlCEJO57dwb7JkD1DHhQcAi4QwUYtEoVxx+yREbrBakO+8 nV2zSblZC/g7bE1FkQSKBT69RX4r1K6uVukFPFUx9rUmm48ghq6QGTTK8DOLn90YRD/6 gVxzhaPwHHS3ZlwBrQbFrgiJVQejDvJi9IvJD9UO13Hv1QHANm3Nal3Zhv+SIZV83I1e nlKtr6lBlGvY2TQzWbaTNF4/ZEuhHnYP7/XbybyPFhtqHpGgEhMzuAJHJb7DWI0pazu6 eWjKvsQiLKk+WZaeRwZZGvet6Ek9kSkIlchMDkzWFYrK/rwVxs1/sdmCnlsUYc8+P6Pk Br7g== 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=fs+Ujol2wKNchtL6/hVq4Qw7DqdISyJ47g01Y+VnMus=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=hq40jKfXcOrmpba07A0hYwfiDm2wYcD9Ta8MfFiD6K4t0j09JDbEaZ6ScEXyZYhrLc Z/44mq2D+Jj5GpgqGruJmo9USRkD9+WsfvvR9TBi3Y4Y4fIHuc6q6OmD/hzvHKcCSyI/ CASR7EcaFBWfuAqP00hop8G6HoSzOOcBmxKxTBCvUiYkrkiy0uzkkmmmUX+ntzbundgR gh+QNBM586IvLtWQh0iVCR1Ef0pCVySNu6alTD3SbGCj9RjXpDNTLyX6xaxAp/70qVnL nJqrG4I9W2RVcnUs0puxyszLsfD0jvaalkHdPAaCZNFLry5FDCf6EZGkT2QfjAzb3+Vz A2hw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="UMDy/bgy"; 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 d22-20020ac86696000000b0042de588bc95si5191464qtp.562.2024.02.19.05.56.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:56:34 -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="UMDy/bgy"; 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 7009B38654B0 for ; Mon, 19 Feb 2024 13:56:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7009B38654B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350994; bh=fs+Ujol2wKNchtL6/hVq4Qw7DqdISyJ47g01Y+VnMus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UMDy/bgykGr3pWA7L4UbX4BsJDHiGp49KJ1O8wDghaquAUZzmj765VYlBl3BgU2rP Yaid7P/4qf3TkwT8yi8vi/mRtsr+KQscS/AJ0zRXliHL+tA5RUBJKmAV+q6TCpZ0FG O90MvK0SHkf4BpCHV0PXYxTLcTNLZ7Q8vM9zbAzY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id DE0BA3864873; Mon, 19 Feb 2024 13:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE0BA3864873 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 DE0BA3864873 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; cv=none; b=RB7i6fj/CJobJmbKEY6qt7ZEaFhWYp05HAFhXvbqNMiYksOub0q7CfEIfHMM4vzLbUIzoaTGHttNkKL8gCQuv3UOR/Q6BL5pJPoPYYBeckt3YAgm9iVxyQ5a/SASgwg5cmkh/cuqiNENyAO7pi3ETrMTuvW140kYK7ItZF47eFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; c=relaxed/simple; bh=DK/buwRkf+f8vkrHyKbDHbVu19IcozjC531g8TgHQ6I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EEoL0U60KxeSqeN0Nu+GqKbsqLSrmgMt8TF/LeB0+2heAe3K/jV+pEcvxOX4iGyt7hWSW5ifuaCNfr8G0QsW+TO+D+YlPvVBHU7AtNOkjswu0BJ66yS0zXQx+yZ99jBwNpOd3I7Gofv+R63BGaUR5Q8YdiRgPMWM6Ir1O4yFqxw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDW79V016541; Mon, 19 Feb 2024 13:51:51 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wbd09du8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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+UW24.02) with ESMTP id 41JDpZQd004103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:35 -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 41JDpZRK001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 02/22] libstdc++: Optimize std::is_const compilation performance Date: Mon, 19 Feb 2024 05:51:09 -0800 Message-ID: <20240219135129.3635809-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: KB27mw1qteCL-Kdorr1ZfQXv98I__EO6 X-Proofpoint-GUID: KB27mw1qteCL-Kdorr1ZfQXv98I__EO6 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=767 clxscore=1034 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1786112060520651610 X-GMAIL-MSGID: 1791335852383328158 This patch optimizes the compilation performance of std::is_const by dispatching to the new __is_const built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __is_const built-in trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 21402fd8c13..6e9ebfb8a18 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -835,6 +835,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -842,6 +848,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3327,10 +3334,15 @@ template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template From patchwork Mon Feb 19 13:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1297536dyc; Mon, 19 Feb 2024 05:59:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUiwLfddVywcQCQkiYg7t0fQ6Ae4diITjp3AtRGlF3IbS08DkwKWNhqAYDNjRJPcu60IcFEoeAWpaX5pqlaRUht9jLzHw== X-Google-Smtp-Source: AGHT+IEuAejlu/5wNR7jtt/rXvKWIg9lgscd7z+XzXEBlMS9tW4wTW7zpD8BtL9W27eavtqzM587 X-Received: by 2002:a0c:f0c1:0:b0:68f:6e0a:d47d with SMTP id d1-20020a0cf0c1000000b0068f6e0ad47dmr3095562qvl.49.1708351186562; Mon, 19 Feb 2024 05:59:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351186; cv=pass; d=google.com; s=arc-20160816; b=EF+g3nb+KweVJ1rlDoEHusN07JLBSIOT4kIbleXSI+N5yRpp2xC6ZO9/hQIF9Ul4Q5 iVDC09w+GORLtb0sK2ptsU/zYf58nn3nJ68OjN8cG04exgaEwOmm2P64+2CYskUhom/x q0uClW747g1fLiEuW6Neii/XnNBhsy8l4uwsIdn89XMovWl3V86uZ5QVRHzNXWIaCPTn DpZhEaw9UtPDxbYPt4APxgIkGq3ifAjzQCobLffgiVMsTF6XSfG2vP1NoPeyojsvISRX gN1pHOtq+9W091KNon3FFuB2oZ9ahpdC3ONkbgyrL+6DV26IvR2G4HB0ESI3yKsknSM+ eoFw== 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=BbrXHe4TuE0NBrPENrKF1IzStufZIMcrykE22Tdi098=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=N/3rnfRzvKLFqaoR7pPLcmvZiHgKhSdnNLy/XnuaBiSHmJ79l/sFtlCtvwkYCo+1/9 PuTBBKVEhp0OoNCiMhbVYpWDO8vA3Bq/TOvvwHRsl4zzN8hML5lrKp+btW0nOlMaSWZJ 2ZIcVBzfo7ptDcBWij5Q3v/CrgiWgat+k6NEFWH7LmSDGpZzG2IYFbBSwLXF9IgSlDBQ N6FHUzF9XXvBwutNx3nhgYF8tUp20P8voe6PKwmLtnGn2OcXvrkIpO7BC5zRYWDTH1b5 ozg3+KdJG2hXNkS9pSuPsiXpkzFcnKEkc4XqUu0ErVkIm/p26U2p9EWBa5rIA/IQqCZs bcTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UI8rGmqE; 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 kl29-20020a056214519d00b0068cd964819asi6094752qvb.392.2024.02.19.05.59.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:59:46 -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=UI8rGmqE; 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 1EDD2384CB9F for ; Mon, 19 Feb 2024 13:59:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EDD2384CB9F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351186; bh=BbrXHe4TuE0NBrPENrKF1IzStufZIMcrykE22Tdi098=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UI8rGmqEtOWfk5AsQHMGa3hD700ZxP8QXaRDn3kjEQnDe9OfZWHKHherSON9JbjqT zmblApRVKJqkoDSKgmLfaA2U1jBTHkBzhrTLsudfHkczJ9hRqtNDWikskfcQz3O8ad u9Qn1BtcFIVKUoLd45yAUO5BihTvY20pFZGX2LeM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 1B3E538654B5; Mon, 19 Feb 2024 13:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B3E538654B5 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 1B3E538654B5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350719; cv=none; b=b5cgzjN3DBwa++sy8ibbTwWvJHRkdWi6PDxobwBjhUl46rOVhzIo2oiuD2SyhBqOk6qZHhdtOS7UDoJm9TQh24m5HYwrh/a7t5Ibtdpzv6cngb5mBnJYVkrMIfWlHGR4B84skUhf2ymoc1JETm60GPcXgKt5knWtSODP5OZNfdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350719; c=relaxed/simple; bh=fmShwV45NLcYcsBYWMj1K2esgnUNIB4p+ChCFNa+n1c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dBMvyOe5awI86lbVIaIfMtpZcU6BJftlArZImnKriZb9Q0+vXg0In4V9M0gaqSDpTK9DA9CKfExfzL3rUbjVDOTIIhhjahl7EkleMmzdax/2HztIL3kzecRRAqi/e0oa6wViGyvozGHc9yLhDqpr9Da8DApw9zG2ZeA/jFWLS0k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDpYSl015911; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6dpexjh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpZdq008917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:35 -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 41JDpZRL001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 03/22] c++: Implement __is_volatile built-in trait Date: Mon, 19 Feb 2024 05:51:10 -0800 Message-ID: <20240219135129.3635809-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: -qbY8clT2GT99z1YpbrOKHnZzJAZRUiv X-Proofpoint-GUID: -qbY8clT2GT99z1YpbrOKHnZzJAZRUiv 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=689 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1786112119857678566 X-GMAIL-MSGID: 1791336053844585880 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. * g++.dg/ext/is_volatile.C: New test. 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_volatile.C | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8b7833d6cae..91ace54cac1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3860,6 +3860,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 36faed9c0b3..e9347453829 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,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_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0d08900492b..41c25f43d27 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12532,6 +12532,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12702,6 +12705,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: 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 e3640faeb96..b2e2f2f694d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -158,6 +158,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..80a1cfc880d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Mon Feb 19 13:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296360dyc; Mon, 19 Feb 2024 05:57:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWu4GHNvDHuxvGv4+mmLoLexRtchVVEt3q1kP1vSz/vZNpETwfJahrvqzOPhCQNemmRR66Q+JWwYQAAu+73znzBK+PSUw== X-Google-Smtp-Source: AGHT+IFj67OUGylf6ZuhCz2AAP0gt/RtbBvyNQnjsgJYpg4MiM/dVjgYH7x2AwjbyNeVR0Nl83jM X-Received: by 2002:a05:620a:134b:b0:787:519a:252a with SMTP id c11-20020a05620a134b00b00787519a252amr6390649qkl.35.1708351025295; Mon, 19 Feb 2024 05:57:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351025; cv=pass; d=google.com; s=arc-20160816; b=GlWRwtLxeHROEJ3FX1RdLKLBGfMEbVIf8vW5xoFe8iyH2gSd0ftXfdnxMUccLksNTv E3yGCLFPBgXS199NUIWTTiqy6lqRKsXEKUDy2l5syBkGadD3jI7vGKWQoSnK1S8UCOJ6 fErxgSTvTnth9Jlbx3zFyQRKuMGRv2UgTwHnu1DtCDMa31qohq0srKsVrVHSPguL/I4a JFiZN0DR26scErqGSPT8zWbOiVAf7JxJNLkgZb1zAQE7gR9RKBiVyO36mIprNHzNRRDE Z5IX8ZmW5iBi99FeTzgSBocQrpeWpbfqOb+d6OLzzmzOettIU6VhpcB/+FC9dxT79Lc4 o7eA== 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=ysf8m6lP/8/PGBY1lK9v689ejogPiG52yf1gUrppZnI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=k7Zg+9ue4cueaS0IWBTAErajyPgtZXvYZ2nC9MNkWFpfwHexQVH9zPsPn0UW3zXWTH Q8HP5aEcZAY0jIn23rVX1byBGIhIwx9Znn8i38C305mCyJe8v5y2htwPTYAxFm4mwEHC NRBVybaWNlfSV2tO3hv9v4wtBAhLvqs5MYIlfx69zVpNCy5fRat/nV0XyM4lIlNjQpVG HkwzgUCMcH0L5cjHe0tfJ22VwcnO+hcf9Qk3Z5+FSP5Vx7ULuERlMdTJr0PeS2saoOM8 2Gn9rfEaNTEpVU56aiBkqKIvh8h6Tb0D9AOsQ0OMUW2HauCkfMErTByRuCnii5UAu0TI EALg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DtQRCgg6; 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 vq7-20020a05620a558700b007872d315cd7si6119280qkn.301.2024.02.19.05.57.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:57:05 -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=DtQRCgg6; 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 E8E203865C2B for ; Mon, 19 Feb 2024 13:57:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8E203865C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351024; bh=ysf8m6lP/8/PGBY1lK9v689ejogPiG52yf1gUrppZnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DtQRCgg6S64iwatI+3kOoex6pYYR+f/vALGuediORvT7L5UTtJKi77SapLFr6WzJv PjtWs747s+CfpE4OaGFmbt7C8Byw8qGz2bJkO9YwFE8MccmBB6kKnSYpBZTcwO1r/T WjXdY9ciwV9CjNR7LEqLmMSScWbKd6IZ17SU0sjw= 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 8D5A43864804; Mon, 19 Feb 2024 13:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D5A43864804 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 8D5A43864804 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=1708350702; cv=none; b=Caf6hhkbxQ6s4+awp85c6M9xXpALILP4pXm9K/13mqwhNRtuuzA5EI3uo1L/CwOJiAe+pR7J5Rs39ePo7KA6JsFA/zZyXhbXImrmNJFE5tdYQfZZNK1iUH0sGsTRtzde37WzyD/HS4NXapNj67nbYES7Ldp97IhyhHWmaWdBzBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350702; c=relaxed/simple; bh=H6zOVUl8oWGElE96ZPU7Yajgdu2XoF7FbNqhYFYoXG0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IZN8pBnWieLjHM4d3NMaDeRvpdSdiT22/SKSht/9oYhXt1c7nB3VIh6nZb6m0bWEt/ZQ3LnjXynWdDObhOLYr7+HDJ0x/i5vsb+OmHDQpn5vgwGTFV55u8i2GhB8/steAYZh68gKeLIzRQn6dDg3WfZYDBII2aKH9hdSj48H3NA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDKOAn001468; Mon, 19 Feb 2024 13:51:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb67mf21h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpZqk001135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:35 -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 41JDpZRM001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 04/22] libstdc++: Optimize std::is_volatile compilation performance Date: Mon, 19 Feb 2024 05:51:11 -0800 Message-ID: <20240219135129.3635809-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: C8YLE5GR5U7lZFEBX7P_Loi7lF9hW5lG X-Proofpoint-ORIG-GUID: C8YLE5GR5U7lZFEBX7P_Loi7lF9hW5lG 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 mlxlogscore=609 priorityscore=1501 mlxscore=0 suspectscore=0 clxscore=1034 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1786112126491765165 X-GMAIL-MSGID: 1791335885072577536 This patch optimizes the compilation performance of std::is_volatile by dispatching to the new __is_volatile built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_volatile): Use __is_volatile built-in trait. (is_volatile_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 6e9ebfb8a18..60cd22b6f15 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -851,6 +851,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) + template + struct is_volatile + : public __bool_constant<__is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -858,6 +864,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3356,10 +3363,15 @@ template inline constexpr bool is_function_v<_Tp&&> = false; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) +template + inline constexpr bool is_volatile_v = __is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Mon Feb 19 13:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1303982dyc; Mon, 19 Feb 2024 06:07:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWRFE2+ghmpq+7fmpCM1XQaOVBRa6KPG8gvlq6+S0hhAvYe1seiOCtGo1PIct3i5XNuJSOxZjfPeislgTCRyuO4C9qAOw== X-Google-Smtp-Source: AGHT+IGsOgjlFMpNHA52k9gMiCsY/8xJtOIlgC76JpKsn2HJUZeju2EM/Wd+UUP99TUdpeN+e2cF X-Received: by 2002:ae9:c30a:0:b0:787:6e99:a889 with SMTP id n10-20020ae9c30a000000b007876e99a889mr1374115qkg.37.1708351629254; Mon, 19 Feb 2024 06:07:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351629; cv=pass; d=google.com; s=arc-20160816; b=zVAO3Qbbzf5moPnYey3d+M9G+7kTGuuNMiEYBYDl8OJyHX//rqFEcrHCppSUiKm3Fy Fu6XIMVpYSkJf1GfsZK3SKldHsO0cS4Iw9/Ug0NJ2eo5wW/3Ni9XYYKha22O2eYszgwI TXrd2cp+Ve+7y/2eNUmZ29jc2kHkDVs692/sS3pN+chz70UsyVHNIu6uHHSAV99rqab4 ZOdZtwbLBhhoss4EWGDZJJwiNwspkdo9jwFUKqra5tW1CH2dXyz8VxwuCXyP2SvXmZ+V TRzEgR737Tmeyo0LHYX0ZlLnQ1saKo0ULOec+0MWP4A+zrSP/3tvr8whdzSQs5M85z9I d0wg== 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=+7op3MVEYwYdNw5EcWTJTv54L7YkBxOz68cYwGFZraI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=tDFRVb8lur/PA6CsSK0bOQjbh2sNxPbDFTv2Csns9uZDVFbPzWk/Ek+Ww3vq8QNebw 4HjyH22okxVN17w5Dl0uR1ZiEPu9ZNQ+6w6vsSsQa31TZl91j++uXwMxFWtIMxVUT/AA Q3CUasjPzh7Nnu/UjX+Hj9l3qtogYQxoHE2cqbRD2c01QSuCtga/cp+Sr53VH9jy8SH7 eYNChY7pQBTHfcnujBHIssldDKvS30c9egFaP7u85I71cBptlB4jobt47NomRWI9p4Gs 8FNykpNwfzIOGx5gBbk7N5Wmtm5ZLt8skKvh/n1tFAyQS6uOUvRmSzTVhfbdzgQJvCQt CG9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s+NFNm1A; 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 a5-20020a05620a124500b007872ba3e220si6415349qkl.536.2024.02.19.06.07.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:07:09 -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=s+NFNm1A; 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 D8E66384CBBE for ; Mon, 19 Feb 2024 14:07:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8E66384CBBE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351628; bh=+7op3MVEYwYdNw5EcWTJTv54L7YkBxOz68cYwGFZraI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=s+NFNm1AwiHbMPKzHeO5+d55ycKi4OUjinWsUQJwUMVuYVdX6hy/YsUubYA8AWOj3 mRdLk7odrFRpld3uiBBNeu5q6cQB01Jx7KcXZ+YEupGeWnh4wwsahF6IjkoGadOqgq x5OVHcREC1S3sjzAly4nxON1YQ0ygk3TBIFm1S/w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id DA0F63865C36; Mon, 19 Feb 2024 13:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA0F63865C36 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 DA0F63865C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350716; cv=none; b=P/q/UieSAnWFOve7G/7e942I1A8yv5+u4ftZOBbQpn8mqRlyUJJk7NACjLUXHJJE6SedcMgEqugOd0dEY8vU9d5Ed4+N053fkn5OlqL5nUSbmnlcIWS6422fuEcaO3Av19vB9JiDmInScEir12wHEOllTy20TwTYZjhkpK5F0OM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350716; c=relaxed/simple; bh=vQr59V5Yw0W6PP3mLRqw2ATEdMKnH8pjId2MEe/vMXk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XP7jjK87AMrp+u7Hs800XVO5yydfZpr/qignj1/k+0fFw6zYWSL1RoqfCyCOQeJ3mnIOGr3DuqJ/vWumr6yJoxGze8fWIWN+ZGNsKzQXFeT7CRRq5YaPXoSM2+TfqRqE+/XXISNuOBig9F92Yk+llKegt2Avs/pXyyLyy3c0ZMQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDpq5m031117; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6vpxv5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpZro017815 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:35 -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 41JDpZRN001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 05/22] c++: Implement __is_pointer built-in trait Date: Mon, 19 Feb 2024 05:51:12 -0800 Message-ID: <20240219135129.3635809-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: oxMQXWj7cf2T2ckQ0Q_SHAt7X0sJ-otc X-Proofpoint-ORIG-GUID: oxMQXWj7cf2T2ckQ0Q_SHAt7X0sJ-otc 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1034 adultscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=734 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1786112185994066034 X-GMAIL-MSGID: 1791336517531525766 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. 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 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 91ace54cac1..22cabd97cb6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3827,6 +3827,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e9347453829..18e2d0f3480 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 41c25f43d27..9dcdb06191a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12502,6 +12502,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12701,6 +12704,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b2e2f2f694d..96b7a89e4f1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -125,6 +125,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) 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))); From patchwork Mon Feb 19 13:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1297891dyc; Mon, 19 Feb 2024 06:00:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXZaokJyGyDG0mZ5HlhJtOi0UaHm9XqMeiQNr3DyYsR+TfLaijNlQFSBtZpWHSyE7DedFqv72ok1gEAoUnFXi6+q1Xlrg== X-Google-Smtp-Source: AGHT+IEi2DgCPOvgjtWFKiqHo7GPkiyRyzxEiMgs9a0cib5KJmhEh2lkJpoOfH6XVWZhM349+4hl X-Received: by 2002:a25:bc88:0:b0:dcd:3ab6:2c6d with SMTP id e8-20020a25bc88000000b00dcd3ab62c6dmr9798653ybk.34.1708351217335; Mon, 19 Feb 2024 06:00:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351217; cv=pass; d=google.com; s=arc-20160816; b=zuSV/JUCxHQjBx/aSgwJPV1TXBSFusqVtQT1Dzrzm8uf1V823OOHVtXA+MS4Nwg0/7 yR1Y0i8I9d9td5xl2Ksd1jznRtucr5z+KTC48p0xq+OZxNIlVoAJbfwevRjfcUBECyfK 5Kxh9RT3SPMWiGowiLPGt/AyMcDAcOBMnRq+B5585szDJ4GMMs8BVAqX5+1u8aJbGh4L DwiUC+betuZtEea98y92Vc6+ocvsWOMY7oiyKT5FgFHdxdfST5cZXSUaipU6WpdR8WOc e2Dl0w/BMBalGnpgrrTI54t/pv//4ZxrLqdZStJlV+jRycxv6bI9+HVlDJQvurK/gZeJ KH7A== 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=Zq9+eMB8sN9tgH0GGILxXRj/nGFmjQ69hMTRm/kNCnE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=Uq07bGSYOHD+3Qv16PuFsju74b51sT6xgUUlBBaGYUfmD1HalM/mY4nwPf2EBh78aZ wVyulATuaIZeVLlOnpXlbQ52yxLAmW6frlYXXHZbiPmnEC2eCgpMAkNq5qfrBhL5z0FR yiVGrPInbCGfeJTB5NQIdQe+NG1RiY8bsRW8Bu9OeK4T8xqRHWt2ZYjswbdHxrqMIWKc 67gV/M84Fp584ZY4hQylXGnnLju94sSHnhSUE7b4p4wOY8zlX5Jl2unV+M4fuMKLi/q4 8L0z8f2WYi+lCvZwFSFZYmw7pYQPXJ4+GTwclLNFxmyAH8NR3NDLzjVxkMSJAFJ9/wcA L10A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vJqECTa5; 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 a17-20020a05620a103100b007876a589548si1780201qkk.321.2024.02.19.06.00.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:00:17 -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=vJqECTa5; 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 C512A3846461 for ; Mon, 19 Feb 2024 14:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C512A3846461 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351212; bh=Zq9+eMB8sN9tgH0GGILxXRj/nGFmjQ69hMTRm/kNCnE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vJqECTa5Fl/ywEsfjGlolMiqoOU/5H+zeu3jmiDBGBFYEiDTZPoxI3S0AGptlOqO+ 2gZOP8m0T+sfCAHP8UJZynAssITcjbgO8vYpu6Kvnoqu3w0OTYAnXZN2sdTtV0ic6q +5xTjU502KzIO2r1uAca8ojeUXYny0bhJmGBOavU= 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 9353B3865491; Mon, 19 Feb 2024 13:51:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9353B3865491 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 9353B3865491 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=1708350705; cv=none; b=l3n3VnA/fI/c3bLgLlnqRUmWmqbMh7MMxai0HukyR9rE/DlAymU0+V3xFX7IbkZl6h5Oi9aWBIYey+0Ol6PSzUd7wu5OZmhstuALrxOs5s3qGbNTufaoIpm4o+qz+u8eTPjdpcq5y5/yepF3qQNYX4De+NM9D1I8E7dluM2T9C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350705; c=relaxed/simple; bh=0j7pGqX1dyjEBzI4/kraerESh3rtXiAuHvwEtDSmWUE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=n4gnoSNMNJyCt7GYTTftHS8pwmADueU1JB9Jc9fmlo5sBzwbYhz3mdwpmWVqQ3AlGv3OHv1+qS1fX+fobNWl0i1OJBBZVcsSNV28qA/EUQvg5tZ5kUHhwXhdmf0WID714df9J4AoSkKFYHAiCcatVv6VMt6/Oomewrf+4KMaXd0= ARC-Authentication-Results: i=1; server2.sourceware.org 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 41JDpPRZ031470; Mon, 19 Feb 2024 13:51:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6qmewyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:41 +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 41JDpZvl031678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRO001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 , Jonathan Wakely Subject: [PATCH v7 06/22] libstdc++: Optimize std::is_pointer compilation performance Date: Mon, 19 Feb 2024 05:51:13 -0800 Message-ID: <20240219135129.3635809-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: q8dNZpR-9yNYZrE-FraXDUTJpvG0wO15 X-Proofpoint-ORIG-GUID: q8dNZpR-9yNYZrE-FraXDUTJpvG0wO15 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 mlxlogscore=374 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1786112186161256731 X-GMAIL-MSGID: 1791336085942639193 This patch optimizes the compilation performance of std::is_pointer by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer built-in trait. Optimize its implementation. * include/std/type_traits (is_pointer): Likewise. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 31 ++++++++++++++- libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 59f1a1875eb..210a9ea00da 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 _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct __is_pointer : __truth_type<_IsPtr> + { + enum { __value = _IsPtr }; + }; +#else template struct __is_pointer { @@ -377,6 +384,28 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) typedef __true_type __type; }; + template + struct __is_pointer<_Tp* const> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template + struct __is_pointer<_Tp* volatile> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template + struct __is_pointer<_Tp* const volatile> + { + enum { __value = 1 }; + typedef __true_type __type; + }; +#endif + // // An arithmetic type is an integer type or a floating point type // @@ -387,7 +416,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // A scalar type is an arithmetic type or a pointer type - // + // template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 60cd22b6f15..6407738a726 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__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 @@ -3264,8 +3278,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__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 From patchwork Mon Feb 19 13:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296668dyc; Mon, 19 Feb 2024 05:57:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgMSF6Z+cNIqAN8jDl6RJ35fvAa1iAhSJpN3YqTzmokR+peMipJ/1ZmtNH10rRKPZfZ+a2vrBYfCeTW9j90Z02iyOnXA== X-Google-Smtp-Source: AGHT+IF+pfGUnYb1O0/oJ3A4xWLdm/CXt5e6o/glWzRU3mWKxyCdqZl4BV0Lv8nI+8BCCobvwlLC X-Received: by 2002:ac8:5841:0:b0:42c:7e8d:9958 with SMTP id h1-20020ac85841000000b0042c7e8d9958mr17008603qth.11.1708351068796; Mon, 19 Feb 2024 05:57:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351068; cv=pass; d=google.com; s=arc-20160816; b=wN68hxR9LhQiQu6MLqVQRKMILEaotwYSmEfSRG1qKU4Ocpa8arlVVc88j6B4I1qVS+ 9itRf9MffGjEql4pZKV5B88GAH54PKSqImveys/PoIR0qzxzjHvXaRfttul4tjSLxqeS /lQ8YEDhtGV0L/VLbM7mORR56bcw6aGM+sejh6I99k9Ajsj1Lh0sH2oljuDHyqtmO2U7 fqHQ0UTEWvaPKl6Ce9Km9eDd63dx8h+xL5SkXTm2SZ9zepvzCsi4hwjbo3e78BN7kvPl baA2ruRZf4ZptZMRCH4iZ9ZByeY8HiprMz4NHz3/u9l0jYAdOfOwN2FR+IHGVReM8zhe 9aIA== 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=/MGYgCib8rDLdjqoPq84fmyosS4ueXYdEkUMtX1lQ5I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=KAO/nYOujAO3hfxgIm9r4AYrdy8lJy3OIMEEUAMJifiq/zbWv/Mrr1cXdIGLwilp+l jOYn+W+wY7yTfo/EZIKPfiyj+RoahMte/BBPeSWnSitw5w4K8GOUiytaHL21ej9WRJJi B4mTMaFxCqQsaRtPIpjnQB0vCRHqLF0cEyjqKZHR9wpHKCGqxujQcVUv0GFqerujMGW/ NtcS3FEks7y75F0rMbWY+F8qRz7J2kYW4LHZWNUqj2LKU2vRDQH4b/np+zfX7XjQ/VKj gjPtGM0Oh4iWvV11rmvIoCujvIwrKhI59x6m2xDTyhi/pM7TwpBCDa7lIKQ0TYsFjOYD sf4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xBkdgsiS; 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 e18-20020ac85992000000b0042e2034bf22si502323qte.234.2024.02.19.05.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:57:48 -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=xBkdgsiS; 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 5581F386C581 for ; Mon, 19 Feb 2024 13:57:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5581F386C581 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351068; bh=/MGYgCib8rDLdjqoPq84fmyosS4ueXYdEkUMtX1lQ5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=xBkdgsiSVZ3tlP1YCc2/gIS3M3mwWvaODp+uzm1kJ6Vo/ujigQFKw158oiiliXCuE ZAh4FtDV2PTTazmV2ZyVshEDEaiabdoXCu+pzRTZ1drg57yjoI+q/b3+CY/sqFva4y 8sFcrJ1EJztQZcnR9LX6MNNQHqRUNYVgqDECYm7I= 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 041F3386583C; Mon, 19 Feb 2024 13:51:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 041F3386583C 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 041F3386583C 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=1708350713; cv=none; b=MxWr3nqxh62LwhgvN4Lohqf1LB+uu7RaeLi8EvFM8+SpEwjBHlAZulqkUwM+FcrEuVelGdlBMmGJYXLNzxtKtv4HDtICCNE/93rK5WqFsnxg+diqckz1L/zWEeBYbcHXnWscbPpGaR5kz2Qts7aFlzzQwP4/hNREhaq8xa0OGrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; c=relaxed/simple; bh=gtEsOvhgLgsyNdeNEfnBGGO3waj3gKlyhHRKeqhYo+Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=va4W2xtbiTEUlqhIlRRixa5AV8dxiZiM0Kwjyg0Wr/QbbcohCz5Exu92X6DV0XO9CD7vdj7+/aeMwCAvfFIhMS/v1X0CaQSKsKfQvhBGTAs3nLnQKTUsoDK0L0jDC9YSsZmEZyJYntC4LAJfNJyiBxNnHfD4zZzILcvXufWge0c= 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.17.1.19/8.17.1.19) with ESMTP id 41JDXQCM016146; Mon, 19 Feb 2024 13:51:50 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wc503gqs6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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 41JDpaWE006477 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRP001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 07/22] c++: Implement __is_unbounded_array built-in trait Date: Mon, 19 Feb 2024 05:51:14 -0800 Message-ID: <20240219135129.3635809-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: JMEZ9-t1EnfkfidZDcG1lIiv21vmID82 X-Proofpoint-ORIG-GUID: JMEZ9-t1EnfkfidZDcG1lIiv21vmID82 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 mlxlogscore=617 priorityscore=1501 impostorscore=0 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1786112219523462016 X-GMAIL-MSGID: 1791335930354797850 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. 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_unbounded_array.C | 37 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 22cabd97cb6..62b264e4757 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3860,6 +3860,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 18e2d0f3480..05514a51c21 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) 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_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9dcdb06191a..1794e83baa2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12532,6 +12532,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12708,6 +12711,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 96b7a89e4f1..b1430e9bd8b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -158,6 +158,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..283a74e1a0a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +class ClassType { }; +class IncompleteClass; +union IncompleteUnion; + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Mon Feb 19 13:51:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1294599dyc; Mon, 19 Feb 2024 05:53:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV0nHn8fr6m7r6q0AVrqxTKxxjBrvsIJye9hEKDw50HMaCVNUeGdxUx61xYZOFFZNsYqa83MACYPOKSDxRjWh1yxk+JQg== X-Google-Smtp-Source: AGHT+IHu4i9aWf2OOGPpfCEqZ0voWMzYKp+StXHKNpPLZFrImBbEV0SGQ2OAYTQt/Htw2YwUdMdf X-Received: by 2002:a05:6214:460a:b0:68f:5fe3:a90e with SMTP id oq10-20020a056214460a00b0068f5fe3a90emr7307923qvb.29.1708350807402; Mon, 19 Feb 2024 05:53:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350807; cv=pass; d=google.com; s=arc-20160816; b=OX2Ho7PEuf1QeNEIFbDwDlTmOl5hm22cprkHoZyKscDFkotpnk0VontxmG5UyaIzWh bKSSKQhL6nDXgio8qPkV94HzxY8z+OFisrrBNW6bzbPHm6HdPVJU2craYlE8X/LNhBlL flElR3bf83g3A9UMVZAyCYSzrxflVMN7gaBotcPoVGupe4eBNRJrQ1WWoMDpxk8XeJ+F dR3h6Qz5ZuaA2W+fynvvdvlbVwsxaEc0xVG6u9XardL/8jfI/3ebQ1XShQTgynjKb5G1 0zB2R3PBlHj4CQsxGs8oZua8IiZfByJenec/nv3ydxm2X4y58UCFUZhtDOHHC6gSFl0l YdUg== 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=QYugRasLyMLk3LT6NMwu3UR8R5wXBiWa7MZ/JvH9Kyc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=P+/+aGHnNKVwAfICsJTREi0/Ot4gqSK4acGl8DVCw2Czbh8kDNYawnK8Zk6oBSHbGO O6M1MY7f+IbJH7nZlliphLyu5v5Sf3svGti1MAIPBWKoHJKyqN3w/gZNgzts2UQKxoEP nW+v9e77S0qmAZq8iW04oc4dXfP/bnznGxt8R5TGG1wii1udDpyId4cYE6wyNeadG04W 0C2n8UjiIHheC4KkfNiq+mhAAP3XYJEqcMlrCgh0TWLmjCWgx8N22JAcllcfjZ7IZ/xi XMs6bnAOf8ddQMplxnrDUbYWeEZRjloTnO6qiQq+t4e3utZDyO9VMOomZMDGvTY0LKzy Zoow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=weKt6WUs; 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 t4-20020ad45bc4000000b0068f6f85b1e2si2189253qvt.543.2024.02.19.05.53.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:53:27 -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=weKt6WUs; 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 0F6DD3864809 for ; Mon, 19 Feb 2024 13:53:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F6DD3864809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350807; bh=QYugRasLyMLk3LT6NMwu3UR8R5wXBiWa7MZ/JvH9Kyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=weKt6WUsmzCAT+VciLAbPD0LMfbt5MXk4jrQp4S794V5+09vDhfnzfArTu96VJIc3 1wItTZsWzJePhFb3IL6M1V09DOdCHvdhnYd9A/z/nuC6tm5lNxl0K47D5CAat7zs9i V4NMjdCaycxUHZpLFlEIOhw78iZtQh0LCfFJhqiA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 18E51384F00A; Mon, 19 Feb 2024 13:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18E51384F00A 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 18E51384F00A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; cv=none; b=ex3eNJX4chvjIsbfgNZNrNsjYC2djflT85NE3gnnN3lU2c1enryaDxV25fE4uAI/WFRBsVQZ/IToY7gsk9Bl+UPjAKnqmLAq8PTvinyIrDZh4Wc/RPWc7ZPSAlW6EY+NXTFhThK+nHW0WN3dR9cCB+lVDyjqejz/CYnlQCIxS9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; c=relaxed/simple; bh=fgJcJYLzf/As3rlsk6dSpoHw89Qd6uC0qFj/SXaILuo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JFVF3/jaV/jVRkYgFHxSixcz4tuhYVLk2dS1xT/EsxHu/8+vVU6Cq1fsjA2pyFN6Fp/+AqR9PgM2N5V7YB08RChP3krA7ww+3rYaRbH7mW5mn8PRNEyWsw8YHWk7doSV6D149AWRx/N7RB9ZBFYYTMowz4p+alQZQriLFAzK5I4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDmnkv011923; Mon, 19 Feb 2024 13:51:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6dpexhp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpapg001136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRQ001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:35 -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 v7 08/22] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Mon, 19 Feb 2024 05:51:15 -0800 Message-ID: <20240219135129.3635809-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Vaxmt2aT7zEtKKL-9ZkCe-otP05S0wQq X-Proofpoint-GUID: Vaxmt2aT7zEtKKL-9ZkCe-otP05S0wQq 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=405 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1786112256931161952 X-GMAIL-MSGID: 1791335655848832737 This patch optimizes the compilation performance of std::is_unbounded_array by dispatching to the new __is_unbounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unbounded_array_v): Use __is_unbounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 6407738a726..c4585a23df9 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3706,11 +3706,16 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Mon Feb 19 13:51: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: 203112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1301453dyc; Mon, 19 Feb 2024 06:04:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUzSeOLkzQhczMnb//voiTPpMfo85ppnA2B9rpboSgt5K0rLwQbWDh/JKA3Jiiyy9wsqGJe9hCT5xAPvgQ4Cyk4C+phJg== X-Google-Smtp-Source: AGHT+IG4vAjRP/YghqCV8seuoekdLNO936XrkyrUtBIW5LZyhjdkb6koUzJ10/gQ5cA9A4Qrqmjp X-Received: by 2002:ac8:58c3:0:b0:42e:359:9f0d with SMTP id u3-20020ac858c3000000b0042e03599f0dmr6396215qta.52.1708351447890; Mon, 19 Feb 2024 06:04:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351447; cv=pass; d=google.com; s=arc-20160816; b=aHy9a4Q1nnRkQZgEiIt4Fo8MetHOJpO+BOLOHzDjk6ORxIVoo/NKdav1k8cjnOCtJs tHxauR/WMy1JO0S/VQu7PxdPK/O9x5FAGR2O5ZHPFv4BYs43CCLlp/cKeEF7dnNSVbAF 0EiCmlmNKM+uPGRXKnu8r79QU1SwtbaGCjkiQ+FiSWo5TQQJrn/lSIAlF3BHM08LjCW/ ++rIplECgBoCel7KQ+7wOuWSro3HdgJ6r/09XhSV3RW37Sa7jpBohKKCC4fL4Ywaw6o5 iwHho/uJ4lcmVjJDcTuBG7siv3tHNAteyy+ykE8X4tS3bKbLLxjLALlbIh4xT6888XuT i0yg== 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=SAbFBJt8EjwkK+E3Rp4/yasgT4o6VWVMN/9ROSvnMZM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ogOhFuN4371mtM2VqRwTAyAOkclvWTB4+gkb+zUlJ05b/qW4CU2Yl0p0GV6/OLhaB5 e0ufUeoFdbjHhuIBxLjdnU8F9VG6XzOedfRAO8tSOAmYZVlcyHe9v2agOE4Ky5gI/n7H yQxjNJG6f22JvOnDVwjcFVTrWCe6QNrCugJMqe9fMgdyCGR5UdSVtJjq58TXqfbMYp/j QymCUS1v8ZE2X1NJGQml0tOzamx9vhTPqEADw3hAQj1OX9Lvaog+0gCQkEdVdEWSmIaK BNMtajNe3krLpqi7PMYOGaAq257QTrcMCU+2mU7PN9SRIRbEn9Shhn3PqwIKkG4vqwYN VmPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I5Dzh8dU; 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 y11-20020a05622a164b00b0042dbe58b542si6379499qtj.704.2024.02.19.06.04.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:04:07 -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=I5Dzh8dU; 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 8C214384D169 for ; Mon, 19 Feb 2024 14:04:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C214384D169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351447; bh=SAbFBJt8EjwkK+E3Rp4/yasgT4o6VWVMN/9ROSvnMZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I5Dzh8dUZoyJ2uFTrOCuH0P72EGiRPnGcHtFBCzRkx8nJ/Bgl/VY9W8uvB4DZEZYj q4qcyj0NdtG5rVmC0Ez9yDmNQc7HPnx9ZPmtcv9TYM65AnHdEfJ08x63PgTzeJ1M+h K+NxSpMbbhsmnRDkTSnRgEbXywl9i+6HM415EiHU= 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 483EC3864C64; Mon, 19 Feb 2024 13:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 483EC3864C64 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 483EC3864C64 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=1708350719; cv=none; b=XbZc0URD2AzblWyBu5ZIpZi5Xsz6z4tbNO1uvOuFrelNDCeK1szZKq52NE1CrTOQcvbPfxhcyNcP/Q8D+B0oL9fYetVM/4jaIYhPHnSIewoJsd6G405GfgO9lIK+QcGWfgoTFxo3dmz2cnYOLQLMGtrktjzcx2W71hVvbLHPZtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350719; c=relaxed/simple; bh=kDbVRMUw7tVBZBzIl96qfQxXNMIYlb8zZXYfWumBrl4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xwnChr5aX5VSrd0/KWkgCH+hk43ont06SoryHgcwum3XXMf+jU5sGv7800gS4bgmrCI0wb2nvKSgrRkrEuhIOc02rgla4eEoUlpvcrV6u9vwrWSXXdhA93j24nlPZut3DWSQVm5hmpYZJ6UBKWR67AckIwpr4PX5MwSrxqseHWQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDnRHk030908; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb649f51q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpavv008918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRR001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 09/22] c++: Implement __add_pointer built-in trait Date: Mon, 19 Feb 2024 05:51:16 -0800 Message-ID: <20240219135129.3635809-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: maNNsT_kCgZU_8NhSjg9go_OcqD7kvsK X-Proofpoint-GUID: maNNsT_kCgZU_8NhSjg9go_OcqD7kvsK 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1034 mlxlogscore=558 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1791336327737213910 X-GMAIL-MSGID: 1791336327737213910 This patch implements built-in trait for std::add_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __add_pointer. * semantics.cc (finish_trait_type): Handle CPTK_ADD_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_pointer. * g++.dg/ext/add_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 9 ++++++ gcc/testsuite/g++.dg/ext/add_pointer.C | 39 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 05514a51c21..63f879287ce 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 1794e83baa2..635441a7a90 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12776,6 +12776,15 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + if (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE)) + return type1; + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_pointer.C b/gcc/testsuite/g++.dg/ext/add_pointer.C new file mode 100644 index 00000000000..c405cdd0feb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_pointer.C @@ -0,0 +1,39 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_pointer(int), int*)); +SA(__is_same(__add_pointer(int*), int**)); +SA(__is_same(__add_pointer(const int), const int*)); +SA(__is_same(__add_pointer(int&), int*)); +SA(__is_same(__add_pointer(ClassType*), ClassType**)); +SA(__is_same(__add_pointer(ClassType), ClassType*)); +SA(__is_same(__add_pointer(void), void*)); +SA(__is_same(__add_pointer(const void), const void*)); +SA(__is_same(__add_pointer(volatile void), volatile void*)); +SA(__is_same(__add_pointer(const volatile void), const volatile void*)); + +void f1(); +using f1_type = decltype(f1); +using pf1_type = decltype(&f1); +SA(__is_same(__add_pointer(f1_type), pf1_type)); + +void f2() noexcept; // PR libstdc++/78361 +using f2_type = decltype(f2); +using pf2_type = decltype(&f2); +SA(__is_same(__add_pointer(f2_type), pf2_type)); + +using fn_type = void(); +using pfn_type = void(*)(); +SA(__is_same(__add_pointer(fn_type), pfn_type)); + +SA(__is_same(__add_pointer(void() &), void() &)); +SA(__is_same(__add_pointer(void() & noexcept), void() & noexcept)); +SA(__is_same(__add_pointer(void() const), void() const)); +SA(__is_same(__add_pointer(void(...) &), void(...) &)); +SA(__is_same(__add_pointer(void(...) & noexcept), void(...) & noexcept)); +SA(__is_same(__add_pointer(void(...) const), void(...) const)); + +SA(__is_same(__add_pointer(void() __restrict), void() __restrict)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b1430e9bd8b..9d861398bae 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_pointer) +# error "__has_builtin (__add_pointer) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Mon Feb 19 13:51:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1295117dyc; Mon, 19 Feb 2024 05:54:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX07CTspwOIFbftjNdBsQgRWVlTK6DGUbJKcJm1sxfirzSSEG+VziyvExtiSDFmdG5qZQqxQDGG2xV8T5nim3eROimxaw== X-Google-Smtp-Source: AGHT+IFVXFXL9+lI/2867g0y2qLHu4jwbfpTz7wOk0gKs7SJSsIx27T4OnSCu7ZrdHMDR3Uvx8TN X-Received: by 2002:a0c:e086:0:b0:68f:5d8f:7c14 with SMTP id l6-20020a0ce086000000b0068f5d8f7c14mr4948480qvk.19.1708350868634; Mon, 19 Feb 2024 05:54:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350868; cv=pass; d=google.com; s=arc-20160816; b=X3qkDpQpK+ACeToaZPQ3ALXqrORuzVlPzaUqDFRt+CovDVgU1gU7dxy1vcVRFlkTKG +RwhZQx4vVBQEjvhKI5MkFC2rwaq7XflmjA8s1L3bnH8pBl63y2eKhAoF5Va2+1XTD2u vLJnbvNLDp8Dl1Rxf6kvWz0MoZc6km6YU28690YEtdtwN4nDi1dxtGJfFa5DpYV9chXo mfantP/s3owA7bRxMgAiHzWoZz8tNYuRbGfjqljApaiW6o0sy3SXR9rJ5Z1cuP5Vc9Ae /XvpXIyM6oGiaJw9OUjk075OEqnKgeLwJmFsyB/FVdgN3P2kxsIGKLLi85DH9k5QaVmN id8w== 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=JiZ9B0x6FgiG6MO3MczLWGvheK5B+fEhrXMz7V6EBsA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Sm/4JWo83jWDA8Q1Hlo1+mVDiJWVJurXCl9JP2yzBfsZAJgg/WyGI7jODrq3q/wtRY NxMv1hqkbWV7bUGIGfusJptf3thVVjpypf4dec7jzspF/Utl9QIZ12Oo/AapGHj0GvfE OvPJbmtEvDO1SNiHzU8aBES/FhGWlOMGyGiTZ7Sx6l0uNi6D/L/KmiN7gAWUoatVhDHu Pu4UL/9qZHYdEk1nCW1IU0byLu/8o7W9N0IgR2r86I8iBGgQDdmIWuS4qL8KD1ye6xPV wlvtroJwZmcXRa0hj2G7UsgPNs8XrESF0XMyNSG6QhGpWAhRGy1Yjr97pjsLfDvAG2Do aPZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WhYU1ALW; 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 gu13-20020a056214260d00b0068d14789a92si1214486qvb.378.2024.02.19.05.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:54:28 -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=WhYU1ALW; 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 32569386486B for ; Mon, 19 Feb 2024 13:54:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32569386486B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350868; bh=JiZ9B0x6FgiG6MO3MczLWGvheK5B+fEhrXMz7V6EBsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WhYU1ALWAIst9kW59VKhN9dRfKN+MZLS9ONNVhxCfOJZ77T3Omx6KXDKaMkKLC55U YeMLb4F4mWV623GbFMEY26dwwMkQ7IgVGZdVFvOakGi0YnHSo4hH36a7wI/cC5UCtY jxgyCTRu4XzVFR0J8ig6nZMSp/2LUXcgSFmB1NBk= 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 866CA384DEF8; Mon, 19 Feb 2024 13:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 866CA384DEF8 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 866CA384DEF8 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=1708350701; cv=none; b=KcVKGJUHQbED+0WzicgsEY1Q2MrI5D7F9gTemia1VEl+VeAGR7UrCidO8EgaWKPVhYVxsumNRNntkMQhv3UYsaZ/JpXycBja/mNY7KllQUKxkGQPZ98vdv345amFQSgSWaD9aQa7rc9HBsEsBQXRy4uaPFCQ2CyLddbi6AxPC6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; c=relaxed/simple; bh=VYv1wMdTWXNgPdFXhF4pd+kvnGn1Jz7jNHVAYkCHFiE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kZ5HcrZLrQpFrUmMA+vQcnQDnN/KFXKkSb7uDMAxjro054XVGlg4KwRYxmTvNoqzE6GyuBKdJ10/rpcg2j7NMLcDcpdK/IHbse6+0UPXUCfHYF2TXIKKvxkWM1H962wBfMyD4QmA00S/mAfxfV9cP6V3UeMeMRUeyTUIhs6emjM= ARC-Authentication-Results: i=1; server2.sourceware.org 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 41JDpPRY031470; Mon, 19 Feb 2024 13:51:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6qmewyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpaRK001137 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRS001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 10/22] libstdc++: Optimize std::add_pointer compilation performance Date: Mon, 19 Feb 2024 05:51:17 -0800 Message-ID: <20240219135129.3635809-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: MoHAxwHx_fIrGCqUe4_fuP7QpBONhVRR X-Proofpoint-ORIG-GUID: MoHAxwHx_fIrGCqUe4_fuP7QpBONhVRR 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 mlxlogscore=521 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1791335720463356899 X-GMAIL-MSGID: 1791335720463356899 This patch optimizes the compilation performance of std::add_pointer by dispatching to the new __add_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_pointer): Use __add_pointer built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index c4585a23df9..6346d1daee2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2149,6 +2149,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; #endif + /// add_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer) + template + struct add_pointer + { using type = __add_pointer(_Tp); }; +#else template struct __add_pointer_helper { using type = _Tp; }; @@ -2157,7 +2163,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __add_pointer_helper<_Tp, __void_t<_Tp*>> { using type = _Tp*; }; - /// add_pointer template struct add_pointer : public __add_pointer_helper<_Tp> @@ -2170,6 +2175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct add_pointer<_Tp&&> { using type = _Tp*; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_pointer From patchwork Mon Feb 19 13:51:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1294918dyc; Mon, 19 Feb 2024 05:54:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU8bHrYEStEbK9qw50ZMqxRxwazNZYvIHM8RTvfB3Nwy0rYmw4ae/ewIGEdJaOLbiR1RO6qf7Yc3KWLP1cM7bzzjjXClA== X-Google-Smtp-Source: AGHT+IE1riq4Hb2MO3YBqi8rs3NKDf1CONhTEyPLUF4H5xHFGnBLETIiMDl1grm2A3LWU8WivM/q X-Received: by 2002:a05:6102:c52:b0:470:42a3:2d5f with SMTP id y18-20020a0561020c5200b0047042a32d5fmr5008534vss.14.1708350846471; Mon, 19 Feb 2024 05:54:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350846; cv=pass; d=google.com; s=arc-20160816; b=vBJvXTqVi7PIU9bugGc7uyFOAKb/kVRckfIRSDaxZuOcq9tJxdUO2GrlgimZObFUi8 kRLJm35+cWYo55Xna2TgTm6ZkmwqpmOkouezFn+waSyzL/R4PXioMDnTl7MKfGJlBSOH axbgnPL8xztJ+h6nBqTwmPIHRtJCLVb2MmNgZE4TqUW3JTYU8lNL3BDQfF/mhrCaF2jv EQnL7iHrz0r5OvLeZItHduQS7wOZLpLXPdWr3GDVaLdbM9MOjyXSJbtZUj1P2ey1BWvL oQw5pMDJ88mISRhmhGQpr/z+EmUkkIlmVbol7TQKPmiOktFaPXGbUxqS/ctCt93zv0yk D1nA== 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=AkPqF0DYV/vCJa6fZzr66/usN9PYUvb4qrMfCdmaghE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=J5ECT0Jexw4K+LCB3NApUN62nMB8+GTWgkKyt3NS0O66yIRz6nd4oGV7lEZIRcuQr7 qBXCrsKLbM0tNFlASQGsc+rQiH6WxhFBUuz26pN5Qh5a3IxfK/GcqLzpCiUzG27a8spy fyvckQmegMpdP7g+3wpK+/QV5pnAj0BAb7hKcOQgC4Wuvsx5Zp+mQ1rRAy6/d5gxPGqL ph/jntpo5nzLRf+0s/0K8++2aIEbsV7c0xQ/RY5WHZhStm71RhKFXxp30P1W/34d48mD H1sXmLAV4thSK+zfgXjQczCjAQAAm8VvbGEI26U1ukxrgFYcNbV+011x3oUkqTkCmg9n t2Rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="aqfP/ADA"; 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 l6-20020a05622a050600b0042e04621f7bsi3583851qtx.3.2024.02.19.05.54.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:54:06 -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="aqfP/ADA"; 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 098DC3865C1C for ; Mon, 19 Feb 2024 13:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 098DC3865C1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350846; bh=AkPqF0DYV/vCJa6fZzr66/usN9PYUvb4qrMfCdmaghE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aqfP/ADA6SvKGw9w4aH2h63ClL5b/0N/kyOh4Lw/+bHq9AZ3KvPy8tGv0EihtXfzU ZerIwRAkoHL8a48pyMOuISInQ3p6nGLZfFKqSNyXi5rzCXGHWxsfGcoY1X3agkIV5G i022Le8cEbR9oO8zTC62cphwypAkVe7WuOD9BXBI= 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 822C0384DEC6; Mon, 19 Feb 2024 13:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 822C0384DEC6 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 822C0384DEC6 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=1708350701; cv=none; b=exmPCGu09MlaHHNwQp7QYatoZSTY3ULcsN7xmtqwGMPBzf8dbBtuCz+Es1z/0VWNvJMVsr9onLTkyL3bkq9PGAccFTnd4KqIcXL8hON3kCJLxwKZXQHZBUsE56TTws2ik5H6LzqCHxiYseFMoMTKt8LA/Wwvqdyl2PlJZGDd7RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; c=relaxed/simple; bh=vWHVj+3U2Qo51Obig5crCGtC90nv1gYcl0vjSsiLw9Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YMKO+342505s2KmaVYWBbv79/X6s27sUenoObsJ1m8lc5vnzfsWD+XOwoYom0zopwz6heU9lqoJqPOnzgyQB0gYqb5Wo29pwCY98bPxBWaF840Ar8kCDiD/GAG321yBY6iU5w1nIZsXsweG0bILpDRI/+Fets0Ajmnaa8pklCco= ARC-Authentication-Results: i=1; server2.sourceware.org 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 41JDpPuQ031474; Mon, 19 Feb 2024 13:51:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6qmewym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpaOn001138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRT001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 11/22] c++: Implement __remove_extent built-in trait Date: Mon, 19 Feb 2024 05:51:18 -0800 Message-ID: <20240219135129.3635809-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: kimFISlinVDdyCK65w3FwrJPNPzQkK7U X-Proofpoint-ORIG-GUID: kimFISlinVDdyCK65w3FwrJPNPzQkK7U 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 mlxlogscore=362 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1791335696762196644 X-GMAIL-MSGID: 1791335696762196644 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)); From patchwork Mon Feb 19 13:51:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1295417dyc; Mon, 19 Feb 2024 05:55:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0uJ8UhIs7Lnig1igP1VFFVNnQ2ckP2KU+zq5BBbOy1djqpXwvyTYuQCH9hn5EsXmxZykCmpigga7FKODL54PE2siGfw== X-Google-Smtp-Source: AGHT+IFj3AGRHBIaEP5vh9j3zIsu8Tq/0QvGO1+1zJPAnExIqxPgkf/5a93RidUFbLp2ru4XwDHB X-Received: by 2002:a81:8706:0:b0:607:dfc7:abd8 with SMTP id x6-20020a818706000000b00607dfc7abd8mr11507995ywf.21.1708350910349; Mon, 19 Feb 2024 05:55:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350910; cv=pass; d=google.com; s=arc-20160816; b=0wwJb5YuC6ZMPO5Mg+QqZxP51H2fzlMhY+9FrjUykPWoKRHTOlPVWhT0s94gTXw+Sb XvTZMZTAMs6Xr50yLpCOKt1CpfViSpSIpX4rGH5fdMFzakx4yBmk3TAPIYjsvqLmf0/o +7gSTyUyAOONjj5AkgTFdX/5Uh9PXwffP4vHrjUJRQmu5xeSbMKXyz88jMgAP2CBrqpX CWK521SVdnuCOcSWPMxp4aV0ugF/kNJowOidjg99e2FCFnzbFNz5dJm837p2Rxj0k98h i0BHZwce7JVVlpXG6eAjgX89zkU9yxwdCMcBInMDbbkXxW8L5YFoxVoe5w34y2qFTqDz GvUg== 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=Tx5ITed+Uh47pQDOHhaKfuf6rkKipYwdxTElZnXyEvg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=R7ykbZLU74oqqpg5KFKK2JqZ/Y409+cwWNMO6C19V+iWRYKu4vVohkKSXS/JDaESSy Nun9i+3m8ZJSBFzKqZFCYt92Ai6ZVg9SaMFXIR088AJA5w+jaJKHKA9r94XGGzVdFhH0 gzftT75CbNhMuFh0C+ddelNMIk/DxMUFx+M599owO0JrXr+MD68IObpBtybsyhUNGJD4 PVIl98/AQ6Rng0+IHt6g127sHS1smZhZRKbTmdhwS2U+/quS2xnU96VnCTZgumQAYr/w TyFy2Pe/WJmW+sEDimb4NnHJwrEa9Sx2WZGcyqYFFncVlnJqEMiBdIWdb0kNpiIokgYZ Dvog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sz0jEOg0; 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 v16-20020a05622a131000b0042dfef499d6si4724473qtk.553.2024.02.19.05.55.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:55: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=Sz0jEOg0; 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 0627638654AD for ; Mon, 19 Feb 2024 13:55:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0627638654AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350910; bh=Tx5ITed+Uh47pQDOHhaKfuf6rkKipYwdxTElZnXyEvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Sz0jEOg0n4KiDVQft/DEeXeWISpEFOlvB5D8+uqTxxorFBsGYyQ4k5YilSk+xvlqj QOc6WizoLJQ7CgY5udBnygKgtQPI3kqSTrP1AbzJvBlkCfMqnZdZErZpZhoT/Ou8ag jCdDgYYZNtCWqwnEKXlmaqZVoPVaY7x3zNzk3Ypg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 1BA0C384DEC2; Mon, 19 Feb 2024 13:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BA0C384DEC2 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 1BA0C384DEC2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; cv=none; b=elTwjJOxlpf2GbL4S+I/zgRJpI9aKcpYi9eUx6MfD+3GDEx8Y3+wyfu+SL9xvl6ZSJksENm0aDkK8zwPv5O+Ppc2Mw7MPNA0oRf9YzAU0OXR2GxZwRDwFw6w8aJoLXqKRCT8es/hoDKtTjyY+UFIsREbvqzHsWaftg02wvRtaJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350701; c=relaxed/simple; bh=TtR29RbqI5/S2zhTNSHywl6CX8wHfgAq92kW8Jr2XSo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xYR7lCng/6Osq3rd9EigWHsDIQQXk6mw/8VNmPNdz0x10yFYC93jzBW30rejOWF4edfeTccrLypRRArL4fvMKIg4A5MSeE5QRfWw44fWekTsUsZ+XbGnKurreamKVZNrj5kzyiub2/JnEtspPrAGTQVoYxY/L/Z/wFvAOc3scEg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDoHIr028614; Mon, 19 Feb 2024 13:51:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6vpxv4y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpaUc001139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRU001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 12/22] libstdc++: Optimize std::remove_extent compilation performance Date: Mon, 19 Feb 2024 05:51:19 -0800 Message-ID: <20240219135129.3635809-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wbE1w0UF8dR9WtfEPBpAmxCx-3KHZ9YA X-Proofpoint-ORIG-GUID: wbE1w0UF8dR9WtfEPBpAmxCx-3KHZ9YA 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1034 adultscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=552 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791335764107432354 X-GMAIL-MSGID: 1791335764107432354 This patch optimizes the compilation performance of std::remove_extent by dispatching to the new __remove_extent built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_extent): Use __remove_extent built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 6346d1daee2..73ddce351fd 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2092,6 +2092,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Array modifications. /// remove_extent +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent) + template + struct remove_extent + { using type = __remove_extent(_Tp); }; +#else template struct remove_extent { using type = _Tp; }; @@ -2103,6 +2108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_extent<_Tp[]> { using type = _Tp; }; +#endif /// remove_all_extents template From patchwork Mon Feb 19 13:51:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1302902dyc; Mon, 19 Feb 2024 06:05:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVK7giBkB0kQL7hdGL5M3Q+2XCHq0DqPLkKMD0MDXaePNboGvd+FY92Q5Blt/o/7U5VLZL5CbaWZcX1ScgJAsglxnw20g== X-Google-Smtp-Source: AGHT+IGHFZ2/g7w+YeuPm+yk1aVFkH+WAddcOmEuZi+GIPMz1lQxxMQ8U/LcFuHnx1GsnzLeMOPT X-Received: by 2002:a05:620a:47e1:b0:787:70e2:d285 with SMTP id du33-20020a05620a47e100b0078770e2d285mr940203qkb.13.1708351552371; Mon, 19 Feb 2024 06:05:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351552; cv=pass; d=google.com; s=arc-20160816; b=0r+qx6i9F0DnrWhww8hpNWtqHJIStDvSvVSAFYMVmy3mkBBM4gXZrlBEbUsCuft3/s 9bN5pm96cnNDGVTyqEWtL4GySWjutQ3J1Y155IixVvmIOEwboifeCgxvjL1Ei8QhvYn7 F1M0+Xykz494O3AX6rQuyXP/YULQJFNdPH5JsyTtFkNGEs41NiSfQgn8aORi0X/ha7E6 pcGaO8lRXK1AQnviNB5r0n3nUZGJSVzXofnLvKUjR4aiXavsCHJhrDTDYimh6Wa79Lf+ eAmU2oK6D3gTXhYi23PzjwFsRoWXu/3oa7txvyQ5xJdyT4QR/C3hQVKWE5V0sr/SxjQn lDpg== 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=9NBhFqglH9iXCw+BD1pCUz6SaNW3wh0e/nUQl+MTt4s=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zRGwFnxkQHN1XgL3uqsYG5i/Trz3ytAELyx9tblUpF5l2N0rx20Mm+Pb0FFy/P3F+5 YlVqAjx1kcM8j95aU5d5coS5EC/8Afld1a4mN3QrqnhhdbAIKVOANBfqnY//Id/S6u9g p7wdJXZgXgWHdOUx+ZzhfoiGMTD2o+pnLoqQiLpD/jJWR4/DprmeDpD63XzF5wglH02i 9eEz6NZfeZWjCFLOrMQ9bseA3INaongSlUpczPdgX04DutOmXSKQgT4pkphglQv8mh9t DZtnanttrMhJGnxfpv0BO9zEAx7/PRTpZW97y7+0SYR/W2PGKUuw6N/keUDLVb+nsEhN 3bSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Apdjv1/M"; 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 z19-20020ae9c113000000b007872c5d8e74si6067227qki.708.2024.02.19.06.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:05:52 -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="Apdjv1/M"; 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 0F19A3865C32 for ; Mon, 19 Feb 2024 14:05:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F19A3865C32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351552; bh=9NBhFqglH9iXCw+BD1pCUz6SaNW3wh0e/nUQl+MTt4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Apdjv1/M9RC8dvefHsZFzLFyYYNQWAByIxkikrD6MDELJIrojafZUgbF/yccqQmY7 4pxDobawA5FFs6Hc1BLAe5aHrxaxXGpRxERf7j2PxQxJzoO8l5atOMGo7FM83Exz8I vUk1I4oQyaOYb+ogrNzcmExuSXTbizrRJLCdKNB0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 3CBC2384CB8F; Mon, 19 Feb 2024 13:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CBC2384CB8F 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 3CBC2384CB8F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350720; cv=none; b=jpJhA/2GZ7kAC12v8/LSRAaHigLg8MKebRGTUB2gYTCcW5GmfYQ5Q1BsDGlu3H5eL/SfOeOGkP4ErWv/zy8uFE6a9lU0hBajlaQ/uVSIZda6znjtmeVU3R/ZyNPvdRu0ujUBZaGJQTBfcDIX/lpfS3FSFApRJDMrX0shbaBRhjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350720; c=relaxed/simple; bh=7LL7qMrbvKzLOjtntCZaEUlku+JTEdX8VwiZwC4xLd8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=jAgR/3ubzuolw6LGr0sfgHHTfmTqYVjZkkDxIaIbEsa01Bbsyhl3ORn5fRFqTcBFFwE/w3EV+OvJTeuNpeLm31uF+68iIaMYQU/CCMcfMnoyBkGMIx2GhplBVMUkrfHAFqkjb3p+BaqnkIAeSzKmq+nFBpJOTi+mUG3iattGhow= ARC-Authentication-Results: i=1; server2.sourceware.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 41JDfjC1014084; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wc7s083pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpaPM017816 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRV001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 13/22] c++: Implement __remove_all_extents built-in trait Date: Mon, 19 Feb 2024 05:51:20 -0800 Message-ID: <20240219135129.3635809-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Q1O6tOlPOp4eO_bvi20zwxuI9DmuqxHw X-Proofpoint-GUID: Q1O6tOlPOp4eO_bvi20zwxuI9DmuqxHw 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 mlxlogscore=451 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336437389389294 X-GMAIL-MSGID: 1791336437389389294 This patch implements built-in trait for std::remove_all_extents. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_all_extents. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_ALL_EXTENTS. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_all_extents. * g++.dg/ext/remove_all_extents.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 3 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/remove_all_extents.C | 16 ++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_all_extents.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 577c96d579b..933c8bcbe68 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -98,6 +98,7 @@ DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) +DEFTRAIT_TYPE (REMOVE_ALL_EXTENTS, "__remove_all_extents", 1) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) DEFTRAIT_TYPE (REMOVE_EXTENT, "__remove_extent", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 58696225fc4..078424dac23 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12785,6 +12785,9 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return build_pointer_type (type1); + case CPTK_REMOVE_ALL_EXTENTS: + return strip_array_types (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 5d5cbe3b019..85b74bd676b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -176,6 +176,9 @@ #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif +#if !__has_builtin (__remove_all_extents) +# error "__has_builtin (__remove_all_extents) failed" +#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_all_extents.C b/gcc/testsuite/g++.dg/ext/remove_all_extents.C new file mode 100644 index 00000000000..60ade2ade7f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_all_extents.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__remove_all_extents(int), int)); +SA(__is_same(__remove_all_extents(int[2]), int)); +SA(__is_same(__remove_all_extents(int[2][3]), int)); +SA(__is_same(__remove_all_extents(int[][3]), int)); +SA(__is_same(__remove_all_extents(const int[2][3]), const int)); +SA(__is_same(__remove_all_extents(ClassType), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[2]), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[2][3]), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[][3]), ClassType)); +SA(__is_same(__remove_all_extents(const ClassType[2][3]), const ClassType)); From patchwork Mon Feb 19 13:51:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1295238dyc; Mon, 19 Feb 2024 05:54:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX0tz/LoOqelAN7fqDC9B+C0WOv6u4vQTCPKrkhuMm9U+pbCi6nPkNYjEcf7l13oj1rXn81rgMGr8vqfBrY3swrqrg/wA== X-Google-Smtp-Source: AGHT+IH1ySEVnug/QVsBD5IJFaTsRBvwnFRn7mDV5zAMJQu4M+JUa5NWjcWjqcNXRKygfbzHiJ5Y X-Received: by 2002:a05:622a:390:b0:42d:fe52:8bb3 with SMTP id j16-20020a05622a039000b0042dfe528bb3mr7065294qtx.41.1708350886525; Mon, 19 Feb 2024 05:54:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350886; cv=pass; d=google.com; s=arc-20160816; b=s1yON6NWMZMutp6NHK5VO7FuxKB3+mEzfTBjqZDlWCymfrWTo+wQUPpB7eb0nJQ7cn ELQYQtZ1PLVoK/9IVH4hN1ApxHKFuEAZN+hxzct1Lk0CaEDjH8191Ix8oucoqpJyqNnv gEfi2i8lGeOGH71MHNJU0SA9yzKYObqQSvxmnblUpdmUxbX1eP1HAMVjEFmiXRVKujqM B3MrKQbUorSSbD9DGy478HcIkF6pjVC6sLkP6qkFrAkxMTjPni6sX1HDU7Owi4EYTW1N oaCSO0ZSEiNZ0oxC1UkQ+CnPOIMafhRaS0MFpOm09FaqVGa75gCoh7FZq5NGAB9640/Z bfEA== 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=er6jZZ5SFIqNgiOlZADLtwujTFdoRxcRJew4SiO3pXE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=D66Lhughq3FdPoAZSpftLKX8sDzH/LDFzbs6RpHB6FMuUc92gAKxlCZD8Xs1W4cZ/l hC4ZTxVbo0Cb+fTOH+M0N+Sj1b8AMKw3KkxeJgEI+XotC7JgVhrisITdqkc++l3HN21P cPb5pVyULRSlVC/MNtPJube7WHXcZNHJfJrrZlRKsQwpSofC++EYUYYXzBJ3GXIDQ4fi GTAPAfQS8xJ1NS7CDkP7dpR1MQaNfl5qqveu/4nDut0lvzOO7xiRNnO0pIZY3FTxcFAj SR9NxJle2/WOYCXK+kkMCO5CmAEavtvklrrPfXQO01ioatLWvudw6jcpT1p1szr1AkQq OcpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e72nIf5S; 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 f13-20020ac8498d000000b0042c4dc12656si5771471qtq.781.2024.02.19.05.54.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:54:46 -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=e72nIf5S; 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 21E543864C64 for ; Mon, 19 Feb 2024 13:54:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21E543864C64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350886; bh=er6jZZ5SFIqNgiOlZADLtwujTFdoRxcRJew4SiO3pXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=e72nIf5S0OWRBdbz4Sq798UXp53e1XYD32H+da5Ofl5m97taA9JUVkjMD23mHnSPM WCs9lh7v3voFqCFtol4/Xr0nXEIgNUUAkl0xs4y90yyKXG2mo5ehlHgeOHGpyt43TP lO9btIdIJYOLMoCMrVcf9bF6xtB5/Tmou6fEMeXI= 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 05DCA384CBA7; Mon, 19 Feb 2024 13:51:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05DCA384CBA7 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 05DCA384CBA7 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=1708350705; cv=none; b=WpzdYEVq7hsRZ+Txsftj7xReniy8z2XEzB3D1z1QxYr0vdwyUE5RXOgRj0Z8S+Ud44YuxckiQtw/iG1l/7FNzULiBIDnwLKCan2pukpChDLO8aFPx/eRrUxrr8ktrI1jt4rUqCpIDaG+gl+g8qLuGRCjQcgxRS7b/zdUpERhpzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350705; c=relaxed/simple; bh=noosxmzgtZJ9ettk3mZRSTRchM07Y+bDGUJwAhFMoiE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=adrGbK2nFR+WS3GKL/xWoFolv56pBo3YF+2ZYp7mRrFAJp5dSRLxoh1tONBENqlOlq42G8UbaoHk03RFV4Y78wSFfkz7Lfr8h78HjJGCb7gk3HhKNG/hosdCjpxRBbOhOyOgDPWfSqqX1m8ixuFMO5ZNycnU6rH0Vd2R2YWVT14= 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.17.1.19/8.17.1.19) with ESMTP id 41JDWIBu013161; Mon, 19 Feb 2024 13:51:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wc503gqrq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:42 +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 41JDpaug031679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRW001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 14/22] libstdc++: Optimize std::remove_all_extents compilation performance Date: Mon, 19 Feb 2024 05:51:21 -0800 Message-ID: <20240219135129.3635809-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: epZNcRFgRrv4_0R5UjuIXexJcy0FpAAV X-Proofpoint-ORIG-GUID: epZNcRFgRrv4_0R5UjuIXexJcy0FpAAV 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 mlxlogscore=819 priorityscore=1501 impostorscore=0 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1791335739233839060 X-GMAIL-MSGID: 1791335739233839060 This patch optimizes the compilation performance of std::remove_all_extents by dispatching to the new __remove_all_extents built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_all_extents): Use __remove_all_extents built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 73ddce351fd..34475e6279a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2111,6 +2111,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// remove_all_extents +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents) + template + struct remove_all_extents + { using type = __remove_all_extents(_Tp); }; +#else template struct remove_all_extents { using type = _Tp; }; @@ -2122,6 +2127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_all_extents<_Tp[]> { using type = typename remove_all_extents<_Tp>::type; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_extent From patchwork Mon Feb 19 13:51:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1297762dyc; Mon, 19 Feb 2024 06:00:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHoFfdhbsP3MiZ16Hlx15bXPYy3o8Oyu23E6v1YFBLtwymBGRUxRSadnS974+hhOzP7nr+NeFwD14StOsw8Mzk6HG2yA== X-Google-Smtp-Source: AGHT+IHeT5nRuhMzWWl7k1Sk3gZIdjt5e4D6mew6u5eCQv9IFhNWI6GDI9deo9G6ZhKMISVs/5m+ X-Received: by 2002:a81:4e52:0:b0:608:bc7:9116 with SMTP id c79-20020a814e52000000b006080bc79116mr6080909ywb.10.1708351208377; Mon, 19 Feb 2024 06:00:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351208; cv=pass; d=google.com; s=arc-20160816; b=YK00zf6eATRZjGhtDYtNWqTehEqh3JYnmpVY7gTH8yfyDTHcqrTkECqN2oRBFl9qUU 4w/PSnK81cBK6GBinJYddgXOKIgbKL4TFdSGcKVF1IP0PYYoWq5sgx77xkHNxpGTvCL/ O+digBwPEBHH+sifWb6oiYVszmSH5a6xbgVrUxUMlFlFpdqsS5aqnX3yaWEzhBLovmX6 hNBOmUAk1JlyFul5Zz02sDFmCm7eVkdDWCwBe722CuZEMOUUaPAYTr9YICxTBZm6oyw8 zDc+9yaqBDQNglu2N0V7BP1gyrSt42GVXNuwR67+COTyZpuYMNZzghHZiKNGWrW45slW yS0w== 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=GDtFMAilfS5gi2cQB1DByGMTWM/wn1wLdvCJkd2amIQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ByYujt/2i+UpoKnbNytoDZ1nNSxGIWEkgu5/DF9ciZzt4a/VtOQkltxu1OtNu536TB Hh3WK2wxxW0AFvbV8SteSAUrpJxDmRHqVf9y3N2udDMUezICL5WOugYU/7O4TAHVtFoM 4CLxOoSLMjMvci0Jy0+2AkTMwKUb7YT65DolvDVw23cbXsmDGPgEehVXUJqlwWBakzXZ eqQVSHxdu/uCJ4Eea0n066KDBm9/yn1FoDjeRU/GyRO/kc7ZDVjLR64w0rdOQM3yAoXX O9PryF9rNBvKCcFtd/HPhfmnQl3/W9+ff5OM7R0HP3d+GodqgIo7Fu/wj2Sah9hZ3438 wEKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YdWZLVci; 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 x6-20020a05620a098600b0078753baa31dsi5089659qkx.181.2024.02.19.06.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:00:08 -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=YdWZLVci; 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 1223C386C5AB for ; Mon, 19 Feb 2024 14:00:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1223C386C5AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351206; bh=GDtFMAilfS5gi2cQB1DByGMTWM/wn1wLdvCJkd2amIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YdWZLVciA6dgGqBBcWV4H4+QYR3bDgO/kbiehQTDXWsUpVLlIg6q7K5+7u4rIgEgc NLzo/wablY+OVVl0LYfBxCdvoX/6E0SxUBQvR9ucdyn7tHAZgpT6ZGcoZsARyCWuu+ Gsnad2QLsnjOhxE1w7nuruUeEdM24UD0Vj/wC0fw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 94394384CBB7; Mon, 19 Feb 2024 13:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94394384CBB7 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 94394384CBB7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350714; cv=none; b=KhJG6gV2XAwZXzx1Wzlbo8emylzc/nIrO03tfJu9FU5yAAiebMbnWN8zcyreW2fxlMrP3s88ML1pXEYCCmB/1TSQZe8WrnS49BpJ0dTTtpPjEYQqKhDUp/VBx2UA5iYoSpzOKJkXain+TG95/JonFmFy+mVuqlbUeDEBAtFKPMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350714; c=relaxed/simple; bh=ALiH/t72ZeLC0Tc+KDQhGfZYYsI/l+YYTlZOHR142YE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Z23bJgMqS3E4jJl4CMqs6Z+fObm/j74trWJomP78G7WHssvLcGPs7whud6jV3lgZjA/LhumxYxo0RwWkIDM/jPdQ3Lmb5gguPNul7gh1gu229dp98sifK2/l9vBicu4e+O5Gpo1kT4E/fkTIpBBsFB+0U+9PF9eHhp+YAmM1CzA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDl2LQ008871; Mon, 19 Feb 2024 13:51:51 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wbd09du8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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+UW24.02) with ESMTP id 41JDpab3004104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRX001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 15/22] c++: Implement __add_lvalue_reference built-in trait Date: Mon, 19 Feb 2024 05:51:22 -0800 Message-ID: <20240219135129.3635809-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: De42KMLQ4Io8YqGcFw1bIsNxDrhERt8n X-Proofpoint-GUID: De42KMLQ4Io8YqGcFw1bIsNxDrhERt8n 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=786 clxscore=1034 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336076562000648 X-GMAIL-MSGID: 1791336076562000648 This patch implements built-in trait for std::add_lvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __add_lvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_LVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_lvalue_reference. * g++.dg/ext/add_lvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 8 +++++++ .../g++.dg/ext/add_lvalue_reference.C | 21 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_lvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 933c8bcbe68..9a27dca4ea3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 078424dac23..05f5b62f9df 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12776,6 +12776,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_LVALUE_REFERENCE: + if (VOID_TYPE_P (type1) + || (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE))) + return type1; + return cp_build_reference_type (type1, /*rval=*/false); + case CPTK_ADD_POINTER: if (FUNC_OR_METHOD_TYPE_P (type1) && (type_memfn_quals (type1) != TYPE_UNQUALIFIED diff --git a/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C new file mode 100644 index 00000000000..8fe1e0300e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_lvalue_reference(int), int&)); +SA(__is_same(__add_lvalue_reference(int&), int&)); +SA(__is_same(__add_lvalue_reference(const int), const int&)); +SA(__is_same(__add_lvalue_reference(int*), int*&)); +SA(__is_same(__add_lvalue_reference(ClassType&), ClassType&)); +SA(__is_same(__add_lvalue_reference(ClassType), ClassType&)); +SA(__is_same(__add_lvalue_reference(int(int)), int(&)(int))); +SA(__is_same(__add_lvalue_reference(int&&), int&)); +SA(__is_same(__add_lvalue_reference(ClassType&&), ClassType&)); +SA(__is_same(__add_lvalue_reference(void), void)); +SA(__is_same(__add_lvalue_reference(const void), const void)); +SA(__is_same(__add_lvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_lvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_lvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_lvalue_reference(bool(int)), bool(&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 85b74bd676b..3fca9cfabcc 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_lvalue_reference) +# error "__has_builtin (__add_lvalue_reference) failed" +#endif #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif From patchwork Mon Feb 19 13:51:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296997dyc; Mon, 19 Feb 2024 05:58:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXI8n9J5IWZ9iOKMNuu24o3+OPlgpvA41kO9XLg5CDcZUsLkXd5D+BkmVMmyNhb2ED4AGeBn+kxkDUr41G5PMnFMWSqZg== X-Google-Smtp-Source: AGHT+IGsgK+CNOIfcWxWGRWKnFQo5GLJMfWx8KH5TAG8YW5WjCIYs6/q7HM7o/HgkJlUs58N3VVT X-Received: by 2002:a05:6214:2604:b0:68f:4d6b:d123 with SMTP id gu4-20020a056214260400b0068f4d6bd123mr4863835qvb.18.1708351109413; Mon, 19 Feb 2024 05:58:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351109; cv=pass; d=google.com; s=arc-20160816; b=vSilpIv0VbAv8my27SB5xNa1ayLZJba7lDPClE2YQ7sf12aHafP1jp3jELzA+//NG8 Pn5h/AzER+tyykRlztbA4Xz7E/GJnP+g5oa05yxYsUKRQgTmgYJIKWVp+q0j1FXUcI93 rfYvZ0yKeSFmG8rM0esue4pOyDl8uCtmmQz/Ej/sDCNhG975Ul1iM+Bkyhr4fr8ujFpm VdVIkCbOM6Rr7xd+4wGBi4AkHBhgQEDTLPHK0eDPrNAcfmwk3vsjEzbBkQQHASuCOi4C IW/Au3FRGUvTAHTPgOojhU1XGiq6exuIbwdVZ2fVnzrs4ZVFLmDjSjyR84tgo6re9Jjr XeGA== 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=vRZT9JDrd622Iu6u+J+ASACUdFUCxkKR1xiPwypan9o=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EQzFHRPcvKiRQHWQDixQC4E1shx7nXJPLeFqaOKyuy+8dszc5Us6TvQoP65dbzVseu llYZRylWYQL+XcaaHgqyvV6sxa3NEhthba6fWQGkK/oeaRSn3ySWuHL1mptZgMKkafpN jz8pF1TRyt8vq60K8ZpmNwA9EBLJ3tqh3OM/aixIYnYEX6laHapprU63RBmuXYCRTiEY xIi8UVy+LGkLSKH+Hnf6kPTyxYQ4k/bHvLx+jZeWdYQiBm1ZVxz1DYn5tsWtK1k31F7a Y75yuoI6NQns5JGdVcThCkCc4ESx9/oiSlMcXWX3zyYcNw6+kxBXwctHBDXO8R0qn39o NaoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XUA7/PGI"; 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 i15-20020ad44baf000000b0068f846ae6aasi608666qvw.197.2024.02.19.05.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:58:29 -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="XUA7/PGI"; 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 0A4C9384CB9E for ; Mon, 19 Feb 2024 13:58:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A4C9384CB9E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351109; bh=vRZT9JDrd622Iu6u+J+ASACUdFUCxkKR1xiPwypan9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XUA7/PGIvSHZVtgAhOdclWQKkok5kHGGArT2WwGrEA+R4q9Zi989DSSyw4ERC669U a1pTKDV9j2BQRz4WZDS5DDqDjQgwru94LjQvuD1F0sXWuP7K1ySYq/jvlR6T7rc33a NoJ+P7WHu4GpJi9PnS5KLL+Y6D57YjUB5aKBPRzw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 8697C384F00A; Mon, 19 Feb 2024 13:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8697C384F00A 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 8697C384F00A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; cv=none; b=o1Qko+f8Zh4BiGwpVhDFiHbuy5m3HkGj8GoSH1aNN2uCEc2qMqWjhBCQHBHkXFftYT1llSrH91h8U1krHgPL73qEbhrpZuVweUNrzw+8ZlLVyu7JB20rDgm/dUx5xIGBA7iXWdry4V2yiBvEXwbaZVdTXwn0iyTGzZ6ljd6d2p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; c=relaxed/simple; bh=/d5pYHgmndZQUPM3uuFkM9vlgI/s8JMtr03/Zl99wNM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A0I99vdZA8Y4kRPI2B/W8RvKOkXXTFf4mEHEB5aTDtidr+YhHPQLLiWLSNU7c3YMvZLNOAGz4+RLGfz957i1ORomM74a42x1GGyOQoxg6Y102hXTLKuffUxBNnNjzmFpGjm7qg/+21osQdoryZVPvxpBX9luku9MfbbSGAdpVEc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDVgMj015862; Mon, 19 Feb 2024 13:51:51 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wbd09du8r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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+UW24.02) with ESMTP id 41JDpaeI004105 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRY001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 16/22] libstdc++: Optimize std::add_lvalue_reference compilation performance Date: Mon, 19 Feb 2024 05:51:23 -0800 Message-ID: <20240219135129.3635809-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: TxRUD8vodRvN7990RP6srsM2GQf9PQbt X-Proofpoint-GUID: TxRUD8vodRvN7990RP6srsM2GQf9PQbt 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 spamscore=0 mlxlogscore=715 clxscore=1034 lowpriorityscore=0 adultscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791335972696208145 X-GMAIL-MSGID: 1791335972696208145 This patch optimizes the compilation performance of std::add_lvalue_reference by dispatching to the new __add_lvalue_reference built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_lvalue_reference): Use __add_lvalue_reference built-in trait. (__add_lvalue_reference_helper): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 34475e6279a..17bf47d59d3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1157,6 +1157,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference) + template + struct __add_lvalue_reference_helper + { using type = __add_lvalue_reference(_Tp); }; +#else template struct __add_lvalue_reference_helper { using type = _Tp; }; @@ -1164,6 +1169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>> { using type = _Tp&; }; +#endif template using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type; @@ -1731,9 +1737,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_lvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference) + template + struct add_lvalue_reference + { using type = __add_lvalue_reference(_Tp); }; +#else template struct add_lvalue_reference { using type = __add_lval_ref_t<_Tp>; }; +#endif /// add_rvalue_reference template From patchwork Mon Feb 19 13:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1295230dyc; Mon, 19 Feb 2024 05:54:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0BmCUigaCg8WEeynr1IDA0BQWQM6iPW1gTDKKOGKwOBM2skaA3i9C7s8OTSjRgcF6xSom8wNTog/SDRgqNA9t3e35Aw== X-Google-Smtp-Source: AGHT+IF2R60UYAhzG2HCppOtAyEncIGN4VCNPE7Xqh653ev9d4yEa3sCSIkzEmIBBHKll9/PxRsJ X-Received: by 2002:a9d:750f:0:b0:6e4:41f4:e791 with SMTP id r15-20020a9d750f000000b006e441f4e791mr6216558otk.12.1708350884724; Mon, 19 Feb 2024 05:54:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708350884; cv=pass; d=google.com; s=arc-20160816; b=v6BX9kmUVaLD309eQZCBJHYrEA3D958nuo71KAtFB53uVnxxfHmZ/XGpZ8GSilurfC QYFi/2sXwbETPecc9KvDdJWpp+6RCCxw62yTd71KL7+P0q0fnkW9xCa/rleHsxUdZWhE 1+G9thZrw+2xGF6C/BHqMQldglHbUDixSYfcWoNzrnEapFCBUjlAYY4j8owu8fXCAhFN AT8Qgs2dKXInhr5EfExHp3+9yvcsrb2ett3JL6+tJz8A4Y0mmt3iHBCe9myT1Tmz1gjs rIf1BVf2yyhwBPJkiYXnPDQY4SO6J3YmlvAZf3n3t0l//TpHEp71x0bkcExRFt47zK5Z b58Q== 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=Ms8DvYdGqZju0xqP+uWeqDrd/M1dQHT7/o800YdVdPM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=We2E0QcnM2G6TnpU3lJISignJ8GExglDYi4QhA0h+Ha0Br6vSqTYeH0fgzYAWha4S+ 1pK1Y8ICVRPPKZAwgPJRA75ynjNQ+pHYD/bDYaqCkhEoJLaFrO1q7zxZB/4Yllk7XL+1 L/PEZp25OhqXu7Q4I9lCd7x5qExvQ82Q0axGzl65SM6zgRmvRTPKceC1v8Q06eujc0tW /kHZSsvAFRO5QezwdaYVxpvqfc1Nii/xfvVCO6sqJXBt7GrpHSPxmBZ+TdQvtGGsYpIp Acq6l9tSjP+/VmpMw9sNiecS7aPO2UbfOFC/laBjDrR+c2PSnRsE3PZnqz6UEZqjXEIT TsOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L6e1BPJH; 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 14-20020ac8570e000000b0042df89d42ffsi5164238qtw.171.2024.02.19.05.54.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:54:44 -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=L6e1BPJH; 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 462F8384CBA7 for ; Mon, 19 Feb 2024 13:54:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 462F8384CBA7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708350884; bh=Ms8DvYdGqZju0xqP+uWeqDrd/M1dQHT7/o800YdVdPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=L6e1BPJHjuV/LCnIPoa/FSB+vT0LTzxmB5eoWcF9AOSSw6EV3zRU4PhIqnJDqWEJN lAxE7vuxEsyyYTQ1Nzm3lB7cGyqRP6BBUskDdagFyjHpvRM7sKMR7L4hyo/qhzsL9o Fgb55NC8d4HXXZRX2nk+oOgJNlkxh2QHD8Zcj9/4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 6B0C3384CBBE; Mon, 19 Feb 2024 13:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B0C3384CBBE 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 6B0C3384CBBE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; cv=none; b=UnI3PHgCKoPmgwLxXSrfFcExnBX0YedqjMjqynH/GeB0pG1O2vPP2snuR4DJvHO0bXdrHq5zKyPVZo7enKxwpMHCciqPKXJ16s76h151baeqvIQvrYvuDiYGno5kc3VKiMWSB06N78WEzk0lwM27rGMIidoutiUJKvrLHoRFJyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; c=relaxed/simple; bh=XzPEE95yRRX9fG1TBmN/Dww4kezjgkNHgKOEXc42Kcw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=t+hDt5aRtKBinKmINKhw9D3yNYTi/FLqI0cVt+GUmKZlx/SNE5a7ghFu1Sty71uLm8lwr0JC6Agrb7LvKa1WutK/TlnS2FFyTHq0R3+KAm2bDivG7cg/dTTDNFHMDdv3WMRp0FO8tjYXg/7LPfDKXqTV07+64HnUPfYKWXOx8AQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDY7Vo018654; Mon, 19 Feb 2024 13:51:51 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6dpexjb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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+UW24.02) with ESMTP id 41JDpa8n004106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRZ001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 17/22] c++: Implement __add_rvalue_reference built-in trait Date: Mon, 19 Feb 2024 05:51:24 -0800 Message-ID: <20240219135129.3635809-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Y_iuCAzjQaJK-XDxKX-IEuTuzjb5DiPT X-Proofpoint-GUID: Y_iuCAzjQaJK-XDxKX-IEuTuzjb5DiPT 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=462 bulkscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791335737058875659 X-GMAIL-MSGID: 1791335737058875659 This patch implements built-in trait for std::add_rvalue_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __add_rvalue_reference. * semantics.cc (finish_trait_type): Handle CPTK_ADD_RVALUE_REFERENCE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_rvalue_reference. * g++.dg/ext/add_rvalue_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 8 ++++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_rvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9a27dca4ea3..173818adf79 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -50,6 +50,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) +DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__add_rvalue_reference", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 05f5b62f9df..19d6f87a9ea 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return build_pointer_type (type1); + case CPTK_ADD_RVALUE_REFERENCE: + if (VOID_TYPE_P (type1) + || (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE))) + return type1; + return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C new file mode 100644 index 00000000000..c92fe6bfa17 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_rvalue_reference(int), int&&)); +SA(__is_same(__add_rvalue_reference(int&&), int&&)); +SA(__is_same(__add_rvalue_reference(int&), int&)); +SA(__is_same(__add_rvalue_reference(const int), const int&&)); +SA(__is_same(__add_rvalue_reference(int*), int*&&)); +SA(__is_same(__add_rvalue_reference(ClassType&&), ClassType&&)); +SA(__is_same(__add_rvalue_reference(ClassType), ClassType&&)); +SA(__is_same(__add_rvalue_reference(int(int)), int(&&)(int))); +SA(__is_same(__add_rvalue_reference(void), void)); +SA(__is_same(__add_rvalue_reference(const void), const void)); +SA(__is_same(__add_rvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_rvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_rvalue_reference(bool(int)), bool(&&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3fca9cfabcc..c2503c5d82b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,6 +8,9 @@ #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif +#if !__has_builtin (__add_rvalue_reference) +# error "__has_builtin (__add_rvalue_reference) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Mon Feb 19 13:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1299443dyc; Mon, 19 Feb 2024 06:01:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX4fZvZCv/KgnJ5k8QgNsGgA8n9hHif/0hzmqJtfLnUBq8Zj3/cEBY+343rtF4i7T0GUR+AiQyATWubhSG1lf5/8YnmOQ== X-Google-Smtp-Source: AGHT+IHbCTN9C53VyzahrbQZfxPEjJ611te6mO2V4T5Oq0+eHtqLKT3A0Q5fA/Of9B9Gap76GHiX X-Received: by 2002:a05:600c:3492:b0:412:6c73:a646 with SMTP id a18-20020a05600c349200b004126c73a646mr51211wmq.30.1708351312773; Mon, 19 Feb 2024 06:01:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351312; cv=pass; d=google.com; s=arc-20160816; b=jcQTIMPTrIz4USo6mQc4oBmlsfvappqtUGX957pogng6rRHxwKnPGpuJOqvifNmmPr GT/xjGmygOfSh1J2OInzkqomUO7FXbC4qYwilnWWR++DiYr7pn9DktMsnRChMT1he2fQ QbwYVIlNxQEKXhG7sF4sm+gJltbDn7AagGaS4W1XqkTnNtXuf3MampvsjwMW0OlYBHRQ AqgVvUSIIKMltpggR5MvywKAoEb3ibRKbfNr2xBT7Wwc9+cED/vbMZONyr2z4BIsF+2t Vk5xbl8Btks6EazMnp+e5uFo3pofwZr8CwN9PBxueFZaw1cqnE0aGaH/rTS2JGKMQqSb jDkA== 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=elGDHfvNkpwr8EzItvxzljPA39vs0002JgLcbgLKr9Y=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zrN/WATfH5hJBw0vNsxMrs2DKEhdEUgSNoKCa+LCTNxM8xx+dBwj3zTmgLOYzHFZbC vsJKzmeIKZzqgzaUqP3hUZqHJRkfyd/k/paUmdCwq4d+SBDV5LgJeXKCBQxNuiLrYmOG P3Wcc91Mj34/+/qsKvqKecmZXN475sWLI7RUqs9pk3AEJ7VKLET2+Srk46pTE6SBujdn U0hreZFLRaGrayhCAVbB2WzsXYTbrToVgR2VoDsPNhfkbpyMR4a/a4CVHhMNxr5z1VjY JLnVem3gleCPn49qg0Qiu1OESPdfMPTyOFsbdNly61hqVdTTSm51oFYQcZh6FOGIvbWv 7xUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QpunEv12; 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 o19-20020a5d58d3000000b0033b65cabe3bsi3902934wrf.652.2024.02.19.06.01.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:01:52 -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=QpunEv12; 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 F1C18386EC11 for ; Mon, 19 Feb 2024 14:01:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1C18386EC11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351283; bh=elGDHfvNkpwr8EzItvxzljPA39vs0002JgLcbgLKr9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QpunEv12NkHOUllvpVS1X7sh/94LhulLvZms0R7LB4iAAZCFFma1sV8mGNp0xsnc/ 72LPhrdD/LIQIvU/5vWLlsTcZic5vfJdlsrRbBTpmbPsvdhw0ghEbdYu1kEObyTR2l xApDlJIu7uEIxwZipv52KaZh5UimCa/KepBXRaxk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id E6F753865C3C; Mon, 19 Feb 2024 13:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6F753865C3C 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 E6F753865C3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; cv=none; b=buTXn4ItpQjNlvDb76zcm+pWNx9i9yNJx9z6e0PktIWBEweDYTWO4PoN9kr2To3JxNR6HBnhFy5GWX64mR6zhTPCJw3kt5UsiF7cVaLCkyxBhBuwHAAkdQEvINliOrwRIttGS5z3NR8jduNfUVChr2KPxbYcM+bOykjuIBp7cf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; c=relaxed/simple; bh=8hEG5CjpuoI1PfbSiMdcHFy5SCrsJy7Oh6+fRwRygjI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LncJrXhmnOAm4uHBpjgD1AwL8PNO0cbxyudUl+KtTuruRSSiu0XLTBdjll/mDm8T+Tjtdvzugnc7tUEzMuJMvm4D1MOTPm6Z3bOcK3Uc/xNEAvrsqWCBm8UHP72UlymDc1WeVq6eKy3C7GEqoLCFwgpPnt5ZYb1ni3YNCwhuRqw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDlt4S005880; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6a0pxry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpaxE017817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:36 -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 41JDpZRa001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 18/22] libstdc++: Optimize std::add_rvalue_reference compilation performance Date: Mon, 19 Feb 2024 05:51:25 -0800 Message-ID: <20240219135129.3635809-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 4RglBA7TftdyIW5nuzqUlbHstSzEIGMh X-Proofpoint-GUID: 4RglBA7TftdyIW5nuzqUlbHstSzEIGMh 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 clxscore=1034 impostorscore=0 mlxscore=0 spamscore=0 malwarescore=0 mlxlogscore=737 priorityscore=1501 bulkscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336185814634233 X-GMAIL-MSGID: 1791336185814634233 This patch optimizes the compilation performance of std::add_rvalue_reference by dispatching to the new __add_rvalue_reference built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (add_rvalue_reference): Use __add_rvalue_reference built-in trait. (__add_rvalue_reference_helper): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 17bf47d59d3..18a5e4de2d3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1185,6 +1185,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference) + template + struct __add_rvalue_reference_helper + { using type = __add_rvalue_reference(_Tp); }; +#else template struct __add_rvalue_reference_helper { using type = _Tp; }; @@ -1192,6 +1197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>> { using type = _Tp&&; }; +#endif template using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type; @@ -1748,9 +1754,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_rvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference) + template + struct add_rvalue_reference + { using type = __add_rvalue_reference(_Tp); }; +#else template struct add_rvalue_reference { using type = __add_rval_ref_t<_Tp>; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_reference From patchwork Mon Feb 19 13:51: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: 203104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1296853dyc; Mon, 19 Feb 2024 05:58:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUW18E0wUGCkA0CV8/17E5Kk3ahiFebLJsR3VkLjY+cZX7xGZd3Bmdqt4X5RCnUjUAXcb8xzMinfj6OVt+Z/ONkbk0Lgg== X-Google-Smtp-Source: AGHT+IFE9P/wU0XRbozFw1bXitb2BrYfASyaCYDLfygH6LAl+D7C9wLfaig/8wKPXLN/ZQUT65LA X-Received: by 2002:a05:620a:4093:b0:787:73b7:9d00 with SMTP id f19-20020a05620a409300b0078773b79d00mr74712qko.51.1708351093890; Mon, 19 Feb 2024 05:58:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351093; cv=pass; d=google.com; s=arc-20160816; b=qn/XV0EsuaLGMhTGEVRBPwaFwe418CQ8mHOQTZByLACLHcBH+mkFC+4nCt2xDZDIhi s6/XVVMHuutjedLNr7slQ9ylfTg/pKGIlZQwYZBKYJN7WQHYnsrv7m2Rz/EM3qGU0dRw QDNs233/I1WAFfMdN1pEl0O73v7y2l0jpwnXFCBhp7GF/DvseO586rOPJZ63CCMYen24 zuMA4Fs9FXozfceEefHvwwMJYV8IZArH4Q5YU8gYbNoDU/9bMIMhTAsCIAMGxLcJKj2h lR1T27sL9lpDMT3VwfbpnRmEA0QY3WY5U5khz9kk9MB6ajNDqL4XB/Vjy4/F0VgvySmr B6pA== 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=XFQAE2oI0raYgkTn6+vuZ1fQNuJBaUOzoCpMJC+xZnc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=buz0Q4lF0LiON7Xn2/zRfyIww4M6GqzuvP6C60EiCpaIZN5jND9ryw+im2rqJAWPR7 R4BkwQ0fosuGm8l/T8GKykEGvXTs0sCS5tPQOVnRjm91Wmmt+TXQEstvtPKVXe2QAHex ExSojPQP9QqKVGXy9iZvXPUxAPmhlCOgev7jN9EYboHJskg0z66oMHZ+Jr0o28CMsRrQ 46eQByqtWBqqBEVovWw3ByLNj8ktCvFDd+VSdI1+8rhLkwAIjVCz5cp+vXtHKQqhOHrL N0fTlGgcVdCSuCFNbuWQMapUPj4IjAQJGFlXo0+HCQKZFemx6n9SI+pZYONb8heP0zzT 8lFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="FNreLI/e"; 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-20020a05620a04cc00b007873eaf2e56si6016638qks.24.2024.02.19.05.58.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:58:13 -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="FNreLI/e"; 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 6F9663865474 for ; Mon, 19 Feb 2024 13:58:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F9663865474 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351093; bh=XFQAE2oI0raYgkTn6+vuZ1fQNuJBaUOzoCpMJC+xZnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FNreLI/e5jpDe+zZazN8I+t9arK3jqNHVC843prO9o0qjaPcqRl/f2PBKrcDRji5h QLOOe5hIsCvWI+cLap0jawa/BnlZqgV/pOln1KDZnnEwJwtCdvljSOojvRWzko12D2 kVvaumoIeDJl5duuSZAVUxG+osuRzN+IMSlf1yo4= 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 1810C384CBB3; Mon, 19 Feb 2024 13:51:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1810C384CBB3 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 1810C384CBB3 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=1708350705; cv=none; b=bVoCO3VbnrWPtiD4QSfRT1LkY/t6LHFho9C+sjZVGR05motqslcKr+HRbl7OsTcj6B3plSa9N5rynynfo7UJ+z0PIKwjFGRYfWr42HwSDNHEuah6KPmRQvOrquV3gOjzwv+8egmT0fLlBUGJbuCnvlhiJa4TGRCl1y3YNjkYvC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350705; c=relaxed/simple; bh=1gH+O9a4vL4oY00vB4+DswXckPx945fkWnb8Q0PpiLY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ERQLzMAAvqaGRbPq6U0g6/acukJfk+2dxNQs7//yF7uI04CTtYqOz2bG8rdigH6cCfPClptFErDRyntwfQ8kRpnlvX8IOEFBYCfIiRR841JTwrPPhOP+4UW+OrV/rD/w2Ttz4hq4gNMMQ9H5u6wGG88WjJxrY65X3v1WByRxjSw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDoQEE032425; Mon, 19 Feb 2024 13:51:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb649f516-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:41 +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 41JDpbWH031680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:37 -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 41JDpZRb001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 19/22] c++: Implement __decay built-in trait Date: Mon, 19 Feb 2024 05:51:26 -0800 Message-ID: <20240219135129.3635809-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: XgIEkJFe1YMbPllmgqm7gjPCHP0XqICV X-Proofpoint-GUID: XgIEkJFe1YMbPllmgqm7gjPCHP0XqICV 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1034 mlxlogscore=543 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 X-Spam-Status: No, score=-13.0 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: 1791335956932456083 X-GMAIL-MSGID: 1791335956932456083 This patch implements built-in trait for std::decay. gcc/cp/ChangeLog: * cp-trait.def: Define __decay. * semantics.cc (finish_trait_type): Handle CPTK_DECAY. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __decay. * g++.dg/ext/decay.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 12 ++++++++ gcc/testsuite/g++.dg/ext/decay.C | 39 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 55 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/decay.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 173818adf79..2d1cb7c227c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -51,6 +51,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__add_rvalue_reference", 1) +DEFTRAIT_TYPE (DECAY, "__decay", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 19d6f87a9ea..45dc509855a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12801,6 +12801,18 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, return type1; return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_DECAY: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + + if (TREE_CODE (type1) == ARRAY_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2, + complain); + else if (TREE_CODE (type1) == FUNCTION_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain); + else + return cv_unqualified (type1); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/decay.C b/gcc/testsuite/g++.dg/ext/decay.C new file mode 100644 index 00000000000..cf224b7452c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/decay.C @@ -0,0 +1,39 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +// class ClassType { }; + +// Positive tests. +using test1_type = __decay(bool); +SA(__is_same(test1_type, bool)); + +// NB: DR 705. +using test2_type = __decay(const int); +SA(__is_same(test2_type, int)); + +using test3_type = __decay(int[4]); +SA(__is_same(test3_type, __remove_extent(int[4])*)); + +using fn_type = void (); +using test4_type = __decay(fn_type); +SA(__is_same(test4_type, __add_pointer(fn_type))); + +using cfn_type = void () const; +using test5_type = __decay(cfn_type); +SA(__is_same(test5_type, cfn_type)); + +// SA(__is_same(__add_rvalue_reference(int), int&&)); +// SA(__is_same(__add_rvalue_reference(int&&), int&&)); +// SA(__is_same(__add_rvalue_reference(int&), int&)); +// SA(__is_same(__add_rvalue_reference(const int), const int&&)); +// SA(__is_same(__add_rvalue_reference(int*), int*&&)); +// SA(__is_same(__add_rvalue_reference(ClassType&&), ClassType&&)); +// SA(__is_same(__add_rvalue_reference(ClassType), ClassType&&)); +// SA(__is_same(__add_rvalue_reference(int(int)), int(&&)(int))); +// SA(__is_same(__add_rvalue_reference(void), void)); +// SA(__is_same(__add_rvalue_reference(const void), const void)); +// SA(__is_same(__add_rvalue_reference(bool(int) const), bool(int) const)); +// SA(__is_same(__add_rvalue_reference(bool(int) &), bool(int) &)); +// SA(__is_same(__add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +// SA(__is_same(__add_rvalue_reference(bool(int)), bool(&&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index c2503c5d82b..3aca273aad6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -11,6 +11,9 @@ #if !__has_builtin (__add_rvalue_reference) # error "__has_builtin (__add_rvalue_reference) failed" #endif +#if !__has_builtin (__decay) +# error "__has_builtin (__decay) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Mon Feb 19 13:51:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1301638dyc; Mon, 19 Feb 2024 06:04:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVz1l+/94mCPk1OlofYu0uq0tEeUMT5hQhMoifuT3KXioNHKIdZEOLxgXFNNchZJQFdjkoglP7Ilu0TTcQLa7kxSR4O0g== X-Google-Smtp-Source: AGHT+IEeYT+43mQBAHtfnioRT5gX+xKwVDYYriqLAdhWoTFWV3grWZgX6/Q7/bixzh7YrckI7peP X-Received: by 2002:ad4:5ece:0:b0:68f:6f1b:fa41 with SMTP id jm14-20020ad45ece000000b0068f6f1bfa41mr3780890qvb.4.1708351461755; Mon, 19 Feb 2024 06:04:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351461; cv=pass; d=google.com; s=arc-20160816; b=TEl1GSD9/c/hfyyvfDgBDsyyZFj0AkSPle5/syg0RP2Si/Kb6jx89J8Wxx5sLOpqo3 w/L4vfHok8ALrBQ4p5dNtwg+AH6rq1C7Frt8kyRXwWmoaDFCL23pkMeHYPm7U3Di7560 XfCmRVykD6qQ+qBzzyD4MqOXJOC7iG+lvudoNVsSq84YMYExTLdiG5nIbOgTnUBW+W1v Scx24Ycr+V5f1p2E42nctlOr3XaFsdPoKIh3lxIfuBfd/rBaauWWUVwECP0seMe7JDAH QIin9gpGEa6QPXXKzD4cb9iIsXjmj8KkZz2YoHv0NwyyRZQ5lunvDWehPg2XLE6LctOw sFZg== 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=5/6fpITJp6VEOl/rMhl5H26mhzFkHcV8OvX0psRh2EU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ganRpfm6ymMjam6DFVyOM52X3AMVGvG2pQO5QPyEE1GIOSDSxBbuQqjmLbJOHbDCoX aqmMcPAoVDWSWpU45vebmmW6cLXOx0o+tEIhN/M4J3KJy2y4h2QLg0xB/aIIERgrIPPo IqtatlmWWL3h0hWkbpcwaxufbfOC9TjfNabmkQezbcc2tGAFwmtbGHplEb4R1EOBh+E0 yUegpO+6OeAyNmwnfiXdeolIJPiQ3r++aaqflKRksIZo5+t5DR3OsGhMyg+X6W0BRUa8 5gkA84A3eXRyqC1JVAEyHkgppHVPeNomn08f8zHoew6IgLmPNZRwWzC0TdFfHqmcQeqR tfAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nF9tpVxS; 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 sq3-20020a05620a4ac300b007871791228fsi6289718qkn.669.2024.02.19.06.04.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:04:21 -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=nF9tpVxS; 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 6AEB03865491 for ; Mon, 19 Feb 2024 14:04:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AEB03865491 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351461; bh=5/6fpITJp6VEOl/rMhl5H26mhzFkHcV8OvX0psRh2EU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nF9tpVxSxYpZubLi1dQwdXtd1+cgpKyQw4Lm90sDRuipAawmTSDO7kY61lyQCQEWH UwgzrcK3n2FZV4Qpy2ODpb3LC/0zI65pwTuse/QkXAkEaZf9soh+FfRA5wHMH80Z3R f4hdxppvA5XPbstKuwdLk9nhh6+Gzlaynb30+U4g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id BC7733864877; Mon, 19 Feb 2024 13:51:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC7733864877 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 BC7733864877 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; cv=none; b=ZzueSYH+woYYuIZbQ/+fearhIz3ob4TxAk5QAYyNnYmDKLNqASxkHBTowRpYd2trVhV31msbgcU9BsNqqQZyaRJJSo5p3f00nbMScmVD71zbl8YuRlM+B7LYmClxyAj4I7bJ5S7/WsRVAxNQCqXFa9hjQg8agYSKEl9vTnmSGY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; c=relaxed/simple; bh=x3HabDfYE+N1rP9G2WHdqZ4tP3FpTiSMwVAtW/KR4mA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=b3ZSGLr/CiW9J+Zr4bpg9udoxbin/pPEY/F4k3VD5SejiupSgdg0umd7RA9YmsdYF3/L7nUgOc+2NbYG9zWZQU5Nwwc3GXOiLwb3hKl0Qdpyk+xtO3JsKVYZpBXdIXYv/tCHV4GKKajyRg1V8SLssXBcro9u8vYEHfLliiO/d8w= ARC-Authentication-Results: i=1; server2.sourceware.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 41JDisa7025480; Mon, 19 Feb 2024 13:51:51 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wc7s083pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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+UW24.02) with ESMTP id 41JDpb6k004107 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:37 -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 41JDpZRc001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:36 -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 v7 20/22] libstdc++: Optimize std::decay compilation performance Date: Mon, 19 Feb 2024 05:51:27 -0800 Message-ID: <20240219135129.3635809-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: uj4qXpW6OajYuTYH9KdjUAEcR8w5yk7d X-Proofpoint-GUID: uj4qXpW6OajYuTYH9KdjUAEcR8w5yk7d 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 mlxlogscore=764 adultscore=0 spamscore=0 malwarescore=0 suspectscore=0 bulkscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336342216486526 X-GMAIL-MSGID: 1791336342216486526 This patch optimizes the compilation performance of std::decay by dispatching to the new __decay built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (decay): Use __decay built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 18a5e4de2d3..2f4c8dd3b21 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2316,6 +2316,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__decay) + template + struct decay + { using type = __decay(_Tp); }; +#else // Decay trait for arrays and functions, used for perfect forwarding // in make_pair, make_tuple, etc. template @@ -2347,6 +2352,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct decay<_Tp&&> { using type = typename __decay_selector<_Tp>::type; }; +#endif /// @cond undocumented From patchwork Mon Feb 19 13:51:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1299370dyc; Mon, 19 Feb 2024 06:01:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWF9fo7iTFVhyBIUdV1L9zNSgfSIZaSUzYVq6G7yuEynrSZ3LO5yjdx3EEnNmWWema+2gdgogzkw1RYoJu6wwmQre1CRw== X-Google-Smtp-Source: AGHT+IFefL9epJNS1fPkB1BN1GBamLrfxWUKF24EVPh1NQ4g3csFkRNTADqAWxgiqtFm1nX0zZN4 X-Received: by 2002:a05:600c:4691:b0:412:f24:560a with SMTP id p17-20020a05600c469100b004120f24560amr9338251wmo.11.1708351309243; Mon, 19 Feb 2024 06:01:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351309; cv=pass; d=google.com; s=arc-20160816; b=FA+Qm5p7lMAylVrv1MEdqYgJFcKIF6CAneH+Ld620Qfy5pUxZJCojN5OpHwq2IIaKS OyjzseuQS1cDG38fXriXfbUGtA7xHBJoJ99Dw3+RlMcUxRBwyuBLh8DTkGoKcdfq9erS VP5gafikwdiBQUU18ISu00DjHvBPVfQy93rNaTHFfK2ouuh2gY4HKu5zuPj1LphzeUvu z8ulZ12DHtUL3TjIcCxbOb0PaowK81YHDZvY8+nBVrtxvBrPoYJgt4YnOvMPGyN2ahMv tru/b3OLeHIWdbitBB8lUTB4+3EYRAMu/8/EjbDqqj5aZ5JK12Y23BbwG3XKqxRQNCSt YvLg== 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=57PpdBg0BBXCYV2dq+DJeXz5PzgzdOaEtypMsfWjTNw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=S879JI25PT71kdaDVLeIs7VNCtdwBBjlSvfAesWZPZwqxHWVj6t/8hrosoI3lL4R8C DSEwZ4nIFjJKZrJph94+Exp/cLFTPNQbrj0ldkEsUDPIQhyuq113PJn/b3ZHpSHWxuSJ V1XYUN9T9FL6uRLgXpDxe0dkNuRxeDKGVv/5lydKRBr9KPGaAqMsJheaLS7HWySVq2jj 11lY0aMtGzoLskce5aP35YQaWAvZCXL2eceujR0JXPevkqtmkB+BtStQdpB3iA2W2rCC bryJcsG7sKd+rtbHiiziuZr/SsRPxnx/KmzfdhwUF/ylu9f/NawN3+jtUELxpsTTs83f Uibw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ib7wEQso; 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 z12-20020a05600c220c00b004126aca61c5si302639wml.2.2024.02.19.06.01.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:01:49 -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=Ib7wEQso; 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 D4CE3386F026 for ; Mon, 19 Feb 2024 14:01:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4CE3386F026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351280; bh=57PpdBg0BBXCYV2dq+DJeXz5PzgzdOaEtypMsfWjTNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ib7wEQsoiM652bBgzNXQ6019nV9/In3HJQu1TFco3BH+qwGjjDgi4d60bpYjgzLDK ue8TZYaoXYguHLaqehHSKsxb2uMY2xvDe7XXi0VFo9D3xA1Psd2owRcn4XX1zUE8pt MNinhEfmCse8HnlhH/7SGYWcB5kFWpfFrgZ0e6sE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id F22E83865C12; Mon, 19 Feb 2024 13:51:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F22E83865C12 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 F22E83865C12 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; cv=none; b=jqWyHOYLjGYuU7LaRheFeV226shww6FN7paDy0Urag9FdCHucDcTkZoXSBZ1wcyKkejFU1grbeXktDqBFb6GZrcfVECWl3inOS8tj0G9A8XIuzauMiAmWqoDGCm8jBvrP7euZNgzu8wWSpzFoNSMDGdlJQWVY7KGLL9MIXitxAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350713; c=relaxed/simple; bh=g1eWmhi4z4/17JYQLuFMHiwFbdTwbz/1YQ5SEH9sMww=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nMCh2iiLYErZrKGEupAJPB9TZJS+O7+QRHFLXLYZTjH/nMj1KEFFBxsd5i7ThFuKZSkR7emwvKVe2fbaO8whTdued52lG69tIZHFRdMx2LyjlHmf/FOmTptSNuQ/Pg2lIhzWvmyE0mzkQJLDD+7bJUPdbD2Hg0i+FeltVnE6mvQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDmH9N016832; Mon, 19 Feb 2024 13:51:50 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6y06ub2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:50 +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 41JDpbtf006523 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:37 -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 41JDpZRd001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:37 -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 v7 21/22] c++: Implement __rank built-in trait Date: Mon, 19 Feb 2024 05:51:28 -0800 Message-ID: <20240219135129.3635809-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2KxV3HPvfpH-Yq7Ot3LOEqgCLt_4nGOI X-Proofpoint-GUID: 2KxV3HPvfpH-Yq7Ot3LOEqgCLt_4nGOI 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-19_08,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 bulkscore=0 clxscore=1034 mlxlogscore=927 mlxscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 phishscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336182104506502 X-GMAIL-MSGID: 1791336182104506502 This patch implements built-in trait for std::rank. gcc/cp/ChangeLog: * cp-trait.def: Define __rank. * constraint.cc (diagnose_trait_expr): Handle CPTK_RANK. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __rank. * g++.dg/ext/rank.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 23 ++++++++++++++++++++--- gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/rank.C | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/rank.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 62b264e4757..a9b6e7416fa 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3869,6 +3869,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; + case CPTK_RANK: + inform (loc, " %qT cannot yield a rank", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2d1cb7c227c..85056c8140b 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -99,6 +99,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) +DEFTRAIT_EXPR (RANK, "__rank", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_ALL_EXTENTS, "__remove_all_extents", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 45dc509855a..7242db75248 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12550,6 +12550,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_DEDUCIBLE: return type_targs_deducible_from (type1, type2); + /* __rank is handled in finish_trait_expr. */ + case CPTK_RANK: + #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" @@ -12622,7 +12625,10 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) if (processing_template_decl) { tree trait_expr = make_node (TRAIT_EXPR); - TREE_TYPE (trait_expr) = boolean_type_node; + if (kind == CPTK_RANK) + TREE_TYPE (trait_expr) = size_type_node; + else + TREE_TYPE (trait_expr) = boolean_type_node; TRAIT_EXPR_TYPE1 (trait_expr) = type1; TRAIT_EXPR_TYPE2 (trait_expr) = type2; TRAIT_EXPR_KIND (trait_expr) = kind; @@ -12714,6 +12720,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: + case CPTK_RANK: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12745,8 +12752,18 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) gcc_unreachable (); } - tree val = (trait_expr_value (kind, type1, type2) - ? boolean_true_node : boolean_false_node); + tree val; + if (kind == CPTK_RANK) + { + size_t rank = 0; + for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1)) + ++rank; + val = build_int_cst (size_type_node, rank); + } + else + val = (trait_expr_value (kind, type1, type2) + ? boolean_true_node : boolean_false_node); + return maybe_wrap_with_location (val, loc); } diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3aca273aad6..7f7b27f7aa7 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -179,6 +179,9 @@ #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif +#if !__has_builtin (__rank) +# error "__has_builtin (__rank) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/rank.C b/gcc/testsuite/g++.dg/ext/rank.C new file mode 100644 index 00000000000..28894184387 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/rank.C @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } + +#include + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__rank(int) == 0); +SA(__rank(int[2]) == 1); +SA(__rank(int[][4]) == 2); +SA(__rank(int[2][2][4][4][6][6]) == 6); +SA(__rank(ClassType) == 0); +SA(__rank(ClassType[2]) == 1); +SA(__rank(ClassType[][4]) == 2); +SA(__rank(ClassType[2][2][4][4][6][6]) == 6); + +template void f(T) = delete; +void f(size_t); + +template +void g() { f(__rank(T)); } + +template void g(); From patchwork Mon Feb 19 13:51:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1297442dyc; Mon, 19 Feb 2024 05:59:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVezXlpBtGRlzfrZ7GYnThgK1GCQqzFB88LnVmae1hXmxkgb3HGXKdEZLx8b87zW0Szz5f/a+LftEwGMPsJfoxBx91wg== X-Google-Smtp-Source: AGHT+IGvX2NlI9jBrO5Gge/UJeEafmtOiEswJ5tI7qNt83MCsXB9nV/hj1A8tB/VWqlK105oG/4D X-Received: by 2002:a05:622a:14ca:b0:42d:c9e6:4b4e with SMTP id u10-20020a05622a14ca00b0042dc9e64b4emr15120142qtx.52.1708351176429; Mon, 19 Feb 2024 05:59:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708351176; cv=pass; d=google.com; s=arc-20160816; b=R/ZA2N/zmxaZAYQuB+7GJpKhiP7dbl9D4xaQxzVp7yr6Tt3H0Hn7zeOQOP2GY7MWy1 TMCoXwdqBJbcEa1vbh4u6j2VuK4oGrAXKtomX47/hbtypZX5lWoyK6Wf37iKxZfrYuTm Ldwg+E6dL2cuBFJyAO5W4mU5UF5KchCQ5DNlWXQv/JWmkyUL5ZytBgpsdsLOrghnVB3Z RTGrja4nNbS53teOt7t4MC/drQ2UiNsF8qTP3JmfMKUZ4VqGycNbahuKr9o3PTZ/6VOS nl9UfkHqq949KuRIjn7jESL1GnzLBIiKIGWGONOITLf5pIipNJuLQikVEQeik1vbUGUR fXtA== 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=Kqm6uE+5jPfMyDNdkfa0LiCgxb1XB7uFGblGj4D6tG4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MplpmCv6x2264+7QQ4nMVRPCLgfEbeXVvtNMxLm/fAn/sypaMNjhdcQsJcbB6edMK9 0FKq2a9cntM7OdxQbh50k/RJSWm/oE0ZJFaYLou2mmM+KavtJm6wLrNpq29oajuudDja WDkOEVRXG7qjTaOuqiJ2GkX71LR6Cf8hArEU5NzJgOo5VX7oREsL/XSF2XLdk5ckmgVX oG5ASHLtGT2sFsfc53EEOWTYm02RrcYy64Zsfx0dorA7080GwFAS/diSeA4nssq5iLqR pJUIYL47TH1g++VzPKGklgGuAdIu2JrEVLYoqqo3YB3cJ8UBlod1MzPQYHZrieh/CtIk p3SA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rawkb8ck; 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 c10-20020ac87dca000000b0042dba5dad7asi6732220qte.456.2024.02.19.05.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 05:59:36 -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=rawkb8ck; 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 C9996384D169 for ; Mon, 19 Feb 2024 13:59:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9996384D169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708351175; bh=Kqm6uE+5jPfMyDNdkfa0LiCgxb1XB7uFGblGj4D6tG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=rawkb8ckwSPM5uZJDfdRxNo9y1q/jEijxFpXuX9on1d6hzB4qSGaWj2yMB8H9D5Gp VFBbISw1WLAoDvHDnDcIY3qLuo9zDd2NbIDKMhEIokb+EirMbAGZCFzLSMCw8JO9OO 7OhTEYuUlWniHky/07Mm/cVxj6WOm6rKLKqalsk8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id E40C13864809; Mon, 19 Feb 2024 13:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E40C13864809 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 E40C13864809 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; cv=none; b=xf931lpWnk6lp5qiGIX+XIQ1PufipB2S2PdrwdgyZYR3VxAXEYkwIWvFxcqs+6XAhpLHif++cAZu2lvowIUh90ie37I3HyimgkLvhyt9g1zUCtmSwyquONLV1R19Xq56yZ4sNl0N3uawPcP9LuI/o/+g+iFV85Lv9Pnka+VeGlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708350715; c=relaxed/simple; bh=nnOSquQzgZeHmIvWdlWALFaU1rHAa4zMhUec7hVpoq4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fMMtzyv5QwENXndQzesRXRC2q1N0d41rxW/uGjMWKtTmIz5zWw6C8J+GG+qOOOprI3oWu9fEov42cfxgsHD2VfJp+BufcvfY/hNUzWbz6C0VXk3ACepUknoUu/+63J2X8d43QZLLQEnHQGF5B0dn41KtyNlVxCLM1JeEbh7XAG4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41JDoHIt028614; Mon, 19 Feb 2024 13:51:52 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wb6vpxv5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 13:51:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41JDpbZK017818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 05:51:37 -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 41JDpZRe001026 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 05:51:37 -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 v7 22/22] libstdc++: Optimize std::rank compilation performance Date: Mon, 19 Feb 2024 05:51:29 -0800 Message-ID: <20240219135129.3635809-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240106050754.3054782-1-kmatsui@gcc.gnu.org> <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: qEB3b3q2ng-6v6Mxlus4bxHMPQRDbuVT X-Proofpoint-ORIG-GUID: qEB3b3q2ng-6v6Mxlus4bxHMPQRDbuVT 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-19_09,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1034 adultscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=800 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402190103 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.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: 1791336042966263648 X-GMAIL-MSGID: 1791336042966263648 This patch optimizes the compilation performance of std::rank by dispatching to the new __rank built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __rank built-in trait. (rank_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2f4c8dd3b21..1577042a5b8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1473,6 +1473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// rank +#if _GLIBCXX_USE_BUILTIN_TRAIT(__rank) + template + struct rank + : public integral_constant { }; +#else template struct rank : public integral_constant { }; @@ -1484,6 +1489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct rank<_Tp[]> : public integral_constant::value> { }; +#endif /// extent template @@ -3579,12 +3585,17 @@ template template inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__rank) +template + inline constexpr size_t rank_v = __rank(_Tp); +#else template inline constexpr size_t rank_v = 0; template inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>; template inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>; +#endif template inline constexpr size_t extent_v = 0; From patchwork Tue Feb 20 05:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp202534dyc; Mon, 19 Feb 2024 21:22:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTd/MSHQaz6q3GMrjNfCHyBcX3xADtVro/m6ardpyu9c1+IVXIVBoy4czIzUdqVSUuiMu78CcmYy/HU01gIgrx8gE5GQ== X-Google-Smtp-Source: AGHT+IFPQDp8fgr3plK5r5ovOyejkg5y2a+mlsRVzuGmrUckOsbpV+hZPU9e+3xahk89791XftS2 X-Received: by 2002:ac8:5e49:0:b0:42d:f2a0:d5a0 with SMTP id i9-20020ac85e49000000b0042df2a0d5a0mr11977216qtx.10.1708406531607; Mon, 19 Feb 2024 21:22:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708406531; cv=pass; d=google.com; s=arc-20160816; b=IuUHiuhfyh3cdocq9y+h26sEkd4oM/mPp9iTVbVJI9ZpkV6h1zvWZRfda0FbkG1JTR c6TvK+nCVCQuNyZoS0l19mMSqymTVGf11NAYhSZWIY58PoF4R/w2/dpqbkM+NSV0uqBV xjKIhKXBmHqqTNJYmG2Hl9Ws4IEuje8CLLEVXRrPQsG2xXCjcArGOsl6ZmJ2Js6C83ad v38rxVvc7Ecd4pT2bKSbzrpogqnIIPbDaHrMT0wNczzg9dwya9C32qWwlXUM1D0EsPh/ w0ZPtVy+OJz/s80jwfUPWme3yqub4ctM4lfTlsOt7q6SIBropvrDI9GhT5goKvKsm25w HEqg== 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=PHhaTAWo7RsTp/j7JCnL7YHxZJ3GcBUrrT8apaUXzRI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HWjEtqcdT8mcNXUX0JXatbdvHmo3DHDfH3OdGB+vrPYcTJtFEmO7JUqIt1GS2PM3n/ rk9uTQYIVDj6qpLR3bjLHlWALIYpPFxFpF7yuI8LAzQnjV6Dl2QTWR1JqKqpkmTMudRs uI3kodNgdI1XC6YgyHUUyPkK2/v/m1AuwEewmudQidwkq7LRG5v90+hxktREU+rkZ84j 8KFoHF8nUYtmJujIXY+M5AFjZylKXpuLS+MZ8h1UET7vEKIQXAu3S6NIEPY5cHrxhhvf wpxmzRHFwESQtCYTVL8xl0rtLQ1i44lb5TJIgvbw2FRtcPMEqmu7IuxMZhnklSW6kX4p gZaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eIUCFlvc; 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 po13-20020a05620a384d00b0078724a778f4si7807508qkn.206.2024.02.19.21.22.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 21:22:11 -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=eIUCFlvc; 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 2A3273858CDA for ; Tue, 20 Feb 2024 05:22:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A3273858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708406531; bh=PHhaTAWo7RsTp/j7JCnL7YHxZJ3GcBUrrT8apaUXzRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eIUCFlvcBsOMVik6zEK/n46OYDPAOCWm4Og4VOUTQvLyz9V6O11c6bdTWyzZAaAgz 9fwabrERz4EfGMKmMwoH67o3n0e0MiAleDkU940Mm04ZJrXcye96JZT/NjYrYV7k+Z zffIvVMMzdo6zYkuFza4eXBtd/OMY4wT8BkRnynA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 170AB3858D28; Tue, 20 Feb 2024 05:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 170AB3858D28 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 170AB3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708406465; cv=none; b=YRA5T6i+1e333y+uOdFWLGp69eslKIfbhej74dRfI6+jjL7oFqhxAlPjzZIMPaQy+7MYkws6HABcx7UOXNWf8L5qyqR0nc5HGhwSJEbiUoM4i0NOoJgivyktU56KVG2Kybub/JCmrfCIHvN5nM4SvO1gfd8eJzACPx6OaBbSwHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708406465; c=relaxed/simple; bh=gMta9oX5X3xv4Bd0ppvuAn1Qt1zFZPBMD0WqPXmmMxA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BDfFZtFFcJ00yqfxf7ZnBF/BnLfI2hK84/WzKsIsuNY4sH+StTP5KxW1SkLnrwo+UPwHiQhTqARzOODKZIvousEf8fX2/KtHFEgtRIeHerm0tvki/0Av8mKQzp5kEeMX9scdUQlkj9MimpOofYZEkgaPTEDB89IYmLoPj5zf4yI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41K5FXvS015150; Tue, 20 Feb 2024 05:21:00 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wckgqrf30-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 05:21:00 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41K5KjEE031405 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 21:20:45 -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 41K5KilC028937 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 21:20:45 -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 v8 23/24] c++: Implement __is_invocable built-in trait Date: Mon, 19 Feb 2024 21:20:19 -0800 Message-ID: <20240220052021.50826-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: nZpv_NbJ_c_pyRoxN87kf4uMJYz14V2Q X-Proofpoint-ORIG-GUID: nZpv_NbJ_c_pyRoxN87kf4uMJYz14V2Q 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-20_04,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1034 priorityscore=1501 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 impostorscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402200036 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.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: 1791394087459851298 X-GMAIL-MSGID: 1791394087459851298 This patch implements built-in trait for std::is_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __is_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. * cp-tree.h (build_invoke): New function. * method.cc (build_invoke): New function. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_invocable. * g++.dg/ext/is_invocable1.C: New test. * g++.dg/ext/is_invocable2.C: New test. * g++.dg/ext/is_invocable3.C: New test. * g++.dg/ext/is_invocable4.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-tree.h | 2 + gcc/cp/method.cc | 132 +++++++++ gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_invocable1.C | 349 +++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_invocable2.C | 139 +++++++++ gcc/testsuite/g++.dg/ext/is_invocable3.C | 51 ++++ gcc/testsuite/g++.dg/ext/is_invocable4.C | 33 +++ 10 files changed, 720 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable1.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable2.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable3.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable4.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 23ea66d9c12..c87b126fdb1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3791,6 +3791,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_INVOCABLE: + if (!t2) + inform (loc, " %qT is not invocable", t1); + else + inform (loc, " %qT is not invocable by %qE", t1, t2); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 85056c8140b..6cb2b55f4ea 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -75,6 +75,7 @@ DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_INVOCABLE, "__is_invocable", -1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 334c11396c2..261d3a71faa 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7334,6 +7334,8 @@ extern tree get_copy_assign (tree); extern tree get_default_ctor (tree); extern tree get_dtor (tree, tsubst_flags_t); extern tree build_stub_object (tree); +extern tree build_invoke (tree, const_tree, + tsubst_flags_t); extern tree strip_inheriting_ctors (tree); extern tree inherited_ctor_binfo (tree); extern bool base_ctor_omit_inherited_parms (tree); diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 98c10e6a8b5..8c7352abcde 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1928,6 +1928,138 @@ build_trait_object (tree type) return build_stub_object (type); } +/* [func.require] Build an expression of INVOKE(FN_TYPE, ARG_TYPES...). If the + given is not invocable, returns error_mark_node. */ + +tree +build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain) +{ + if (fn_type == error_mark_node || arg_types == error_mark_node) + return error_mark_node; + + gcc_assert (TYPE_P (fn_type)); + gcc_assert (TREE_CODE (arg_types) == TREE_VEC); + + /* Access check is required to determine if the given is invocable. */ + deferring_access_check_sentinel acs (dk_no_deferred); + + /* INVOKE is an unevaluated context. */ + cp_unevaluated cp_uneval_guard; + + bool is_ptrdatamem; + bool is_ptrmemfunc; + if (TREE_CODE (fn_type) == REFERENCE_TYPE) + { + tree deref_fn_type = TREE_TYPE (fn_type); + is_ptrdatamem = TYPE_PTRDATAMEM_P (deref_fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (deref_fn_type); + + /* Dereference fn_type if it is a pointer to member. */ + if (is_ptrdatamem || is_ptrmemfunc) + fn_type = deref_fn_type; + } + else + { + is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type); + } + + if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1) + /* Only a pointer to data member with one argument is invocable. */ + return error_mark_node; + + if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0) + /* A pointer to member function with no arguments is not invocable. */ + return error_mark_node; + + /* Construct an expression of a pointer to member. */ + tree ptrmem_expr; + if (is_ptrdatamem || is_ptrmemfunc) + { + tree datum_type = TREE_VEC_ELT (arg_types, 0); + + /* datum must be a class type or a reference/pointer to a class type. */ + if (TYPE_REF_P (datum_type) || POINTER_TYPE_P (datum_type)) + { + if (!CLASS_TYPE_P (TREE_TYPE (datum_type))) + return error_mark_node; + } + else if (!CLASS_TYPE_P (datum_type)) + return error_mark_node; + + bool is_refwrap = false; + if (CLASS_TYPE_P (datum_type)) + { + /* 1.2 & 1.5: Handle std::reference_wrapper. */ + tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (datum_type)); + if (decl_in_std_namespace_p (datum_decl)) + { + const_tree name = DECL_NAME (datum_decl); + if (name && (id_equal (name, "reference_wrapper"))) + { + /* Retrieve T from std::reference_wrapper, + i.e., decltype(datum.get()). */ + is_refwrap = true; + const_tree template_info = TYPE_TEMPLATE_INFO (datum_type); + const_tree template_args = TYPE_TI_ARGS (template_info); + datum_type = TREE_VEC_ELT (template_args, 0); + } + } + } + + tree datum_expr = build_trait_object (datum_type); + tree fn_expr = build_trait_object (fn_type); + ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain); + + if (error_operand_p (ptrmem_expr) && !is_refwrap) + { + tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type); + const bool ptrmem_is_base_of_datum = + same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type, + datum_type) + || DERIVED_FROM_P (ptrmem_class_type, datum_type); + + if (!ptrmem_is_base_of_datum) + { + /* 1.3 & 1.6: Try to dereference datum_expr. */ + datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr, + RO_UNARY_STAR, NULL_TREE, + complain); + /* Rebuild ptrmem_expr. */ + ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, + complain); + } + } + /* 1.1 & 1.4: Otherwise. */ + + if (error_operand_p (ptrmem_expr)) + return error_mark_node; + + if (is_ptrdatamem) + return ptrmem_expr; + } + + /* Construct expressions for arguments to INVOKE. For a pointer to member + function, the first argument, which is the object, is not arguments to + the function. */ + releasing_vec args; + for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i) + { + tree arg_type = TREE_VEC_ELT (arg_types, i); + tree arg = build_trait_object (arg_type); + vec_safe_push (args, arg); + } + + tree invoke_expr; + if (is_ptrmemfunc) + invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args, + complain); + else /* 1.7. */ + invoke_expr = finish_call_expr (build_trait_object (fn_type), &args, false, + false, complain); + return invoke_expr; +} + /* Determine which function will be called when looking up NAME in TYPE, called with a single ARGTYPE argument, or no argument if ARGTYPE is null. FLAGS and COMPLAIN are as for build_new_method_call. diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7242db75248..149c0631d62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12467,6 +12467,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_INVOCABLE: + return !error_operand_p (build_invoke (type1, type2, tf_none)); + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12682,6 +12685,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CONVERTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 7f7b27f7aa7..d2a7ebdf25c 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -104,6 +104,9 @@ #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif +#if !__has_builtin (__is_invocable) +# error "__has_builtin (__is_invocable) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_invocable1.C b/gcc/testsuite/g++.dg/ext/is_invocable1.C new file mode 100644 index 00000000000..d21ae1d1958 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable1.C @@ -0,0 +1,349 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type_v0 = void(*)(); + +SA( __is_invocable( func_type_v0 ) ); +SA( ! __is_invocable( func_type_v0, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( func_type_i0 ) ); +SA( ! __is_invocable( func_type_i0, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( func_type_l0 ) ); +SA( ! __is_invocable( func_type_l0(int) ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( func_type_ii ) ); +SA( __is_invocable( func_type_ii, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( func_type_il ) ); +SA( ! __is_invocable( func_type_il, int ) ); +SA( __is_invocable( func_type_il, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( func_type_ir ) ); +SA( ! __is_invocable( func_type_ir, int& ) ); +SA( __is_invocable( func_type_ir, int ) ); +SA( __is_invocable( func_type_ir, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( mem_type_i ) ); +SA( ! __is_invocable( mem_type_i, int ) ); +SA( ! __is_invocable( mem_type_i, int* ) ); +SA( ! __is_invocable( mem_type_i, int& ) ); +SA( ! __is_invocable( mem_type_i, int&& ) ); +SA( __is_invocable( mem_type_i, A ) ); +SA( __is_invocable( mem_type_i, A* ) ); +SA( __is_invocable( mem_type_i, A& ) ); +SA( __is_invocable( mem_type_i, A&& ) ); +SA( __is_invocable( mem_type_i, const A& ) ); +SA( ! __is_invocable( mem_type_i, A&, int ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( memfun_type_i ) ); +SA( ! __is_invocable( memfun_type_i, int ) ); +SA( ! __is_invocable( memfun_type_i, int* ) ); +SA( ! __is_invocable( memfun_type_i, int& ) ); +SA( ! __is_invocable( memfun_type_i, int&& ) ); +SA( __is_invocable( memfun_type_i, A ) ); +SA( __is_invocable( memfun_type_i, A* ) ); +SA( __is_invocable( memfun_type_i, A& ) ); +SA( __is_invocable( memfun_type_i, A&& ) ); +SA( ! __is_invocable( memfun_type_i, const A& ) ); +SA( ! __is_invocable( memfun_type_i, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( memfun_type_ic ) ); +SA( ! __is_invocable( memfun_type_ic, int ) ); +SA( ! __is_invocable( memfun_type_ic, int& ) ); +SA( __is_invocable( memfun_type_ic, A& ) ); +SA( __is_invocable( memfun_type_ic, A* ) ); +SA( ! __is_invocable( memfun_type_ic, A&, int ) ); +SA( ! __is_invocable( memfun_type_ic, A*, int& ) ); +SA( __is_invocable( memfun_type_ic, const A& ) ); +SA( __is_invocable( memfun_type_ic, const A* ) ); +SA( ! __is_invocable( memfun_type_ic, const A&, int& ) ); +SA( ! __is_invocable( memfun_type_ic, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( memfun_type_iic ) ); +SA( ! __is_invocable( memfun_type_iic, int ) ); +SA( ! __is_invocable( memfun_type_iic, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A&, int ) ); +SA( __is_invocable( memfun_type_iic, A&, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A*, int ) ); +SA( __is_invocable( memfun_type_iic, A*, int& ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int&, int ) ); +SA( __is_invocable( memfun_type_iic, const A&, int& ) ); +SA( __is_invocable( memfun_type_iic, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( B ) ); +SA( __is_invocable( B& ) ); +SA( __is_invocable( B&& ) ); +SA( ! __is_invocable( B* ) ); +SA( __is_invocable( CB ) ); +SA( __is_invocable( CB& ) ); +SA( ! __is_invocable( CB* ) ); + +SA( __is_invocable( B, int ) ); +SA( __is_invocable( B&, int ) ); +SA( __is_invocable( B&&, int ) ); +SA( ! __is_invocable( B*, int ) ); +SA( ! __is_invocable( CB, int ) ); +SA( ! __is_invocable( CB&, int ) ); +SA( ! __is_invocable( CB*, int ) ); + +SA( ! __is_invocable( B, int, int ) ); +SA( ! __is_invocable( B&, int, int ) ); +SA( ! __is_invocable( B&&, int, int ) ); +SA( ! __is_invocable( B*, int, int ) ); +SA( ! __is_invocable( CB, int, int ) ); +SA( ! __is_invocable( CB&, int, int ) ); +SA( ! __is_invocable( CB*, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( C ) ); +SA( ! __is_invocable( C& ) ); +SA( ! __is_invocable( C&& ) ); +SA( ! __is_invocable( C* ) ); +SA( ! __is_invocable( CC ) ); +SA( ! __is_invocable( CC& ) ); +SA( ! __is_invocable( CC* ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( D ) ); + +struct E { void v(); }; +using CE = const E; + +SA( ! __is_invocable( E ) ); +SA( ! __is_invocable( void (E::*)() ) ); +SA( __is_invocable( void (E::*)(), E ) ); +SA( __is_invocable( void (E::*)(), E* ) ); +SA( ! __is_invocable( void (E::*)(), CE ) ); + +struct F : E {}; +using CF = const F; + +SA( ! __is_invocable( F ) ); +SA( __is_invocable( void (E::*)(), F ) ); +SA( __is_invocable( void (E::*)(), F* ) ); +SA( ! __is_invocable( void (E::*)(), CF ) ); + +struct G { E operator*(); }; +using CG = const G; + +SA( ! __is_invocable( G ) ); +SA( __is_invocable( void (E::*)(), G ) ); +SA( ! __is_invocable( void (E::*)(), G* ) ); +SA( ! __is_invocable( void (E::*)(), CG ) ); + +struct H { E& operator*(); }; +using CH = const H; + +SA( ! __is_invocable( H ) ); +SA( __is_invocable( void (E::*)(), H ) ); +SA( ! __is_invocable( void (E::*)(), H* ) ); +SA( ! __is_invocable( void (E::*)(), CH ) ); + +struct I { E&& operator*(); }; +using CI = const I; + +SA( ! __is_invocable( I ) ); +SA( __is_invocable( void (E::*)(), I ) ); +SA( ! __is_invocable( void (E::*)(), I* ) ); +SA( ! __is_invocable( void (E::*)(), CI ) ); + +struct K { E* operator*(); }; +using CK = const K; + +SA( ! __is_invocable( K ) ); +SA( ! __is_invocable( void (E::*)(), K ) ); +SA( ! __is_invocable( void (E::*)(), K* ) ); +SA( ! __is_invocable( void (E::*)(), CK ) ); + +struct L { CE operator*(); }; +using CL = const L; + +SA( ! __is_invocable( L ) ); +SA( ! __is_invocable( void (E::*)(), L ) ); +SA( ! __is_invocable( void (E::*)(), L* ) ); +SA( ! __is_invocable( void (E::*)(), CL ) ); + +struct M { + int i; +private: + long l; +}; +using CM = const M; + +SA( ! __is_invocable( M ) ); +SA( ! __is_invocable( M& ) ); +SA( ! __is_invocable( M&& ) ); +SA( ! __is_invocable( M* ) ); +SA( ! __is_invocable( CM ) ); +SA( ! __is_invocable( CM& ) ); +SA( ! __is_invocable( CM* ) ); + +SA( ! __is_invocable( int M::* ) ); +SA( __is_invocable( int M::*, M ) ); +SA( __is_invocable( int M::*, M& ) ); +SA( __is_invocable( int M::*, M&& ) ); +SA( __is_invocable( int M::*, M* ) ); +SA( __is_invocable( int M::*, CM ) ); +SA( __is_invocable( int M::*, CM& ) ); +SA( __is_invocable( int M::*, CM* ) ); +SA( ! __is_invocable( int M::*, int ) ); + +SA( ! __is_invocable( int CM::* ) ); +SA( __is_invocable( int CM::*, M ) ); +SA( __is_invocable( int CM::*, M& ) ); +SA( __is_invocable( int CM::*, M&& ) ); +SA( __is_invocable( int CM::*, M* ) ); +SA( __is_invocable( int CM::*, CM ) ); +SA( __is_invocable( int CM::*, CM& ) ); +SA( __is_invocable( int CM::*, CM* ) ); +SA( ! __is_invocable( int CM::*, int ) ); + +SA( ! __is_invocable( long M::* ) ); +SA( __is_invocable( long M::*, M ) ); +SA( __is_invocable( long M::*, M& ) ); +SA( __is_invocable( long M::*, M&& ) ); +SA( __is_invocable( long M::*, M* ) ); +SA( __is_invocable( long M::*, CM ) ); +SA( __is_invocable( long M::*, CM& ) ); +SA( __is_invocable( long M::*, CM* ) ); +SA( ! __is_invocable( long M::*, long ) ); + +SA( ! __is_invocable( long CM::* ) ); +SA( __is_invocable( long CM::*, M ) ); +SA( __is_invocable( long CM::*, M& ) ); +SA( __is_invocable( long CM::*, M&& ) ); +SA( __is_invocable( long CM::*, M* ) ); +SA( __is_invocable( long CM::*, CM ) ); +SA( __is_invocable( long CM::*, CM& ) ); +SA( __is_invocable( long CM::*, CM* ) ); +SA( ! __is_invocable( long CM::*, long ) ); + +SA( ! __is_invocable( short M::* ) ); +SA( __is_invocable( short M::*, M ) ); +SA( __is_invocable( short M::*, M& ) ); +SA( __is_invocable( short M::*, M&& ) ); +SA( __is_invocable( short M::*, M* ) ); +SA( __is_invocable( short M::*, CM ) ); +SA( __is_invocable( short M::*, CM& ) ); +SA( __is_invocable( short M::*, CM* ) ); +SA( ! __is_invocable( short M::*, short ) ); + +SA( ! __is_invocable( short CM::* ) ); +SA( __is_invocable( short CM::*, M ) ); +SA( __is_invocable( short CM::*, M& ) ); +SA( __is_invocable( short CM::*, M&& ) ); +SA( __is_invocable( short CM::*, M* ) ); +SA( __is_invocable( short CM::*, CM ) ); +SA( __is_invocable( short CM::*, CM& ) ); +SA( __is_invocable( short CM::*, CM* ) ); +SA( ! __is_invocable( short CM::*, short ) ); + +struct N { M operator*(); }; +SA( __is_invocable( int M::*, N ) ); +SA( ! __is_invocable( int M::*, N* ) ); + +struct O { M& operator*(); }; +SA( __is_invocable( int M::*, O ) ); +SA( ! __is_invocable( int M::*, O* ) ); + +struct P { M&& operator*(); }; +SA( __is_invocable( int M::*, P ) ); +SA( ! __is_invocable( int M::*, P* ) ); + +struct Q { M* operator*(); }; +SA( ! __is_invocable( int M::*, Q ) ); +SA( ! __is_invocable( int M::*, Q* ) ); + +struct R { void operator()(int = 0); }; + +SA( __is_invocable( R ) ); +SA( __is_invocable( R, int ) ); +SA( ! __is_invocable( R, int, int ) ); + +struct S { void operator()(int, ...); }; + +SA( ! __is_invocable( S ) ); +SA( __is_invocable( S, int ) ); +SA( __is_invocable( S, int, int ) ); +SA( __is_invocable( S, int, int, int ) ); + +void fn1() {} + +SA( __is_invocable( decltype(fn1) ) ); + +void fn2(int arr[10]); + +SA( __is_invocable( decltype(fn2), int[10] ) ); +SA( __is_invocable( decltype(fn2), int(&)[10] ) ); +SA( __is_invocable( decltype(fn2), int(&&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&&)[10] ) ); +SA( __is_invocable( decltype(fn2), int[] ) ); + +auto lambda = []() {}; + +SA( __is_invocable( decltype(lambda) ) ); + +template +struct can_invoke { + static constexpr bool value = __is_invocable( Func, Args... ); +}; + +SA( can_invoke::value ); + +struct T { + void func() const {} + int data; +}; + +SA( __is_invocable( decltype(&T::func)&, T& ) ); +SA( __is_invocable( decltype(&T::data)&, T& ) ); + +struct U { }; +struct V : U { U& operator*() = delete; }; +SA( __is_invocable( int U::*, V ) ); + +struct W : private U { U& operator*(); }; +SA( ! __is_invocable( int U::*, W ) ); + +struct X { int m; }; +struct Y { X& operator*(); }; +struct Z : Y { }; +SA( __is_invocable(int X::*, Z) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable2.C b/gcc/testsuite/g++.dg/ext/is_invocable2.C new file mode 100644 index 00000000000..a68aefd3e13 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable2.C @@ -0,0 +1,139 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle std::reference_wrapper correctly. + +#include + +#define SA(X) static_assert((X),#X) + +using std::reference_wrapper; + +using func_type_v0 = void(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); +SA( ! __is_invocable( reference_wrapper, const A& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( ! __is_invocable( reference_wrapper, A*, int& ) ); +SA( __is_invocable( reference_wrapper, const A& ) ); +SA( __is_invocable( reference_wrapper, const A* ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( __is_invocable( reference_wrapper, A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, A*, int ) ); +SA( __is_invocable( reference_wrapper, A*, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int&, int ) ); +SA( __is_invocable( reference_wrapper, const A&, int& ) ); +SA( __is_invocable( reference_wrapper, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper&& ) ); +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper&, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper* ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper* ) ); + +std::function fn = []() {}; +auto refwrap = std::ref(fn); + +SA( __is_invocable( decltype(fn) ) ); +SA( __is_invocable( decltype(refwrap) ) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable3.C b/gcc/testsuite/g++.dg/ext/is_invocable3.C new file mode 100644 index 00000000000..8699b0a53ca --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable3.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle incomplete class correctly. + +#define SA(X) static_assert((X),#X) + +struct Incomplete; + +SA( ! __is_invocable( Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int, Incomplete, int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int, Incomplete ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete() ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int), int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int, int), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete(), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int(Incomplete), Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), int, Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( __is_invocable( int(Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(Incomplete&&), Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&&), int, Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&&), const Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&&), int, const Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, const Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int Incomplete::*, const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( ! __is_invocable( void (Incomplete::*)(long&), const Incomplete*, long& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( void (Incomplete::*)(long&) const, Incomplete*, long& ) ); // { dg-bogus "incomplete type" } + +template +struct Holder { T t; }; + +SA( __is_invocable( int(Holder&), Holder& ) ); // { dg-bogus "incomplete type" } + +// Define Incomplete, which is now not incomplete. +struct Incomplete { void operator()(); }; + +SA( __is_invocable( Incomplete ) ); // { dg-bogus "incomplete type" } diff --git a/gcc/testsuite/g++.dg/ext/is_invocable4.C b/gcc/testsuite/g++.dg/ext/is_invocable4.C new file mode 100644 index 00000000000..d1efccf08f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable4.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +#define SA(X) static_assert((X),#X) + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_invocable +: public bool_constant<__is_invocable(_Fn, _ArgTypes...)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_invocable_v = __is_invocable(_Fn, _ArgTypes...); +#endif + +class Private +{ + void operator()() const + { + SA( ! is_invocable::value ); +#if __cpp_variable_templates + SA( ! is_invocable_v ); +#endif + } +}; + +SA( ! is_invocable::value ); +#if __cpp_variable_templates +SA( ! is_invocable_v ); +#endif From patchwork Tue Feb 20 05:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 203419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp202780dyc; Mon, 19 Feb 2024 21:23:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXTkHg3Q0fObOpb5B3nIiPVcZcVxrD3HFKs3ZlQ5n7EgK9SodS+m5fnbWDEeM2Vzq/8BLdmtcHfwiEJuBHm96ql/Pvmtw== X-Google-Smtp-Source: AGHT+IE+iknOnvrBJWj9npFYRfZoPpzPE9D5TL4MI24kOclKaQlH5mjyj6AsojSAOqjGiBj45wAc X-Received: by 2002:a05:620a:51ce:b0:787:2270:fa52 with SMTP id cx14-20020a05620a51ce00b007872270fa52mr14884169qkb.45.1708406594437; Mon, 19 Feb 2024 21:23:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708406594; cv=pass; d=google.com; s=arc-20160816; b=YdrVxYt82TorcHKyD1PN6FEhoglx7jT8eloxuy9t3lq7LIyegGjbbvYqapg3T6zjXQ qdm/hjmSWuqCNm0are80j8GzGmrHyTpL6Wa6/D9KOKKr/5BpD5S9bR0EIh1VhmNl+AAg j4q+BPYjax8s8aNBhpJ0OQndsq9zaCRp3iqAd8KdcrTUsC57XudzpV+xxtHd1lSGRyBC smQjiqI9dU73ko/7zxBfHVNTZVOKSLFRACc4HT8FbDrTA28meX4P8JG4lkd7C5phmLGI GIPTkXMihJy6jovO++mbwyF4VkFiKtSODkver5jRgHFpAtH4MQKZQWi/6gDxaY3wdQki fC0w== 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=d3ZEbirb0AWQf+wgxmRmUTSOBbnvjcqvZquGBBr3pOk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=RPkUE+tWwPwXrpQe1/FWLsSFimBO3ZWjW3tTO3346ehsxZPH2juIgAwEMUjhrYMaaC OxHRlmL4KtFk+Z1BFO2SIQqzE3/iRRaO7ahYtA3au4HrGlB+2TjRJC1+/etq8OxOpju4 16zusqPfKc3X3rKWIOrsIZ6FGqwOL2d4/vPkKquVp3w0BjlZ0n9PDrmJwuLFEvRSbpO9 c5sakTh1eOdF5IJusHQHLLz5yPBi/rMy/fA4NShG3oYLuWMPZXi9B0svcwlQcy7hj3+g 2W4A6NctHmBS8udfv9sjHoZq4QwQ0bPpsSbIThIBQhVZ9pERvlyj7RQ6CO9CD3FyLWfI caew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="felGD1g/"; 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 u4-20020a05620a022400b0078725bf52b5si7907872qkm.347.2024.02.19.21.23.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 21:23:14 -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="felGD1g/"; 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 083EF3858C20 for ; Tue, 20 Feb 2024 05:23:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 083EF3858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708406594; bh=d3ZEbirb0AWQf+wgxmRmUTSOBbnvjcqvZquGBBr3pOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=felGD1g/RdAGp50bkqg6OgsCUW3YjSuVzzN2M3ZH2b37DyPmSjXuc7PP4F5vi/SwZ 1pg2U/eaGJuns/mCqqY4t4yUfSt+6WlR+jAIfu8kdAwqfH0WY2tCZi9nlC+u+Rs9T/ fTRlT/LUP0ClSbvokMv6uLaxxYqwGBE8ebXtZ4nQ= 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 4778B3858CD1; Tue, 20 Feb 2024 05:21:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4778B3858CD1 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 4778B3858CD1 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=1708406482; cv=none; b=HEvWEuO90ZKtJkierSwytKgQ1VIgupjsjnRtLydR1R+SgoJzSPlytBTm9Os3adQD+fBapeLLzSLGiuTWnEriUoXCWzc8CeM2/VtxtS+17scuLaXmMnvRub1jjD2DVcVSH7w3ANqsJsnaYetKIJMk/DDbvwIkb+SZgFGnowydHWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708406482; c=relaxed/simple; bh=bSuhrA/IYi2balH00VvByoLz9FuqWQp6fQDwg0+iyKM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KG81gE0t/MoyGQ4OOd+txqq46rGjSmaHa9oTkBiWRv5cOqJhFjx2RxiQ5Otbt1y1YfsdGOcbIbbWRbJNu2mHJHdGUZ76QZKgbNITVIS5X5mGzMYltZfAK2hQ/+4JzX3iYdgIvZP/5cfKMgUsOZ9uWHyITw+oqYc/E4Rvlp7DwpQ= 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 41K5IHbu012897; Tue, 20 Feb 2024 05:21:19 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wcgs3s4u9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Feb 2024 05:21:19 +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 41K5Knsi008962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Feb 2024 21:20:49 -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 41K5KilD028937 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 21:20:49 -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 v8 24/24] libstdc++: Optimize std::is_invocable compilation performance Date: Mon, 19 Feb 2024 21:20:20 -0800 Message-ID: <20240220052021.50826-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> References: <20240219135129.3635809-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: OxEwGjq3r4Qy1c-lDx8hztuQ9tFGsBko X-Proofpoint-ORIG-GUID: OxEwGjq3r4Qy1c-lDx8hztuQ9tFGsBko 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-20_04,2024-02-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 impostorscore=0 clxscore=1034 mlxscore=0 mlxlogscore=945 suspectscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402200036 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, 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: 1791394153177371228 X-GMAIL-MSGID: 1791394153177371228 This patch optimizes the compilation performance of std::is_invocable by dispatching to the new __is_invocable built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_invocable): Use __is_invocable built-in trait. * testsuite/20_util/is_invocable/incomplete_args_neg.cc: Handle the new error from __is_invocable. * testsuite/20_util/is_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ .../testsuite/20_util/is_invocable/incomplete_args_neg.cc | 1 + .../testsuite/20_util/is_invocable/incomplete_neg.cc | 1 + 3 files changed, 8 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1577042a5b8..51d6df5ca66 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3233,9 +3233,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; /// std::is_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable) + template + struct is_invocable + : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)> +#else template struct is_invocable : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type +#endif { static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), "_Fn must be a complete class or an unbounded array"); diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc index a575750f9e9..9619129b817 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc index 05848603555..b478ebce815 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include