From patchwork Thu May 2 20:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=P8b4QmR9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlfQ26V1z1ydT for ; Fri, 3 May 2024 06:19:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F76E385E83E for ; Thu, 2 May 2024 20:19:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F76E385E83E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681196; bh=8B1uA7J19w3JslDOAPJNyrod2AEvmT970UKCaPfnu5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P8b4QmR9Ev3nd+J1STXopH3seJo++v7xRNQVrG5LiqVwSL+K6KKntPltxpBEsY22m zfWf+Fv9P9TJtbbTutC4SKKb5iOxo+V3eCiHBEr3xVFquBw5Y9S091BFH2UrlwAEuB 1AmCbcKfS9ZnQvKETiIooBimTW0kWbbM0ccDrry8= 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 4F3883849AE3; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F3883849AE3 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 4F3883849AE3 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=1714680977; cv=none; b=LKiP9/gBJD0/m86KZl3FthVo4sItgiRVmwQHT7ZWIGlSMUu4Fe3lQ3bK2HYLpwKwQZU+6szejTeR4X4ZAcoRgF2/xBPTyiRJi1+g1b+QmTNgz8XbiQ6wo0dZFurlRwYmKSDQBIyLBX/+kwAZwP6cCi00mBNuvYrI3FAwcSa+mtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680977; c=relaxed/simple; bh=Ne1Ye40xOMdmVzZlIthnRmmROOAhHoSbKbgzvcxokGk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=opV/parymto+rO+ayzhdusjFCUYNydTesWZbnc1yr53s2ZQavZpQfkv3gag1YH/Z5HO1Rc4mk4nffzXIlO9W8Nmp5iPCuM6FOXUL8fSppxPVZs4Kgh0BuRr7/63eYMXMDVEvdW9b9zsJ/zMVUwGVW+RXc1RHbwvAsvcJ01i9zdU= 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.18.1.2/8.18.1.2) with ESMTP id 442KFR56017068; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559knj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFqd3013897 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:52 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmO009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 01/26] c++: Implement __is_const built-in trait Date: Thu, 2 May 2024 13:12:02 -0700 Message-ID: <20240502201549.459244-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: cKGppTZn8p3OgSxuOE5jjNkzKV9ULXpy X-Proofpoint-ORIG-GUID: cKGppTZn8p3OgSxuOE5jjNkzKV9ULXpy X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=770 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 8a3b5d80ba7..eaf17a50877 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3768,6 +3768,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 2dde65a970b..fa7ba6a9edc 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12530,6 +12530,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); @@ -12812,6 +12815,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 Thu May 2 20:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=P6vGOMZf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlv41PvNz20fW for ; Fri, 3 May 2024 06:30:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 414D33849AFA for ; Thu, 2 May 2024 20:30:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 414D33849AFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681854; bh=sJYCb+DV69Z6BOBajuOf6/DZpEVNuW1brJD4e4TbbTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P6vGOMZfQ6fkQ1Q1aos+BnRhv4DrNwVOj0X874K0iF214bGEibH9znNkpusBGWjPp CPdrzxDgsEu8BwbVAvI2e6lsu9HcxDLjgnRFKge/C4QA4yMpGFxSYTbPP935gtYmrD iwTTesMUTNfXRk79WiW/VfUwQPgmYnMqgrdRiJsU= 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 D81EB3849AE8; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D81EB3849AE8 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 D81EB3849AE8 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=1714680987; cv=none; b=wqt+kySDHt7g0X7B2N1ooUzVkOOIwLEptLYwdXyJ7MS0JRcpxfF2ng8da2krKWrtvD4m4W29zuiasZZpRiawhz/dz82gLRfd/4WQkX1xSazENKn3HDDvkgGH2EcaN6U5A9IVMQa4IxX0XUz1SeRl1VRCQka3sLD5ZG60SMPaBA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680987; c=relaxed/simple; bh=QYvyzo9GCFR60fTWF8UZijjpf8Fa9x26FbkUTLDehBk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=as6ehYSVX1TvuC9jgJUOD/R2sH6pchlrqtyw/huwO4JibmgUObQfpaJDlngh2+CPfjnLXDHF3KL8iLDgSCoJPOSVctq5HyiCbbmJFoecST1Af8oLaSkleTgPcqPnMfedhTPpq7f2TlufCbH/AZ94TUbHI0Q609+R66fBP4dAzTY= 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.18.1.2/8.18.1.2) with ESMTP id 442K8Qww003025; Thu, 2 May 2024 20:16:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvfu8949n-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:03 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFqxU013899 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:53 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmP009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 02/26] libstdc++: Optimize std::is_const compilation performance Date: Thu, 2 May 2024 13:12:03 -0700 Message-ID: <20240502201549.459244-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: UofPjlSPJ-8YUaCfQaNFRFPvN0Qjre1w X-Proofpoint-ORIG-GUID: UofPjlSPJ-8YUaCfQaNFRFPvN0Qjre1w X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=804 priorityscore=1501 phishscore=0 clxscore=1034 impostorscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 b441bf9908f..8df0cf3ac3b 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 @@ -3331,10 +3338,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 Thu May 2 20:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Ik7buHMI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlb76lMvz1ydT for ; Fri, 3 May 2024 06:17:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC7EF3849AEC for ; Thu, 2 May 2024 20:17:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC7EF3849AEC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681026; bh=pLM3+qKGL/ngFID/GKW7woOEhsyF05M1twZQm9LGl9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ik7buHMIjRafEFw/ldB8j0nknKQ/IJtJ7hvPCygvyWTmg7WiLITgwchFOW+M/z0IL aqcO+wMQqBgDEP/6H5JXC0esoO0TZTgjHF9tlX/+XoAwnffdbTKQ/5EmfARUPyulf9 S7f5h6oF89dpO9atCQgVGa9Zlhq+Dqv6ahPjRCUk= 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 0AD66384AB53; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0AD66384AB53 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 0AD66384AB53 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=1714680965; cv=none; b=EMwI7pKHv8sowDwsw56QQBAzV6aD8llv0veFnZeoO7sxWqQ9HcxhY2lHXJIY2+IguGUipg50UGFFCAQPoU+zlT0nc3EgqEbcE5hqqfaIdRaaVByAEwErGRZjZYAJt83IKDZuHY+sBYxF1N7A0ND5F42ceW0dCTKJ+gEBSHjxmfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680965; c=relaxed/simple; bh=onLdlE4yTIKjjA00VLUbYJI9KNFgY2WZnutsp9qW/N4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CL2mgeM9RYNidc9p0OxFCUGjmXFu9plFGAbdyOhXKFNmwJXMLfIssCjoeI4RC/pZqZ+bS0YGXAH/zLcw4qdvlQf1K6aNaRhXmW1tWu57Rxi1HPzTTNZHIUkRecYHxXMSf8vQ3rhmlhB2EyWU2szBlNDcoWuzqdmLkGjecTBrhm4= 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.18.1.2/8.18.1.2) with ESMTP id 442K5Mpc016508; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559knd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFrs7003569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:53 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmQ009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 03/26] c++: Implement __is_volatile built-in trait Date: Thu, 2 May 2024 13:12:04 -0700 Message-ID: <20240502201549.459244-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: OegA4pBoDl7QcyCrxIHt8v6X6Jl1_Npc X-Proofpoint-ORIG-GUID: OegA4pBoDl7QcyCrxIHt8v6X6Jl1_Npc X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=854 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 eaf17a50877..d9caf546423 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3862,6 +3862,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 fa7ba6a9edc..351235a639a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12616,6 +12616,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); @@ -12826,6 +12829,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 Thu May 2 20:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ffljlzlo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlhc1jgxz20fb for ; Fri, 3 May 2024 06:21:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 650823846402 for ; Thu, 2 May 2024 20:21:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 650823846402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681310; bh=QfI2QiKqV2YAtAUjajot+41k9pXcrA6QfbZH7DSaQcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ffljlzlof96F6XElocxoZzNZHhUG+tsCymETjhEQNDAQaFvO+CRW268/IUMq9CxoU 3BAqMQQtxGWYfbQ87EPWHx7Xx3b4CHMmqNbntV8MaTia1aoyIgzEPsWJIdOg8rr4aI mfs79Q6/bTXt9OTpuggn00wYd9KEyUHJLXxJ+ug4= 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 B26DD3849AE7; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B26DD3849AE7 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 B26DD3849AE7 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=1714680986; cv=none; b=Z2kG5jh5n1C15o+2VbL81jYQW3WWhkcuOSaM5xLnCXvN3QcZXoYVa+VpnuqoDohCy+j79pb2fGO6Kn/fYLjpDC7rFe6HgKdWk7I7nOyRPcOx6KtjpZNlKIkXcBs/l1WNzpZLROpDRHLvP3Tf0eS+z66n1hYjOYqOIxdp85fyjY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680986; c=relaxed/simple; bh=FK3fLNe7YS8k3ksVXMzBB6AQMQOOmssfAt5I5oaD8Qg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gt652XU0cGHiEmRIRPG64ApL+iE60kK773uv3O+uHK4+kUCnBGJken6wfGmX4Tpc58KgwHc1gso+zhmwqmZ0wnRjW0IygiVy6iaCz3GiAyr1vgY+epoyC9ar1q77LXsepF4FuqwX9ow17Wbv8xM/wRVRxJtoXh67bec0vlpsGGQ= 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.18.1.2/8.18.1.2) with ESMTP id 442KDksH030492; Thu, 2 May 2024 20:16:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf53hkds-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:03 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFr8a013900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:53 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmR009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 04/26] libstdc++: Optimize std::is_volatile compilation performance Date: Thu, 2 May 2024 13:12:05 -0700 Message-ID: <20240502201549.459244-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: c4o8zJGZVf41eDCZjHTXcuW_EtEuvlE5 X-Proofpoint-GUID: c4o8zJGZVf41eDCZjHTXcuW_EtEuvlE5 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxlogscore=761 clxscore=1034 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 8df0cf3ac3b..748fa186881 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 @@ -3360,10 +3367,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 Thu May 2 20:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Me8HrrHB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVls75CV3z1ymc for ; Fri, 3 May 2024 06:29:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D20C93846402 for ; Thu, 2 May 2024 20:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D20C93846402 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681753; bh=X0/VV2nCsQiTAXrMH4hW4no424WTnHUibFGunNc+12Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Me8HrrHBfMM5XJBmqJwnR3lOvW+4u0IrRNRdwVr2EO43DmneMUn5T0P2lvLUpoHeG PU4BkMc/G02WKOd+tUsYn4i+m1lTQrhwDfh0dy9D9oE9KfA8O7puHsgHgs5K6fJM+j DlrFcJNLKGMCGvw/Et3B8rUNCp8pOotrQxgxhX30= 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 487AE3849ADD; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 487AE3849ADD 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 487AE3849ADD 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=1714680983; cv=none; b=Hyy75Eb2liqJJrXkWHEEGwmHbcshILYdW3nnPQwjVpjC61k3aB7EfZT00P6Y6+XfFGx/LdYXUul//TGwe/g5p+9hZFGd95r5OHFNEDoXRv0aiBXQTjWPkFyjqc+/leDyQsndho+3ueEOw/bDgDG2wKh7bsKv9cdEQVENzLTt2P0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680983; c=relaxed/simple; bh=LweWSwY6iB3yoZYAXDPGBDQIfDE6g/7UBWCXaIsegCQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Y+6pl+lJtIFhuvEgJ5EASWbaD0rlmrIdHefLng0gBpEHVWjEamfo5/Etpo/xUjyr3FGbGtqjXmzG3fgv9os7V35h6KtXfrTXDdTCBQcfN13n5zxFytlvIkNdvL0bLyb6egDb+fx4DfyIC6vEhMk8hvARH2FmcwrUkWJh1oGOCN4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442K8lJW021473; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sgw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:01 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFrbl003570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:53 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmS009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 05/26] c++: Implement __is_pointer built-in trait Date: Thu, 2 May 2024 13:12:06 -0700 Message-ID: <20240502201549.459244-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mU1G-DGByWcn0ya688AHKZqjansWr5ID X-Proofpoint-GUID: mU1G-DGByWcn0ya688AHKZqjansWr5ID X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxlogscore=814 lowpriorityscore=0 mlxscore=0 clxscore=1034 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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. Arrange the order lexically around __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 | 9 +++-- gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d9caf546423..5a8aaa70fa6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,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 351235a639a..86372ea0aba 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12586,6 +12586,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); @@ -12825,6 +12828,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..4cbe6fe8cea 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,12 +119,15 @@ #if !__has_builtin (__is_object) # error "__has_builtin (__is_object) failed" #endif -#if !__has_builtin (__is_pointer_interconvertible_base_of) -# error "__has_builtin (__is_pointer_interconvertible_base_of) failed" -#endif #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_pointer_interconvertible_base_of) +# error "__has_builtin (__is_pointer_interconvertible_base_of) 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 Thu May 2 20:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1930830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yHDzE01x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlbC2K1nz1ydT for ; Fri, 3 May 2024 06:17:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 667483849AE4 for ; Thu, 2 May 2024 20:17:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 667483849AE4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681029; bh=klX9h2m+FH1BTKFQK1pCA/SRvIQjy6Uj7aHIL7TFlwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yHDzE01x1ap/MZfaXqSwjW50eXQ36+f3CTdsMqXladU8YG7D3f7QP3J8vWDd8BbHI UPif1vcYNN2seAJqR0bBE00CkA2L2BPNp/ZJ9086LANFcBs+n2htvK3CJxAfb2tBPR pODu/x8XxNIuEYS3/Y3Cx1tDXMMVGn6ZesCQU+FQ= 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 1043F3849AD0; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1043F3849AD0 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 1043F3849AD0 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=1714680965; cv=none; b=DKkMwIboc88EGmNoKb5t1x5m6T9jtZxy3bOrrDm4ZfoHlypAYitZp20wtmOX6U3+iNll+6ytYJZxNf+bt7gty6B1Hco2I7QCtqCAuSzIG1KI+fd3EtSD6zgOgdsbg7jZwR3ia+snHsGTommMlUlZgiN3cqC47nkD+JMP0a0Gq2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680965; c=relaxed/simple; bh=+wf8XIzzeR3db9+vgBF9QumECeY2ThXbyNDyKK87rs0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UNdYQyBT+6fSwwD0WF04XUbs8wpHAVKWI2eJlTDqWGJB5xwNAn+MDGozFp3lk/myi5GLC3ShtR0tlFVSpwiPR4R1wXB4xk+l1Yb3tiT13cg12s8m1eT2U6alJOsA8Dbvi9eBESsWpv4FyxA6bex1IzNbLxtBqzaFKEMJN8DV8/g= 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.18.1.2/8.18.1.2) with ESMTP id 442KAgJq028743; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sk2v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFsR0013901 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:54 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmT009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui , Jonathan Wakely Subject: [PATCH v18 06/26] libstdc++: Optimize std::is_pointer compilation performance Date: Thu, 2 May 2024 13:12:07 -0700 Message-ID: <20240502201549.459244-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: TkD0csUBgOjVlMSpQHngW4B6MC2OiqRR X-Proofpoint-ORIG-GUID: TkD0csUBgOjVlMSpQHngW4B6MC2OiqRR X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=428 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 748fa186881..ea013b4b7bc 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 @@ -3268,8 +3282,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 Thu May 2 20:12: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: 1930839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YTC6MBMX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlhV4QSYz20fb for ; Fri, 3 May 2024 06:21:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAAA8384772B for ; Thu, 2 May 2024 20:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAAA8384772B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681304; bh=86unTkiNi7E8O+I07rJk9aqzD7DKizw53Io4QttrRV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YTC6MBMXzdxi154WqxgJivBKrGXB6Mjfti5vjNs1MVusj/NtrCGbVVWz3u4xYj0lY yaSuDDe8/a77dFxehEYV0A2GGu8wLh2Hzd+CEasqwCMEXjGs34P5Y3LG0CiexV3w3m lEEpDIQzvpvegouzT9bGEvMeU4VqtcsBKmVWB6y4= 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 193B7384AB78; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 193B7384AB78 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 193B7384AB78 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=1714680971; cv=none; b=Tpu1XC53SFkjA0EcXc/8qjk8nr7oq9SEcnPDr11LL8dhbUH/lB3qdqECt9ny64ig8kWRISbaHOPVbSw4mqnm2EautJENdxaTe4VipKSkf4Tx1/hg4H5kRi+IDpqi7JxVuPuDQW2+02YC0yseRgaGYeUs1GDCVvjX02VZfclpUSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680971; c=relaxed/simple; bh=YPNPgJw250ZpdHWqF7YnOYB/JidkyClOjfPjv3oW3FM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=av8sm8b2oA6TUuPDkalwFk0Of2PDOMZdHCLNZhnxriK3G1EPtJ4lQ09oD3d4c02TgCjq5L7M8rOxFLqhRlIUUydmEFo5G1CqbGGV5UoycLaJ9TWRNzk81vSM4ywgsylQ9MrtoX/vOjtYOMvrXgx3+WcQrPYbS3CQ/Ye60G7IgV4= 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.18.1.2/8.18.1.2) with ESMTP id 442KFYBs007296; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sk2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFsOs013902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:54 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmU009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 07/26] c++: Implement __is_unbounded_array built-in trait Date: Thu, 2 May 2024 13:12:08 -0700 Message-ID: <20240502201549.459244-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: uD_GpwI69aQPjpOjsLXdxlK14Ob65XNo X-Proofpoint-ORIG-GUID: uD_GpwI69aQPjpOjsLXdxlK14Ob65XNo X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=662 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 5a8aaa70fa6..d4cc8850486 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3862,6 +3862,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 86372ea0aba..138b180d9fb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12616,6 +12616,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; @@ -12832,6 +12835,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 4cbe6fe8cea..1e10c87754a 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 Thu May 2 20:12: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: 1930856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YGmV5mrI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlnP3CWZz1ymc for ; Fri, 3 May 2024 06:26:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3FB1384772F for ; Thu, 2 May 2024 20:25:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3FB1384772F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681559; bh=5Ivyd48jlR+TodNcG5sSksuTc7Igw4skD49TMN5KaMc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YGmV5mrINPV+Zyhavjk0+XMx8EW2uHospaUsOCmhF5o2LKlyU6PbknmIYNwBb7+i1 yOhrfrWs0wqE7bKmMy8NGK4MQZ+zpxLFJ6wwNeLmsUMmechvrgTltjNwrQWO6SPRqA c0eTx85d/cyPxmIjxvIHQ7yVQNdAgUoVTjkrpgPI= 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 499F63849AE1; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 499F63849AE1 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 499F63849AE1 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=1714680982; cv=none; b=d8Z+tRw4XfXtkNNhzR2iJ5mnOTWjOfGBIYkny+nZYixqrxKzy0ahRDTfXmltwv+yNUeavdgDWx7O/hROVIxsmcK7e33y2XQf3cek9RQ+62t+J9pUkg8uEmbR+9tM10OuUBKtn6OAECHrpxllCkZSTWNat6Mg6J9rpyQWy6Krm6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680982; c=relaxed/simple; bh=bNTbbE88pnKyb319UMOzQWFJRmaOHVr12i0zoJId8YY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NlpbcsjhgOcymxCMekQu4vgMQm+f6lwoS2ZX4iIXtD02lHZuAxBFND1BjMn+IKWj7JURiU0gIyWurKYLcK58J2F+mI0qn8tNpBKi9pu9qVj/pLEbaX8n/xWANuxLDLrkTQ/bhYwWETvNPuk/CCdNHJj61UUfHwe6QMX2mTzu5Ss= 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.18.1.2/8.18.1.2) with ESMTP id 442KBl1L028798; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf561jek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFsfh003572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:54 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmV009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 08/26] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Thu, 2 May 2024 13:12:09 -0700 Message-ID: <20240502201549.459244-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 6Eh4wwkXDTX2QW8RXrjlYxJ0TyJDAk8h X-Proofpoint-GUID: 6Eh4wwkXDTX2QW8RXrjlYxJ0TyJDAk8h X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1034 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxlogscore=549 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 ea013b4b7bc..1562757f886 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3710,11 +3710,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 Thu May 2 20:12: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: 1930833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dCAuclCt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlf95wmgz1ydT for ; Fri, 3 May 2024 06:19:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B586384AB69 for ; Thu, 2 May 2024 20:19:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B586384AB69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681182; bh=3Y3/DdOq+I1sFA4uLOeaV3i8qJn/4Bq/eU1FWI5zyRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dCAuclCtRmNE2vETQZ68EOIZFoeIPufWVN3IxZDhiaxVTpI0sFTGhjbimlO1S0Y+e nbfoK63fJya1HyFyVnrOKvz7uuDUMABZiQda6zwPKlB92ICSspO0U/Tk86UKXmx1EX NNGZgErqcRjriZoqKEqKuzayjLarq7cZQJNIXgic= 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 31DC93849AD7; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31DC93849AD7 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 31DC93849AD7 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=1714680971; cv=none; b=CjkKWN3tbhnIUlKwqpv8fGtMklrbZT/2bSv3bqjsvmaBzh0TtSgqV8QhyIVJ0F5aCRHgMUYipFwmDc6zkpZRlsg3kz5xb0PaGy2xp01MC91beBmXMw267DNzMfbysrRzqbqh0qNApAAIv9bB/a9dOPrfh5tqU+MI4p/uJx8M0GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680971; c=relaxed/simple; bh=wO61JSXKtaiaAWlc9EqT7Cbd+6gJgud6lKZEkEQ0YDo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=oI20cRSzIZgOMiw5FyCL7JkxBmEjbnQyuyI5HjWTB0zbhv3dO9HaDBiVCAcVsHEhbiG67cT+4V/Fqlaaxa+ArOvNRW+CyaO1CMD58nUEpajX1H11xirRh1uxUIYU2kBf1NnMrT3O+91RrQHFHCKrg13WvMO4KFtdcxyqghQe7uk= 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.18.1.2/8.18.1.2) with ESMTP id 442JtKh7027800; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559kng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFsEV013904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:54 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmW009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 09/26] c++: Implement __add_pointer built-in trait Date: Thu, 2 May 2024 13:12:10 -0700 Message-ID: <20240502201549.459244-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 17MuNyVCuUX1jpEWvujgYsSWUoG4n_hy X-Proofpoint-ORIG-GUID: 17MuNyVCuUX1jpEWvujgYsSWUoG4n_hy X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=734 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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. (object_type_p): New function. (referenceable_type_p): Likewise. (trait_expr_value): Use object_type_p. 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 | 36 ++++++++++++++++++++-- gcc/testsuite/g++.dg/ext/add_pointer.C | 39 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 76 insertions(+), 3 deletions(-) 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 138b180d9fb..29c1dbe2a85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12434,6 +12434,16 @@ fold_builtin_is_corresponding_member (location_t loc, int nargs, fold_convert (TREE_TYPE (arg1), arg2))); } +/* [basic.types] 8. True iff TYPE is an object type. */ + +static bool +object_type_p (const_tree type) +{ + return (TREE_CODE (type) != FUNCTION_TYPE + && !TYPE_REF_P (type) + && !VOID_TYPE_P (type)); +} + /* Actually evaluates the trait. */ static bool @@ -12576,9 +12586,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) return is_nothrow_convertible (type1, type2); case CPTK_IS_OBJECT: - return (type_code1 != FUNCTION_TYPE - && type_code1 != REFERENCE_TYPE - && type_code1 != VOID_TYPE); + return object_type_p (type1); case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12733,6 +12741,18 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) (non_reference (to), non_reference (from)))); } +/* [defns.referenceable] True iff TYPE is a referenceable type. */ + +static bool +referenceable_type_p (const_tree type) +{ + return (TYPE_REF_P (type) + || object_type_p (type) + || (FUNC_OR_METHOD_TYPE_P (type) + && (type_memfn_quals (type) == TYPE_UNQUALIFIED + && type_memfn_rqual (type) == REF_QUAL_NONE))); +} + /* Process a trait expression. */ tree @@ -12900,6 +12920,16 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + /* [meta.trans.ptr]. */ + if (VOID_TYPE_P (type1) || referenceable_type_p (type1)) + { + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + } + return 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 1e10c87754a..bd9e064ce3a 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 Thu May 2 20:12: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: 1930842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=I6sllysd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlkD0kYJz20fb for ; Fri, 3 May 2024 06:23:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 457F43849AE3 for ; Thu, 2 May 2024 20:23:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 457F43849AE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681394; bh=nDVREQmILJ+tO0YLR6oPn0o1FFect2lPy+S2ESvm+Qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I6sllysd146CWvcr1Xb/+Wrpb1LrmItgcHDumb7SSjKUYVo6CFeQpDYo8M4mkLdkP bkeHVi/y2CHX80PE6rkDh36Q86mj5XXJx177Va8TzZHOp1Hmq3TM8XgkaPGpgFJem8 X9WjNuVOmuE78LI9WmRAglHB04hU+Su28637Svps= 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 46BD13849ADB; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46BD13849ADB 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 46BD13849ADB 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=1714680976; cv=none; b=JSVCOBA5u+pmoWOHAAITRpfYZ/2CsAR0YK84SwSyO+Oi+FZxUF52qWxfwkodaA9EM4jtLEUL5XFYCgIedsGlM8Q2UV9hIJesSlFyHNRp6TT83s6S1PKfSc312AcUvwshYUSRlh+gaxGJTL+aw8idH43smGtFf1BnPZsBIAOKjdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680976; c=relaxed/simple; bh=LRkpd5KbtSwUZwAyt/JaNjAZtfqLkatdU4m2WExOhHE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=puzYrwVnGJj+FVAvDfFh5J00FcmO7lnIlz1iB2rSvYYFwMfS+ejrjALjyh+h9iRYmmXzildbyFbAmGCMcWGkX3wxMEYpRkKrSvrfzmq9sP19GTL5kDdBcQEP/LfBAvnVFmeSoDOciVNH7V9bf1E0GXmCBDcagdURm+DzvKmzmPk= 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.18.1.2/8.18.1.2) with ESMTP id 442K8Qwv003025; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvfu8949n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFtMJ013905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:55 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmX009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 10/26] libstdc++: Optimize std::add_pointer compilation performance Date: Thu, 2 May 2024 13:12:11 -0700 Message-ID: <20240502201549.459244-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: e6a4gZcSRmRMJjGZGmYQD4iquvpxGM7s X-Proofpoint-ORIG-GUID: e6a4gZcSRmRMJjGZGmYQD4iquvpxGM7s X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=680 priorityscore=1501 phishscore=0 clxscore=1034 impostorscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 1562757f886..6313fde94c2 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 Thu May 2 20:12: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: 1930869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=eOpCx3DF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlw54b4Mz20fW for ; Fri, 3 May 2024 06:31:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6741B384AB53 for ; Thu, 2 May 2024 20:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6741B384AB53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681907; bh=Feu69qs8m4g9F9F7XrGD5EHErKEFFFIxkVRa45PWjjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eOpCx3DFHomtfA7ACX9j2/ukXZbmnwDXJCxN4V3cham9O/D2dX1DpKjSmt5a8qir5 HSS6MVrxKT/pGJhaLsrid0/FFs6WXYLbYbTj3vYCKCi5RKaKVDzrWyDVSF6G5RNWxk AXWykRJ55MesuYeM6eo4h7ZJsNJzPkLgDkDCCTy8= 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 E29EC3849AEB; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E29EC3849AEB 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 E29EC3849AEB 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=1714680988; cv=none; b=rZzeeO840hD/TB6YAw0gcjiOiX8jwcImLg4eTfG8DyacbGLshe+YZbA5yhy4Fu/p0sWGnHYBi3vfY0HwiPUGR6MOM4WMVBi5Aqm+z7FgPDlAFiOawwhKoa6SQjIii4h95gRYDU4K4blpEL4fOewDgiFra4EEEmACrltTNkeG5Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680988; c=relaxed/simple; bh=fB5T8kjUeISubTLj5yP+zrOcbxvc95dieVljAK46TYk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xdfPV4ZL1DTz683H4XzilAd0VASd52TPaRCrzrc+6+bTxjGr7AZJ4lkCOS733fTfhyav07X2mjlrCDXAtKjoJWzTzQ5XfJLpBg3sEs2JTX/LRq2a/3mUEN+TaM3VeOfsc059xOykWRp/53HBJsSk9mML1k8QtveYlq2bdJQGAxw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442KFYFv004275; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sgw9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFtXZ003574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:55 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmY009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:55 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 11/26] c++: Implement __remove_extent built-in trait Date: Thu, 2 May 2024 13:12:12 -0700 Message-ID: <20240502201549.459244-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: DeZamSRdHwhWJ-3qgOh540ISvq0Ph0LL X-Proofpoint-GUID: DeZamSRdHwhWJ-3qgOh540ISvq0Ph0LL X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxlogscore=522 lowpriorityscore=0 mlxscore=0 clxscore=1034 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 29c1dbe2a85..383259fca56 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12938,6 +12938,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_EXTENT: + if (TREE_CODE (type1) == ARRAY_TYPE) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_POINTER: if (TYPE_PTR_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bd9e064ce3a..d58e4186704 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 Thu May 2 20:12: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: 1930864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=iaV6aA5O; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlsF2khTz1ymc for ; Fri, 3 May 2024 06:29:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 894813849AF6 for ; Thu, 2 May 2024 20:29:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 894813849AF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681759; bh=EVE1TxJv5qUQK0f5z7DA2iDA8NVOReOeAKlXwfuGtkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iaV6aA5O16UyrS/kpjtluZvA0hbU0HI+iAXtgTOAX+MDGaEwmBbNinbvDNCjrgk1V 151eXkRb0VznEVC+LmEBGFccDWTXi9GXc3qXFFhiDIGHx7Y8HnMMaHZ11uHLBfZxSA v3Be35BtlBmXB5vgG9FH78nuA9+n+CHWlHZaojvE= 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 A88C5384AB6F; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A88C5384AB6F 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 A88C5384AB6F 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=1714680983; cv=none; b=eiaef/gesDbXWwzGza2Xsa5WVwM/ueyloZwMTGo/7wqdOok74GbooM+tW99fwIB3ftX0NruEiem1gDPUgLEXFXrrhbAIOdegAmYymesF8wQUUb7PrweUaZTwM2BK2e++KmKJUUWaV+H9AtgR/4lNLg68Xyl03kT+qlyKTdwjLic= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680983; c=relaxed/simple; bh=3xttDkFJBnihllbCWACdhTR9ZoUdZW3WeCijSqI0NLA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=X/BixCZkXlm756Xk9BFy1HckQjTbPvAWc7yFnfqBWOV4uXFST0idXtzqm54PGkX2R1XUode9ZtZLrjaU/wMuoo3vc2c4Rcr0++CoFkWwzsfgtUCQqwrpl749M0ubOhIHPzgqBmu/vdWrjDS2ggOQ8U51+KTwZ6eOTNa/Zz6nhLw= 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.18.1.2/8.18.1.2) with ESMTP id 442KAgJs028743; Thu, 2 May 2024 20:16:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sk2v-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:03 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFtJN013906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:55 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmZ009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:55 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 12/26] libstdc++: Optimize std::remove_extent compilation performance Date: Thu, 2 May 2024 13:12:13 -0700 Message-ID: <20240502201549.459244-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: F9O73H4Hi0xRBBVuhInB-spUVe09RIdK X-Proofpoint-ORIG-GUID: F9O73H4Hi0xRBBVuhInB-spUVe09RIdK X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 adultscore=0 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=698 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 6313fde94c2..58281c2e38c 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 Thu May 2 20:12: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: 1930849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ybsxcDNI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlmB1N4sz20fb for ; Fri, 3 May 2024 06:24:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5285E3849AF0 for ; Thu, 2 May 2024 20:24:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5285E3849AF0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681496; bh=UuSEmanTio6QXrbhYhIW1w1yb80tXY0r6wcDzX7QonU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ybsxcDNIoXwxfVVzPjXmyhnPJM4D+9uctx3SNwmdqaIesEiyaRLQidQZSqVLhH3GD ZcpZln3SdFSA+m3SnJyzpUi+Pr9AYIJy1CBMDhYqCXiyTprt5DiCXlLrJLD08sUN8x qHwDBZ2eSqaMnYHIjOOo6PlYahve+WrVmp1HGh5s= 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 54CCB3849AE5; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54CCB3849AE5 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 54CCB3849AE5 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=1714680977; cv=none; b=iD5iAa5BI53/1a0NFq3r+W/dOsxhcpcpabjIeS2Yu/BlYYL1fE6CUV35qXhKpUWUCsSuxB7ZnglZJyvwiuzw+jBxAqG7XGHLvh9z/4uI+UXIuOahBPPScqxnDPj7Y1u4uaAH516/DrSxTd6lijCpnS6+N1bqJhUuakwdDEv2f90= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680977; c=relaxed/simple; bh=mwCtNcsF8tNW16FgGlrvBl9fYwxydGZ4jnVDJTLSFIc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tizvrBFGBDl/HPfI4W+KIiBSo0LwelFm+N8cBKqgbbNnb0WxOM58ynbw19i6fvsdRq6XjuOD5BSaMp36vqE4eGxuGIuywOI8IAFFy4mN+KleAJK2FzhQt/LlCb7ey2uSToaL53K70GuG9PEEXViaCimzcbb4FXAUteDODp64fRc= 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.18.1.2/8.18.1.2) with ESMTP id 442KBBst010710; Thu, 2 May 2024 20:16:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf561jv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFt7d013907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:55 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqma009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:55 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 13/26] c++: Implement __remove_all_extents built-in trait Date: Thu, 2 May 2024 13:12:14 -0700 Message-ID: <20240502201549.459244-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: TLXbfTWwx6kR0KklYGV8zV7nZm0gUzgr X-Proofpoint-ORIG-GUID: TLXbfTWwx6kR0KklYGV8zV7nZm0gUzgr X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 clxscore=1034 malwarescore=0 mlxlogscore=503 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 383259fca56..07779a79d24 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12930,6 +12930,9 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, } return 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 d58e4186704..f0b165e2891 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 Thu May 2 20:12: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: 1930859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Bp9qBJhI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlnw6TSVz1ymc for ; Fri, 3 May 2024 06:26:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5D833849AC9 for ; Thu, 2 May 2024 20:26:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5D833849AC9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681586; bh=sTp1UgaUHAXR4ycDyzqPqbVQUPxX0rR2GdOnmMf7BO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Bp9qBJhIn8wfDbtyjW+IZcH4uQV14KXjZ2uWBAOiR7qVnukj0BqEf2eLpNlj7oGlz cY0akPRWUmaNxnSJjkby6AP+w9vtsxO41zMJIicM+81sq9NE1IlGUkNVhk5XMYS0Ze mKM93ucWZawvdIWCyW6rjlE1aaO7hzj0c3DHFRY0= 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 438BE3849ADA; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 438BE3849ADA 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 438BE3849ADA 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=1714680980; cv=none; b=ZHcQ1r3b1IzxAA7/6Pt40rc103bH4FsnO/DYwdR+mgHh7EgArYqCn30jECJNLZ/dXmcrrXyrwWiR9NViFzcJnlGN7gorWoGUFysq+gU4X87nE/gcRxaVxYPP3sTI315gi9QN322EiS6NZqo1Oz1iaYLCqneBK8BHxO/gtsa3fGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680980; c=relaxed/simple; bh=1H+M8c3JyIdWqAqHvrkGrCFxpShFyQQTbdjBZF0bDxg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BS/YGvVmpc427J01TJ5LXsAAkvRvorF5sxYgOnzUNvD75ZcsN7Va789Bjd0nTXIoW1fjqFwuEU2ehDUis5j8KyRAe/joMuNnYTBdAWh288vWgG8RHZnkB457ZYmFdgRVwSfNb3KfH5RixLMCOIMa5fat73mW9WnOC+es3wbPtNA= 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.18.1.2/8.18.1.2) with ESMTP id 442KF0Sb019588; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf53hnv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:01 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFtd7003575 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:56 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmb009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:55 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 14/26] libstdc++: Optimize std::remove_all_extents compilation performance Date: Thu, 2 May 2024 13:12:15 -0700 Message-ID: <20240502201549.459244-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: zbDIOGmCWQkkD15tyCoCnnnJHniGWEK1 X-Proofpoint-ORIG-GUID: zbDIOGmCWQkkD15tyCoCnnnJHniGWEK1 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxlogscore=854 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 58281c2e38c..5b74e44d0a6 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 Thu May 2 20:12: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: 1930829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sWj+pFEj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlb92HHjz23hd for ; Fri, 3 May 2024 06:17:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 699123846405 for ; Thu, 2 May 2024 20:17:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 699123846405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681027; bh=QxE32sk3z5LYqLroOKJ8J8+QzpB6ekfPrlcaTytR+w8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=sWj+pFEjSmRGhwxZeqtIKxTgnP4m41OSbZOSmMYXZZPOVQjtILadoDaunKKbntEWr nmWB1cjq4hHC0WEzmLc6U9ga10RgA3e5BcvDlBc7ByOiCzqcTkWCZLiU7Thlj3IZyS 9qp30uDi8/MBopwHKYA7pv61/CbdtZQygSBs1Hr4= 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 0D75D3849ACC; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D75D3849ACC 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 0D75D3849ACC 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=1714680965; cv=none; b=j1DOqakdgetCbUeKUcmz+66BBZdqpJXJ9yPHGjhDAr9jRFtUn+vyX4jCL7UqibO/EgsrxCmkgtffO/RC5tuYSrGQbt/LTGR1PkJPUWLLf6c/+YhacKyNwt+RLkg9bXxk0lB6Mz/+zJp9WsF04NnkosPg8tFXivSXJKDAdhFa2AY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680965; c=relaxed/simple; bh=wtWb84We47/RZTmdzDznmnV910dqKGBfFs3T8aq1ByE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Kpos6MXAsEal0sAuFiiB0nTfaDWC0bYKRxWy1gsKIZe4WFuQpy/uMKy/l9OKpIaFojT3J2VwsTIkEWIhKupPyDBrFf1IA3EidDppFPGMh9MLjs2Orxk7Q8uhQbdoAWrqRnuGuabPwAJWv9sKu9lCnj9L9bZCsoBUEVGjczLv6cA= 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.18.1.2/8.18.1.2) with ESMTP id 442KCOZN011251; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559knc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFuWL003576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:56 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmc009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:55 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 15/26] c++: Implement __add_lvalue_reference built-in trait Date: Thu, 2 May 2024 13:12:16 -0700 Message-ID: <20240502201549.459244-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ENvFGn0avBV2RtwF349ET0X6jRFPhgi9 X-Proofpoint-ORIG-GUID: ENvFGn0avBV2RtwF349ET0X6jRFPhgi9 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=949 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 6 ++++++ .../g++.dg/ext/add_lvalue_reference.C | 21 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 31 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 07779a79d24..9f2220a1a91 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12920,6 +12920,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_LVALUE_REFERENCE: + /* [meta.trans.ref]. */ + if (referenceable_type_p (type1)) + return cp_build_reference_type (type1, /*rval=*/false); + return type1; + case CPTK_ADD_POINTER: /* [meta.trans.ptr]. */ if (VOID_TYPE_P (type1) || referenceable_type_p (type1)) 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 f0b165e2891..a8b2f0fcfd2 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 Thu May 2 20:12: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: 1930841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Ts0OyfP9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlk20Jpmz20fb for ; Fri, 3 May 2024 06:23:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 265BE3849AD2 for ; Thu, 2 May 2024 20:23:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 265BE3849AD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681384; bh=rAt/pRLroqdiOP2qVKQo8n6pZjpWXMUO8nKscvIklxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ts0OyfP9pNcumONUjCLHM1S5p67H+8KGvOeeoGBSyC97px2Py1gsl436r8EQkJXnd MapCPYg3kvuUmt0YDV+pqFInw+SVkN4dbtjeAiu8VeDBXYmomHb0yVJDQ8GW20pC1x XWUneeC9qNb7sGXV4fWzrp84aJdF7b1MNjSYq4Lg= 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 4C7283849AE2; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C7283849AE2 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 4C7283849AE2 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=1714680976; cv=none; b=FalsGADbNo2hjKLiYxUViFWQaKXv+BuPUUR+2YnmX1e9zqv3q7JejJwGt5Bnh2t/439ALgPJYzFJ42BQqRgadSnnFHAWXZDXunnUO/kQAH3Sc3jCYUldmi3UhPt7fBhFiO4rTwscQIo7tyqi23NbVFJrKokZakHLxgUcPSgdacY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680976; c=relaxed/simple; bh=oQHNk0AQfz+YpIeP66oD4r2eCB+9tB9BT+gN/yc2jvE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ItD3f90lNZyU9bUmV1UQL4p7At+56y0DsXJBkXYy/J5XbpKgClEC1ST3NJDFisnxiPIBWC0XuquxuBj2aCjG7K2QKgpEAmest9gZIf6VfEzEFCevArEYOL0hLzqUyOryD2Mn1Fepo3US1EOILqEXgoIWzrOmEcF9n6eWU4L03kQ= 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.18.1.2/8.18.1.2) with ESMTP id 442KET7i015298; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559knh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFuYD013909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:56 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmd009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 16/26] libstdc++: Optimize std::add_lvalue_reference compilation performance Date: Thu, 2 May 2024 13:12:17 -0700 Message-ID: <20240502201549.459244-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: YQS_NEVPP8gZm0_-w94gsj1Yoy6HFFn2 X-Proofpoint-ORIG-GUID: YQS_NEVPP8gZm0_-w94gsj1Yoy6HFFn2 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=748 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 5b74e44d0a6..effa3fbcb75 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 Thu May 2 20:12: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: 1930836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PkBAoU2n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlfp60jRz20fb for ; Fri, 3 May 2024 06:20:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00CFF3849AF6 for ; Thu, 2 May 2024 20:20:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00CFF3849AF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681217; bh=l2VkGzz9/6PoB8mFGzHMl6C8HzLbvNYh3rry7gryQ4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PkBAoU2nQmAWAcxyc7HNoS5ghDeXz2VMT4tRND5OuK9vNvVVGTHgbDl0US5Xknlyn PtJnIhkKeTpvVWpOsmiAOlSg1tnfceJjTcy7YlHe5qmY11W0u8M13qFV0MXES3xs/O r6f5oDm1qy/Oxo7+CypICAd6WCb8Z9/2oZ/KvHj4= 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 1678A3849AD2; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1678A3849AD2 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 1678A3849AD2 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=1714680965; cv=none; b=gUSY3XC6BRQRw/wMN/njY5+CpE7TQq/rN7OUYu0Mfsh0U8xfDy26Tq7bS4/aRpzJ2E/FwP4p0hxSSZlbz0PGo8e7xXULzF2HITvK/JB3aUh6bNY7X2JlrJu+r/hxQdr0zOi8N1pih98ncq8Vl09GY/7CeDvtwJ6jYBujCAWJ12E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680965; c=relaxed/simple; bh=9zp+ANoRc0lpQmNFFqYZKD0qnS/qJw+N2HCdgbVZHv0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TC0nm9ftdIp19rIFd2Kf5i7M0lqetF+GD5+YPGQBQJIs5Yqc63H4LlTp832pU1mOxl0A+E46Wyw313hFYYPzgQCHz+0Cio7glXEO4bAbhKhskbD9QAZ7DHLVtkG/aqRV53cQIQXPKPLjm8S8wG5VVQxUbflPaZ252f0rsnqirmM= 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.18.1.2/8.18.1.2) with ESMTP id 442KCPi9013121; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf561jv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFu9S003577 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:56 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqme009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 17/26] c++: Implement __add_rvalue_reference built-in trait Date: Thu, 2 May 2024 13:12:18 -0700 Message-ID: <20240502201549.459244-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pM-3tI5gGLV7JEymxipFMd3K1DM3PwQV X-Proofpoint-ORIG-GUID: pM-3tI5gGLV7JEymxipFMd3K1DM3PwQV X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 priorityscore=1501 clxscore=1034 malwarescore=0 mlxlogscore=634 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 6 ++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 30 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 9f2220a1a91..fd6d9fc1dc5 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12936,6 +12936,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, } return type1; + case CPTK_ADD_RVALUE_REFERENCE: + /* [meta.trans.ref]. */ + if (referenceable_type_p (type1)) + return cp_build_reference_type (type1, /*rval=*/true); + return type1; + 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 a8b2f0fcfd2..266cb35a368 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 Thu May 2 20:12: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: 1930837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=c1sQ4PGQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlgt6Rtfz20fb for ; Fri, 3 May 2024 06:21:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE676385E836 for ; Thu, 2 May 2024 20:21:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE676385E836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681273; bh=r/Hp5TedsDq/TDsuy1NYrFuBVTF2V4qiV2ZJwE0IX34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=c1sQ4PGQqaF6BCdm45VaFwOb3MIuSmTm9L0B7ktvp+SiCijjU6uQUHKpwciy1+uau fzpc8P/FJoI6gZNODaGnlMTfbwyhM7USmf2CWH3Y9bZ0Id7eo4rc8a8dpm27y+mMcw M7lgcFgHk0l8jZVeLFIXU1XL5Jw+gMgVT7j/AgTY= 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 3D5C23849AD8; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D5C23849AD8 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 3D5C23849AD8 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=1714680971; cv=none; b=h3nw6tTS8IXPovjhyQzCABRlbu2Dg4VinqmzGQk0oLgZAU3Ii2xNufSq5VhW3kB2/rshEPE00TFOocCGirAiMj33UGUl2wv0gm9x+O82vDMkoUap88RjnlJBfdnNu8t7UP47Yh/Xr5GRm8/7pKYtaC45QQjoRXxvCGnmyjiCs1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680971; c=relaxed/simple; bh=mrowVSRE7Oj/pUVS9z6GbMCA7SDT03wtrA+wovooslQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WwNI24QNyw0biKDCcrMwRHOGNchnEozxxRAco4hU+cvnt+hM887zpkEVPW1Si5TI5eVMN3qxZJHPFyGSu+xyPcSaCujmuKo93NPJlAwc2JCI6wI6P9I83IAkNJ9rW2zg7vaY5iGomw6GtC9uyLymSfukvwQAT4iIMhyhpwEHras= 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.18.1.2/8.18.1.2) with ESMTP id 442KAYl9008494; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvfu8949j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFuL6003578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmf009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 18/26] libstdc++: Optimize std::add_rvalue_reference compilation performance Date: Thu, 2 May 2024 13:12:19 -0700 Message-ID: <20240502201549.459244-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ykefwPc2YsZRR_WdbJKEbLoQZDgaXUao X-Proofpoint-ORIG-GUID: ykefwPc2YsZRR_WdbJKEbLoQZDgaXUao X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=778 priorityscore=1501 phishscore=0 clxscore=1034 impostorscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 effa3fbcb75..824cad90a25 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 Thu May 2 20:12: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: 1930838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BIRTjdae; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlh41wB6z20fb for ; Fri, 3 May 2024 06:21:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64F9D3849AF1 for ; Thu, 2 May 2024 20:21:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64F9D3849AF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681282; bh=RFir0uPNg/xxoEDc/P8Bg7ZlZg70TC76vvXxGRMNiO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BIRTjdaefNSwLvDTVTA8whqJB80iQpNHgVrNLxXaVqzBnh3MB16C7JuuP53x5DmmO anTUTeHzTMdHO3V9ERn/M+wV1vXE8Dhyf/ntYkTKlq4WHzLRU1qGMWSspwnYhu9nli +X7Q/g30mj1vhIoRRIHjTbjEjvQM57gi+YPjvp4o= 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 23690385840F; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23690385840F 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 23690385840F 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=1714680972; cv=none; b=Z4n24UbrlM3crcnRUBwn7DpAwltbJ/Vs/hlxkP/OgwheiBjEkobfEjQEbz/XcI/FgsDh99AQTiOHml0UZfwM/4/iakfyCUw8tKk3BEPBR+3qtFKgwv+8XYeQqTJ0idoeTVs6BoZpQPn9AhLu86tlbbP6hxu2TWOre1TAAMZDsig= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680972; c=relaxed/simple; bh=To7QuIY3jaJWPLlXTpEr2K7UdIEbYEKyx28CSkOdDOs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AI/C9ByZTpc1PBUSXJO/jxJOCSETWRwxFAyb3z1+AmcYS0chBf3agnnPK0dhAfAonsvuwxTvMCcmSf/Oz4VicJZwgRslJDHBQMqSVAZfa/dW+dwaQMCWIfL2qaYDtU/AaMiNce8Ct1azZpqUcmv4edtjKNkLLlMw87YTK9C28ck= 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.18.1.2/8.18.1.2) with ESMTP id 442KESsr026931; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf56hp58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFu4H013912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmg009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 19/26] c++: Implement __decay built-in trait Date: Thu, 2 May 2024 13:12:20 -0700 Message-ID: <20240502201549.459244-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Ggl7ZsHpUI4TIMxFEeHrmogjep01oqNN X-Proofpoint-GUID: Ggl7ZsHpUI4TIMxFEeHrmogjep01oqNN X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=572 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 clxscore=1034 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 22 ++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 38 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 fd6d9fc1dc5..c498191a3c8 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12942,6 +12942,18 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, return cp_build_reference_type (type1, /*rval=*/true); return type1; + 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..8adedfeefe6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/decay.C @@ -0,0 +1,22 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +// 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)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 266cb35a368..d2e6a5b4dcb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -32,6 +32,9 @@ #if !__has_builtin (__builtin_source_location) # error "__has_builtin (__builtin_source_location) failed" #endif +#if !__has_builtin (__decay) +# error "__has_builtin (__decay) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif From patchwork Thu May 2 20:12: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: 1930835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TdS3waWe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlfW4vnKz1ydT for ; Fri, 3 May 2024 06:20:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF321384640C for ; Thu, 2 May 2024 20:20:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF321384640C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681201; bh=0PQVeCwPxxjtQhoQRpz8VxF8kr05dz69v5rX6Fqy+bQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TdS3waWeRclq2DvWpBJ2SrrTgtcrqmUsX6B4Sfmw0iP6KZ/MKQ5yDgW1HLayMuyw4 8U1oDETEtGum5T6TZv+ah1lI/tUGdLzGVBVZyY2hiMELt+ek25l+j/nacQSGEAPMcP q7i5VB1dglIhY5zRni8ZgWTZ47/kgKHDuccXAoTE= 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 1C75E3849AD6; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C75E3849AD6 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 1C75E3849AD6 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=1714680970; cv=none; b=hJ+GCb/lqImPe/cyA6GLcune1Nvyh6L/HMrEWfP0SUbrkuyy+DX4uTGBX9auO86sWpJgLJPhZs33yrOI4WFxgWI6dPUfPZZNrEnQq5cBCcejpPSc+pZdiQnMLJ67UEpGicOIp4xUveQscho+LA7bHgF5x+r3Zfq2Acezytydof8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680970; c=relaxed/simple; bh=rVMrKoQxXgzL9ULnTlFSgjLsk41ADrAyC1AF811cTlM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UOipOCeC9kXi0N+4LzR79jTfi4ZF1Ps9aW2dBD1FfDxx+l6aT7fWpxKoV1akXvUSuJrFIn0L6A7BF1EoSkMO8NFY5XKlJn7NvzjJDDj2wGsRmpKo7r+Ouuzf1RbU46W+l1ZBcEeB2VbfOs1F0SVMXZAsd/kAag1vTR5lBzWGF08= 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.18.1.2/8.18.1.2) with ESMTP id 442KDksG030492; Thu, 2 May 2024 20:16:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf53hkds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFvCg013913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmh009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 20/26] libstdc++: Optimize std::decay compilation performance Date: Thu, 2 May 2024 13:12:21 -0700 Message-ID: <20240502201549.459244-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iiA7gjaygQm5tZ0MPIqzL9pDDgAnjXWp X-Proofpoint-GUID: iiA7gjaygQm5tZ0MPIqzL9pDDgAnjXWp X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxlogscore=795 clxscore=1034 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 824cad90a25..4cc587d4e08 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 Thu May 2 20:12: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: 1930871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bAkjrFys; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlxw4kMxz20fW for ; Fri, 3 May 2024 06:33:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C52713849ACE for ; Thu, 2 May 2024 20:33:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C52713849ACE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714682002; bh=lDkCqG/b/29OnZ2ZMxcddTGqNaU90YOUXiQXNa1MADk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bAkjrFys7IhL2JQ6LvDPpBvppeNsuen0lDSM7PJeqBR0jY9E4yXCzLq2ol2HnE9va 5CVRCqXtOU8C/Dd2bvPP+PHCTjB+HlZu3ex668HNFT2ITaFE5mIDAgf2FTlcs/CJL1 LBu92KMer48+8Im7lEbUMqam/uN5bHNJEyfiYdNo= 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 AF8173849AD1; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF8173849AD1 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 AF8173849AD1 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=1714680988; cv=none; b=oqKevyyobG0hgTCbGNQrINRQTfvkKLboydbuV0FNmbxwh+Rv0xU2UCSmsWcuNflwd+JFfJqgduvYtXl/4oIkvGQgG3KsG5iDmn/JHc+LVe3hgsnzKT7q1bvoTDxzRva1lZmLmCSw7cz1xxTVDsAlmO5Rd0TQ/s2o7VcETjkCr4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680988; c=relaxed/simple; bh=OYT2sOooTANFTxwa9PzqiKyktJD193pmuX80pDW9euU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=axFjhusFhTZl4nwI6119Z8/Ij90LJ1RDHZXNGPnaasXxdyTG1WiroHCcE2jXiJ0C8gXmx1oOU4is+RbGivtLeO96aN7X8DPCnNoPN5iNC0V4a/WZG24tUigjQJd0k2pxooARgP17x3ovSklmDsz8QCkK95iE900Ibqa0/m5YzCM= 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.18.1.2/8.18.1.2) with ESMTP id 442KCOZO011251; Thu, 2 May 2024 20:16:03 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559knc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:03 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFvXg003579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmi009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:56 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 21/26] c++: Implement __array_rank built-in trait Date: Thu, 2 May 2024 13:12:22 -0700 Message-ID: <20240502201549.459244-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vRhofC6ZdYno_S2l0Dlra_0byBsBQ2Kz X-Proofpoint-ORIG-GUID: vRhofC6ZdYno_S2l0Dlra_0byBsBQ2Kz X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=954 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements built-in trait for std::rank. gcc/cp/ChangeLog: * cp-trait.def: Define __array_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 __array_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 | 24 +++++++++++++++++++++--- gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/rank.C | 24 ++++++++++++++++++++++++ 5 files changed, 52 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 d4cc8850486..c28d7bf428e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3871,6 +3871,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..b1c875a6e7d 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, "__array_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 c498191a3c8..a293e0fc23e 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12642,6 +12642,10 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_DEDUCIBLE: return type_targs_deducible_from (type1, type2); + /* __array_rank is handled in finish_trait_expr. */ + case CPTK_RANK: + gcc_unreachable (); + #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" @@ -12765,7 +12769,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; @@ -12858,6 +12865,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: @@ -12889,8 +12897,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 __array_rank = 0; + for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1)) + ++__array_rank; + val = build_int_cst (size_type_node, __array_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 d2e6a5b4dcb..bcaa56a7bc5 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 (__array_rank) +# error "__has_builtin (__array_rank) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) 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..0ab2f235036 --- /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(__array_rank(int) == 0); +SA(__array_rank(int[2]) == 1); +SA(__array_rank(int[][4]) == 2); +SA(__array_rank(int[2][2][4][4][6][6]) == 6); +SA(__array_rank(ClassType) == 0); +SA(__array_rank(ClassType[2]) == 1); +SA(__array_rank(ClassType[][4]) == 2); +SA(__array_rank(ClassType[2][2][4][4][6][6]) == 6); + +template void f(T) = delete; +void f(size_t); + +template +void g() { f(__array_rank(T)); } + +template void g(); From patchwork Thu May 2 20:12: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: 1930868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dE7ttfkG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlv84PLNz20fW for ; Fri, 3 May 2024 06:31:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFDC53849ADA for ; Thu, 2 May 2024 20:30:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFDC53849ADA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681858; bh=Ei2Bf86agIezYNZUeEIeBPNaJsZtLtQ4A7rd33d72L0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dE7ttfkGprB0RTpoaLQtn9o8kJxhYy2HRqS5eHXtp8pNQLN0PAU0fdvgeuNZQHEGJ vsC461mgklaYUq3xEpetAvcbRvJAMA7InCV+crDMFiIIXk7hpn6Af8eJ6JTGPUYZ07 54dR0zmAgTU/JW5LEnRC6xqVQx7JWTXmzIAaLv1k= 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 ACD743849AC8; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACD743849AC8 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 ACD743849AC8 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=1714680987; cv=none; b=FMxl97dL6oLuGPDjbxNBc6qlXtzkRL+qEy6UmwQD311qJabzMpEFFXxJNiBD1uRPt1BObXAxJP62NFlfxUrTZv8tkaItPW7bSUjAwvcWWpQkGVLuw2Dd+BgD4XeVkzkq0NU6KX/eK/eDPSxNMw6m5Sbu9S4R+vkxKFNcMnrL2DU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680987; c=relaxed/simple; bh=RN163wpV98X+X1mtcsm1+6Kt+JydVcxoRpo6vOr/Ae8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bmMU+OF3nAfTypHccUGFmtRVKAQo86T9oxCbZDdVjbMeQqO4ChaY8t5tY7XiD6kIRwF9C3FMchvU0sVVKddsYH0NZOHXXX1GtiN8622ng2OSzjxuSaQHJJeN/+vrHV1CQYjdD+iKdhDNSRCyLop5jyWSTdJMkoj+ZBOMbA6n3lE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442K8lJX021473; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sgw8-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFv8c003580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmj009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:57 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 22/26] libstdc++: Optimize std::rank compilation performance Date: Thu, 2 May 2024 13:12:23 -0700 Message-ID: <20240502201549.459244-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: HuRt1rx4WkYgUcMAQ3Z4AvntMoGqWYWq X-Proofpoint-GUID: HuRt1rx4WkYgUcMAQ3Z4AvntMoGqWYWq X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxlogscore=773 lowpriorityscore=0 mlxscore=0 clxscore=1034 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch optimizes the compilation performance of std::rank by dispatching to the new __array_rank built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __array_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 4cc587d4e08..e9313205550 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(__array_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 @@ -3583,12 +3589,17 @@ template template inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank) +template + inline constexpr size_t rank_v = __array_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 Thu May 2 20:12: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: 1930870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Yw/SRP0K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlwx4Fj8z20fW for ; Fri, 3 May 2024 06:32:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3F94384AB53 for ; Thu, 2 May 2024 20:32:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3F94384AB53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681951; bh=hgT4W0Q2zO9zxaq1b32SSToFqLw95oUHBNKEHb3VLa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Yw/SRP0K9eHV8o2u0+km5Gu7Co11sxVgD5NCzY31MRdxYpvaybkaDtYY9cTn59OdV Ycqrtfhbna2yQkCB/KF91s45Vp4GTOcG3c7Su22IWwRSvbn2xrh2L2XqK9GQrLwGkY 1a4DnodZFJfqboaE+dO9FvhTrBAnscl1H+wYZ750= 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 51359385E83E; Thu, 2 May 2024 20:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51359385E83E 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 51359385E83E 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=1714680992; cv=none; b=ce40TXPGsuaqYgPhYLKPJcO/CrcIkowu2Dk0sjVzXiQ3mzSfY/QIFTf/bVlCsgPvP8xUe81LlWYZ+Z1RSxcBMkrvUwshmPXX3vChZEbVKYoDfZcQ9T4aX4iGBCbHOhhTZGkZgKxoiNPGeLifejXm+lJlEfyNqNsSb8GeNf/zFaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680992; c=relaxed/simple; bh=Q14vAr/HWZqqjWJF9EO6b4j2A+CMCdTdIWw/oWXuZyg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AP4zhsR9j2ovf3mUhnFzuhPtVEHdGm37qfe+ads8YTylx1XXgkfCK9vLzokXw8zR2ZD7uHMhWRlJz8ShH4vnKHVuCMvLLtIHdXDqIYseRqDSRpY519Vc2DUW3o1V0X4aK2jI9U6PHEvad1k1rRfRRnPDt4uSDSmPPedIO5PW2YU= 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.18.1.2/8.18.1.2) with ESMTP id 442JtKh8027800; Thu, 2 May 2024 20:16:04 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf559kng-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:03 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFvIr013914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:57 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmk009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:57 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 23/26] c++: Implement __is_invocable built-in trait Date: Thu, 2 May 2024 13:12:24 -0700 Message-ID: <20240502201549.459244-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wOD5-iAGWiCn5I0dpPlk02ZdVFVKhDzc X-Proofpoint-ORIG-GUID: wOD5-iAGWiCn5I0dpPlk02ZdVFVKhDzc X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 134 +++++++++ gcc/cp/semantics.cc | 5 + 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, 723 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 c28d7bf428e..6d14ef7dcc7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3792,6 +3792,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 b1c875a6e7d..4e420d5390a 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 1938ada0268..83dc20e1130 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7338,6 +7338,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 08a3d34fb01..faf932258e6 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1928,6 +1928,140 @@ 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 (error_operand_p (fn_type) || error_operand_p (arg_types)) + 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) + { + if (complain & tf_error) + error ("pointer to data member type %qT can only be invoked with " + "one argument", fn_type); + return error_mark_node; + } + + if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0) + { + if (complain & tf_error) + error ("pointer to member function type %qT must be invoked with " + "at least one argument", fn_type); + 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 (!(CLASS_TYPE_P (datum_type) + || ((TYPE_REF_P (datum_type) || POINTER_TYPE_P (datum_type)) + && CLASS_TYPE_P (TREE_TYPE (datum_type))))) + { + if (complain & tf_error) + error ("first argument type %qT of a pointer to member must be" + "a class type or a reference/pointer to a class type", + 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()). */ + datum_type = TREE_VEC_ELT (TYPE_TI_ARGS (datum_type), 0); + is_refwrap = true; + } + } + } + + tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type); + const bool ptrmem_is_base_of_datum = + (NON_UNION_CLASS_TYPE_P (ptrmem_class_type) + && NON_UNION_CLASS_TYPE_P (datum_type) + && (same_type_ignoring_top_level_qualifiers_p (ptrmem_class_type, + datum_type) + || DERIVED_FROM_P (ptrmem_class_type, datum_type))); + + tree datum_expr = build_trait_object (datum_type); + if (!ptrmem_is_base_of_datum && !is_refwrap && !TYPE_REF_P (datum_type)) + /* 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); + /* 1.1, 1.2, 1.4, & 1.5: Otherwise. */ + + 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)) + 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 a293e0fc23e..55c2ec4b5b1 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12561,6 +12561,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); @@ -12719,6 +12722,7 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: to = type1; @@ -12821,6 +12825,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONSTRUCTIBLE: case CPTK_IS_CONVERTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcaa56a7bc5..d1c66267855 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -107,6 +107,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 Thu May 2 20:12: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: 1930861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vM15kj/Y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlq72qGQz1ymc for ; Fri, 3 May 2024 06:27:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3B3A3849AE7 for ; Thu, 2 May 2024 20:27:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3B3A3849AE7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681649; bh=Ii2Qu7Ij3cLjuuEGEpBCYONNW5Pqq7hHUhk2QwfxoCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vM15kj/YaoOkI9LV50PFtf64KaTFQ+/fDB8Ebp6gKNooUR3RVx5BI/66eSMYijTxm +kGkGykRaIyhxIJke20oLTRPT/J5X1n1ovCTE9cxKRPxAjkk2Xb8UDBc/UfYMrS6dx VI04TGZ20cF2XXpfdlou574g2LdxsYrHGOTlrng8= 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 7F4AB385E836; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F4AB385E836 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 7F4AB385E836 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=1714680982; cv=none; b=sn+iIcEq+o5OB/Vvkp18KwM1rc7JMgrMtZCVZ4FkJOXOmEPDTQ9Q0hF+zB4I1WOuA94TCFWcMFp55uy+O336vNVR8jaw5wvVlMb5RSwKik8UVKI3ZN4cbtUcb3kAcQZpzTSNODr0TKhjJ+7StbZpmZaxQiXLLm2ugGHnZzcUqYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680982; c=relaxed/simple; bh=wdEKFrsZbnwKwlUqvkUbDQEMZwMLsY9wjRphgQPbidU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=q0LrcsgkwubbLvyU9vMafP3U49Pz1Ksyu50K67mbtcGQol4Vyk50H6pePaUTkZgVHzljrJvG57YNRo8mje5X4Vb5xPAKsRAqs5Ki9Ln37XfB2k+vuw7abIuK3EV/bLZY4OH/Gkb/HvS9Cf80bu4HJX503+OiE+LeatQFC2rW0ro= 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.18.1.2/8.18.1.2) with ESMTP id 442KF0Sc019588; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf53hnv6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:02 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFwF8003584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:58 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqml009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:57 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 24/26] libstdc++: Optimize std::is_invocable compilation performance Date: Thu, 2 May 2024 13:12:25 -0700 Message-ID: <20240502201549.459244-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hqYkjXfuCsit_c5N0xUa6sNN59oNYZ4y X-Proofpoint-ORIG-GUID: hqYkjXfuCsit_c5N0xUa6sNN59oNYZ4y X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxlogscore=997 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 4 ++++ .../testsuite/20_util/is_invocable/incomplete_args_neg.cc | 1 + libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e9313205550..502032787bd 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3239,7 +3239,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// std::is_invocable template struct is_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable) + : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)> +#else : __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 From patchwork Thu May 2 20:12: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: 1930860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tqE9Mc/Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVlpF5nT5z1ymc for ; Fri, 3 May 2024 06:26:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C858A384641E for ; Thu, 2 May 2024 20:26:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C858A384641E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681603; bh=qB2k3+QkW/3itpXs6AtVAMZSjOpPA/WwdSiCX84QynY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tqE9Mc/ZZZoeUSVO1I7bdYOg6q3PX6podH+R2qCvHabTEqP7ghjxiFBFp/T0QWFCX FMTfyUQATDWN5KuROq9y9huCsaUPmpee9c/aprVpf6wc5CT5KnPfcpdDWwlHjXuEL/ 0HzunV97fJkmJqJhrzye1m39qYGj2fLP4ix8UU7s= 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 37D8F384AB69; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37D8F384AB69 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 37D8F384AB69 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=1714680977; cv=none; b=TsDKyLuv5IezClTgtkrL3b3ezchpWbVtpxC8BXnS3VFPZ0O6+69sMmNw/MQ3ZjTtXspSsW/tAlNW9Ce+YOEjxT4IDNvmS4rC31INJ9yzsOBCoDerp0hGN6+0lwmdSpHnw3dNcMQbCEekIkOW/YkZRwubTISW8M7x38vmQzU7NoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680977; c=relaxed/simple; bh=o23x8bHpmtqRIRyw1IvtVQodEVAKcFEmTUikW80oLEk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ozUBeHct3BkGXMySHYRXpBTgNxpMNkJI+lAHFsY2aPM/DLffHOPWpaPt+9r5LTzShtQgU9YeWmdrHo+zfJliOCyiNqhTy6V8bALMcXD94nWi/HDMvXlSNnlqHhgHbazB8OHhgE2e5GQdayAcI7rZsgsD01kRWXpevLeG+lVLMSg= 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.18.1.2/8.18.1.2) with ESMTP id 442JaHLb029023; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf53hkqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:01 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFwSg003585 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:59 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmm009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:58 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 25/26] c++: Implement __is_nothrow_invocable built-in trait Date: Thu, 2 May 2024 13:12:26 -0700 Message-ID: <20240502201549.459244-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: rIj4I6JOfPikltJTgl_6UVmFFhVSFtwJ X-Proofpoint-ORIG-GUID: rIj4I6JOfPikltJTgl_6UVmFFhVSFtwJ X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=967 priorityscore=1501 clxscore=1034 bulkscore=0 adultscore=0 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements built-in trait for std::is_nothrow_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __is_nothrow_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_NOTHROW_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_nothrow_invocable. * g++.dg/ext/is_nothrow_invocable.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_nothrow_invocable.C | 62 +++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 6d14ef7dcc7..8679d3ce658 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3825,6 +3825,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_NOTHROW_CONVERTIBLE: inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); break; + case CPTK_IS_NOTHROW_INVOCABLE: + if (!t2) + inform (loc, " %qT is not nothrow invocable", t1); + else + inform (loc, " %qT is not nothrow invocable by %qE", t1, t2); + break; case CPTK_IS_OBJECT: inform (loc, " %qT is not an object type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e420d5390a..0721ecdf3f0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,6 +84,7 @@ DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) +DEFTRAIT_EXPR (IS_NOTHROW_INVOCABLE, "__is_nothrow_invocable", -1) 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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 55c2ec4b5b1..5d1acba7bc8 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12588,6 +12588,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONVERTIBLE: return is_nothrow_convertible (type1, type2); + case CPTK_IS_NOTHROW_INVOCABLE: + return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none); + case CPTK_IS_OBJECT: return object_type_p (type1); @@ -12723,6 +12726,7 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_IS_INVOCABLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: to = type1; @@ -12828,6 +12832,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index d1c66267855..65740a11800 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -134,6 +134,9 @@ #if !__has_builtin (__is_nothrow_convertible) # error "__has_builtin (__is_nothrow_convertible) failed" #endif +#if !__has_builtin (__is_nothrow_invocable) +# error "__has_builtin (__is_nothrow_invocable) failed" +#endif #if !__has_builtin (__is_object) # error "__has_builtin (__is_object) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C new file mode 100644 index 00000000000..2f9b40e5538 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_nothrow_invocable.C @@ -0,0 +1,62 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type = void(*)(); +SA( ! __is_nothrow_invocable(func_type) ); + +#if __cpp_noexcept_function_type +using func_type_nt = void(*)() noexcept; +SA( __is_nothrow_invocable(func_type_nt) ); +#endif + +struct X { }; +using mem_type = int X::*; + +SA( ! __is_nothrow_invocable(mem_type) ); +SA( ! __is_nothrow_invocable(mem_type, int) ); +SA( ! __is_nothrow_invocable(mem_type, int&) ); +SA( __is_nothrow_invocable(mem_type, X&) ); + +using memfun_type = int (X::*)(); + +SA( ! __is_nothrow_invocable(memfun_type) ); +SA( ! __is_nothrow_invocable(memfun_type, int) ); +SA( ! __is_nothrow_invocable(memfun_type, int&) ); +SA( ! __is_nothrow_invocable(memfun_type, X&) ); +SA( ! __is_nothrow_invocable(memfun_type, X*) ); + +#if __cpp_noexcept_function_type +using memfun_type_nt = int (X::*)() noexcept; + +SA( ! __is_nothrow_invocable(memfun_type_nt) ); +SA( ! __is_nothrow_invocable(memfun_type_nt, int) ); +SA( ! __is_nothrow_invocable(memfun_type_nt, int&) ); +SA( __is_nothrow_invocable(memfun_type_nt, X&) ); +SA( __is_nothrow_invocable(memfun_type_nt, X*) ); +#endif + +struct F { + int& operator()(); + long& operator()() const noexcept; + short& operator()(int) &&; + char& operator()(int) const& noexcept; +private: + void operator()(int, int) noexcept; +}; +using CF = const F; + +SA( ! __is_nothrow_invocable(F ) ); +SA( __is_nothrow_invocable(CF) ); + +SA( ! __is_nothrow_invocable(F, int) ); +SA( __is_nothrow_invocable(F&, int) ); + +SA( __is_nothrow_invocable(CF, int) ); +SA( __is_nothrow_invocable(CF&, int) ); +SA( ! __is_nothrow_invocable(F, int, int) ); + +struct FX { + X operator()() const noexcept { return {}; } +}; +SA( __is_nothrow_invocable(FX) ); From patchwork Thu May 2 20:12: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: 1930862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yKzgzya6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVls16QZCz1ymc for ; Fri, 3 May 2024 06:29:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A85A3849ADB for ; Thu, 2 May 2024 20:29:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A85A3849ADB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714681748; bh=F0nF7GLorW4+A9wZDfYZ05jbDuxIx5qa1nO7iFU4z3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yKzgzya6WNg/Z1TGF83l/pIH1w3tpWhJp/6EDN4uwekUfu9XaBKqpGd2DAxZXkkUP M2V94HJzqmpjWwvfet36btgG7kbtL5iPs1QAhQOREU19M0y2cMrVXALO0bUzennNo9 jNGEzLxZMluWjW2M1ojtGvJ2EDvMIrr8zHIVCC38= 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 615163849AC4; Thu, 2 May 2024 20:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 615163849AC4 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 615163849AC4 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=1714680983; cv=none; b=P0p+DSs80LXSkUYcCkfdAIEfgnPunZFH69u2Gi4CqKagTN5kd2iJOPljVyBtgCSHkmu1rt3j6LWKTsqjalDniakWNfd9NP7NVGx/WlFwz0etXA3YieqDrveasy/zud2zlHLtxbsBjISWqZyUxdho7UKraewMcvbUik7ak2sICpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714680983; c=relaxed/simple; bh=PgQvsNlemZ/0ktNYCcnKxWfOAB42/NB8Ce2Rf57NytQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NLhvmfWJdht4Pth9NNyFO9e3N8RGFXaoarP4URfyeWaulC6mSn7G/b5AWUKM7HEs7GawykJTYQbKvwlvgxsqWlwXt6sWSYrMK3wBcsh9DEwNUmu3Ht5vXCBvMQ27N3Jy7pVp2+vQHvTkJVaW2XivDSG3xyR3sgBnoAUQQra11Rk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442KFYFu004275; Thu, 2 May 2024 20:16:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3xvf54sgw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 May 2024 20:16:01 +0000 (GMT) Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 442KFxPQ003586 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 May 2024 13:15:59 -0700 X-Auth-Received: from ken-20xw00qgus.dhcp4.washington.edu ([10.154.75.239]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 442KFqmn009550 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 2 May 2024 13:15:58 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Ken Matsui Subject: [PATCH v18 26/26] libstdc++: Optimize std::is_nothrow_invocable compilation performance Date: Thu, 2 May 2024 13:12:27 -0700 Message-ID: <20240502201549.459244-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502201549.459244-1-kmatsui@gcc.gnu.org> References: <20240502184529.97337-1-kmatsui@gcc.gnu.org> <20240502201549.459244-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QvJsZ9r1ST2cZMAtqIKnbdcAe5vr5fy0 X-Proofpoint-GUID: QvJsZ9r1ST2cZMAtqIKnbdcAe5vr5fy0 X-outbound-smtp: 1 x-header: uw-relay-non-domains X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_12,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 clxscore=1034 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020132 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch optimizes the compilation performance of std::is_nothrow_invocable by dispatching to the new __is_nothrow_invocable built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_nothrow_invocable): Use __is_nothrow_invocable built-in trait. * testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc: Handle the new error from __is_nothrow_invocable. * testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++++ .../20_util/is_nothrow_invocable/incomplete_args_neg.cc | 1 + .../testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 502032787bd..a046560c178 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3269,8 +3269,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// std::is_nothrow_invocable template struct is_nothrow_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable) + : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)> +#else : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>, __call_is_nothrow_<_Fn, _ArgTypes...>>::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_nothrow_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc index 3c225883eaf..3f8542dd366 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_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_nothrow_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc index 5a728bfa03b..d3bdf08448b 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_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