From patchwork Wed Feb 28 19:26: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: 86526 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3AA3338582A9 for ; Wed, 28 Feb 2024 19:30:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AA3338582A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148627; bh=QzdwplnNRx1VgA2ze/PqqCUx+7t9yXY7z440OlggxyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wN5iCSBUdPWEoezhTQErz/8EQGdYsUaERuAFA9+K7lx/D3XH7A3QpOihl5qmPe5hP 3tLyxexnvKRUVLfA/p+wey9qPrxuzvBldFWMQERTBwg/ZfEmcmMFycdzMdaZ52D+jD PNzNkazIJc6gSgYnqjTH772vL/V9omrOGKC8SrGQ= 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 E79CE3858291; Wed, 28 Feb 2024 19:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E79CE3858291 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 E79CE3858291 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=1709148545; cv=none; b=dx1WBQtqgQafjoZkPZwlZkTnwAOn5d6mOv0WNfdsiDGHASzgN7Yz0by1Ewl9wAEONPRweBA6uPSYiAFKHR9Q9qnAiSAk0KsvZ46y6jJ1EJLHHU8tuLf3WvhOwKKqo4HQuhok3oUpNvmpTsp/hzkGRGxNxeB+MDCA7kaJXJRWRjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148545; c=relaxed/simple; bh=+gayWc1RFaYhEpAfXWDRLRzHbgncpbmx+ZwYvS9f8Og=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PFjIrv/tj3TbPNQKLGJeo689IuCTPYGBY4Q6JqAg8CtLk5LWKk8lxWVWfhSC1Y3/ZmQQzZTGlCo738z3Jn2cIAgIPmpfDXUUeL4PJXErdb9TuN2KiBvzgRP8xEThMsf+QVDKgZA3BKzNN7TlTQb9+7XU9wuh/hrreqzMyp2UcXU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJQh2r029569; Wed, 28 Feb 2024 19:29:02 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h20q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSoZQ032334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:50 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTJ015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 01/26] c++: Implement __is_const built-in trait Date: Wed, 28 Feb 2024 11:26:06 -0800 Message-ID: <20240228192843.188979-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vTBHASciyaJek3iRyAw_4e_VVHWoaz69 X-Proofpoint-ORIG-GUID: vTBHASciyaJek3iRyAw_4e_VVHWoaz69 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=706 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 49de3211d4c..f32a1c78d63 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3767,6 +3767,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 394f006f20f..36faed9c0b3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -64,6 +64,7 @@ DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 57840176863..0d08900492b 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12446,6 +12446,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12688,6 +12691,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 02b4b4d745d..e3640faeb96 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -71,6 +71,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8a0e8df72a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Wed Feb 28 19:26: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: 86531 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD6A7385841F for ; Wed, 28 Feb 2024 19:34:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD6A7385841F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148877; bh=3U2RMIKqBuZBalWG7iXOQ5jbvnmTSxsGGfC56O4MG5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mRhdgtU/nlAFolemIZ2aaboowjVxOK+xGWZ9dMSnXYx/xQl0MvP6MASNB6powIcDl Ie967LknFpBTRShRIvkX7E4dGvC81mfe1nyN3uns5ROkbnfcn4bNGKq0cPny3Si0Sv P9Oq/zJLNNGDF5YaA1r6F/eyD29pBHyzi3pOxoyE= 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 8D59838582AD; Wed, 28 Feb 2024 19:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D59838582AD 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 8D59838582AD 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=1709148549; cv=none; b=u5l0JQuWtbQ8AFzGqs89Zt1c3WRkng6MItNOt3I6GQkGkXdJK/fG8ZddvMuDlHtJsMKoryuaSl+EIlb61yl6Wz+rWpmqNHJ3ED6yAwudt7dS9TbWvCdJ4G9pdteYyU0hTEFJI7maD0g8/qaAZguKBYKY7KH43r9nXfHQbqwb+JA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148549; c=relaxed/simple; bh=krkZkP7FbwVFOkHADDbyTuZoJ5CeX8erARRk6VAUT4M=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=i3o5TB/ppqUSowI+0K4/35f7kenWbeqbS7+fwQ0oP9Biv892WEWzP1tNcW0nbcIcRAQsegUwEi+5beM19/zmlaPTBKh7kQR3xxMsyEYh3jQzBuFWO21SPmzeJgPXlIbLnwxvrjJq7trA13Ft+lGH/NgTD96CZiVzyrmtL+xq7Bc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJJloH010615; Wed, 28 Feb 2024 19:29:05 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj8nusn1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSo1V010159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:50 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTK015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 02/26] libstdc++: Optimize std::is_const compilation performance Date: Wed, 28 Feb 2024 11:26:07 -0800 Message-ID: <20240228192843.188979-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: fDOO7NbP8WAnZhTari9cre-1gB5Dt0vp X-Proofpoint-GUID: fDOO7NbP8WAnZhTari9cre-1gB5Dt0vp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1034 mlxlogscore=629 spamscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 21402fd8c13..6e9ebfb8a18 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -835,6 +835,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -842,6 +848,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3327,10 +3334,15 @@ template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template From patchwork Wed Feb 28 19:26: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: 86542 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAB02385829E for ; Wed, 28 Feb 2024 19:40:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAB02385829E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149226; bh=HBScI1zRLDi1AtkU5VDWARmsXMViCe7KgBnxnQ4EvaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=F4r8Na4MLJuY78scvD3vyr3kQQSoh9bqJM07MVfjaZIvRVt7fzySPZai881anjP0E SowZva0WbEZMbsdYRABZeZvRlLyP1jPKIX6UoTTmItYqY58QydCdyqvYXwMiL+sfQW GfIUU8FoBM0ON/Rd1hJx6nfEqujOXuloEfjJDkj4= 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 0C3013858003; Wed, 28 Feb 2024 19:32:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C3013858003 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 0C3013858003 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=1709148739; cv=none; b=lPNlTMTWJLdHdrMCRRinndhgeVyhmNIobd3w7Ca/rKwoUvClOSn11D+9IxBiX8cgTvgmA1d3NgWyZVHkT2cpGilwFtUyEe22PKfSPTs2+Byi1KqGm1ms5vq4/2Vpbayma+hOMSvXyXn3iwmqpVqgBPwW4b5iqewU06/yfAJql70= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148739; c=relaxed/simple; bh=qT2p3iYN6ZUitlfQgbO3KQBMYdcYj7ok3sVuAP9RBDw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=pAIKtT67koV8FYowjpcUvuudf4sMnzXnI00woAbJ2S78Ren0D9Q+FHhhM0uotV7xYmdpOTNSexZg+BEQarHqDTias7pRT2wm6F4YP1D2M0P15gvQ4Z39xaVErzUPsuwKdDBPtH1bCd4wn2YpJtu9NHuLbBOtuPS+mWlNS7GK9YI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJRJHH009014; Wed, 28 Feb 2024 19:32:10 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wjaey0dyq-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSotd025220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:50 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTL015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 03/26] c++: Implement __is_volatile built-in trait Date: Wed, 28 Feb 2024 11:26:08 -0800 Message-ID: <20240228192843.188979-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 4ELw-KGyEKR1ibcyoIJw_acNroEbU_6p X-Proofpoint-GUID: 4ELw-KGyEKR1ibcyoIJw_acNroEbU_6p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 suspectscore=0 mlxlogscore=671 mlxscore=0 spamscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 f32a1c78d63..9a7a12629e7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3861,6 +3861,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 36faed9c0b3..e9347453829 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0d08900492b..41c25f43d27 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12532,6 +12532,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12702,6 +12705,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e3640faeb96..b2e2f2f694d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -158,6 +158,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..80a1cfc880d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; +using cClassType = const ClassType; +using vClassType = volatile ClassType; +using cvClassType = const volatile ClassType; + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Wed Feb 28 19:26: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: 86549 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAC913858288 for ; Wed, 28 Feb 2024 19:45:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAC913858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149509; bh=R0Tatz7ePYJcIzsreplYFv8WcbL1iC29nvSKwqOABYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uWjPbXhB7Vr8Qrwu92LrVln1OURTE8drVNnl19q2nH/z/f8dTsLgc0B4nnISKiL/W Po021KvgJPVhIBJMLrYfZnZjNNfmPa2/Mwu/Hr6MmX+PuFprmLhYSO44/toFwKxJCw yWoyagbChMYPf+R/uE6RUDRHgh6w/RU5/NSwNj/A= 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 5F8E73858291; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F8E73858291 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 5F8E73858291 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=1709148565; cv=none; b=oZjT16a1vOecFImAd3o80CFxRMi9BT5wnRPg9cCrOzph7yaNmjnjVD50jB1Slr34U94HIJXNpVzncxad4w0aXSRwP+/b8fJQ+0lwpxZx7qQPSFZh1W/4vFW+PqWxoS6dpp7bVCdginVvSzMeg2yrj+DC7YxHlxyy9zV2UzCe/O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148565; c=relaxed/simple; bh=scpvDGs6ghBDig1vs9tNzfPTnpQBTf4paMayk1Tkd6c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wkrZux7k252HmHAEBlJvXnZBjEUMJDqIBBx33rHzi84dqx8hlOzw2Ltj4uK/I5gHvrAAiujzcUBVabelAwj/InwP8yr9rTBKT5kW+f4rxjOor0A4ZCttgX04kbI4YDGR3mDybl3J0/3hK8htnIOYWGNRZs/j6cXrrBqEZDAIA2U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJMROQ013261; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9nb90vp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSoBZ019392 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:50 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTM015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 04/26] libstdc++: Optimize std::is_volatile compilation performance Date: Wed, 28 Feb 2024 11:26:09 -0800 Message-ID: <20240228192843.188979-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: xb7LS0vuHY6xiwA_chzYh5uMS-bsMQKh X-Proofpoint-ORIG-GUID: xb7LS0vuHY6xiwA_chzYh5uMS-bsMQKh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1034 mlxlogscore=713 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 6e9ebfb8a18..60cd22b6f15 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -851,6 +851,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) + template + struct is_volatile + : public __bool_constant<__is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -858,6 +864,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3356,10 +3363,15 @@ template inline constexpr bool is_function_v<_Tp&&> = false; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) +template + inline constexpr bool is_volatile_v = __is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Wed Feb 28 19:26: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: 86539 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B29B385843A for ; Wed, 28 Feb 2024 19:38:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B29B385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149131; bh=AIftVXz7P9+yYxHYmZBy0i3IOufAxvtBjVtbM2qGcFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lRbsDqUgaZeWFTDWIw/GCp7SNE2FvUHpbruS5l9HmCoGypbTYHT2AP+VI9Kav9bct 4v0g/Jk0fCJdunznkXFl6xWjZAuEb+RT4bsUWQd+ICl9jtxxAeJw86vN3lYZXhT/mi fT5EM2ywyci1EKHNEWJeuII5PKYTgj+OlWgc4sCM= 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 71F5038582B3; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71F5038582B3 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 71F5038582B3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; cv=none; b=wRDD7zwFZtfuCi7jh2UFTwLzobmLk3cR9IsBqcQRSlS94f8jsl7uBbAQMtD1upJrqFclNUD3rR7jGIUHUGSgyigrj5yD3PwHv70USfZIpp/a+8nlh8ti3ol+J76iYQhe1BnDjmx8P203/ppfCIgXtb/9TaEh5LdHNZsFP535ClA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; c=relaxed/simple; bh=ABYVYG/Vf7sPJKk2v59mOjNLBNDOTWc7R+gUKJQ5Rz8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZD47MsG3JtAS2K+CCFMqcLl5yl4EZVh1bK2MJCB0rYcFgjmLop7eAb8I0TDs1uwLcILxTM+HoMHlMYB1tHe+yvTXVJq/ilnRZoOfCskG5dN+ySaTDQeFNZYhO31xdUTbMFHYSWmGy4ZG5TY37B1nydb6pSSKI7/AMxJ1Fy68/9w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSEgb017134; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wjamt08qa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSoKP019394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTN015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 05/26] c++: Implement __is_pointer built-in trait Date: Wed, 28 Feb 2024 11:26:10 -0800 Message-ID: <20240228192843.188979-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: URyEk-qmbE_C7eEw-86W4nZmbAyC2f3j X-Proofpoint-ORIG-GUID: URyEk-qmbE_C7eEw-86W4nZmbAyC2f3j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1034 phishscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=716 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 9a7a12629e7..244070d93c2 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3828,6 +3828,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e9347453829..18e2d0f3480 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 41c25f43d27..9dcdb06191a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12502,6 +12502,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12701,6 +12704,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b2e2f2f694d..96b7a89e4f1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -125,6 +125,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); From patchwork Wed Feb 28 19:26: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: 86528 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DBADF38582A4 for ; Wed, 28 Feb 2024 19:30:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBADF38582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148644; bh=6TOjuO3hQcoYF7+rvKp1Xl3PQK2Pwpro6u0Qv+GbRuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BtnPwMI8zcBPWEjRG2Te3TT6VpWIDgZ2PeW01yy3w3FvMjaT/6zNZNusUyTWW0sQj gIX53wCAtD6GZjPQCYOb0nYYAmT3DzW7ZTmO7dySDq2Bc5NLdncF3B7RooQvaZrucG XmPiJMx0KY3faUr2Rj2g19YDewA58FBcCbzvNR6Q= 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 85077385829D; Wed, 28 Feb 2024 19:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85077385829D 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 85077385829D 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=1709148545; cv=none; b=sEXQ+cTlsMSJWTcKRgQ5MIVOFYwFC5oAfOW0LLv0cik1CTlqyZ0B5EYiDLPW5tLM7qX52t4EanEFrba1wUeB2crx/4BIzifbpv8+Zwo6zHtAPEU6vkCqJYC4T1RtEg3u3tqiVrFctYAERq0cEta1tZusgC4gPuNtR6BdUzKnRLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148545; c=relaxed/simple; bh=AcQAaALma4cYlup3xWpLUCNLtWjhVcqS+Q4eZDyMwME=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=go6+Hs8Grof1Kb0q5AMd1NIv9W0dSqbXFFnJaQwcsidQVcbzZHnOhzdT3urT/dG4Mv6FEo8WDIpkqeDjxjZoarR0hY+nKQ81zl/Gi+FDFcMAoVP7Tg5AQAsdkYxTVCYQmDmZbwgfUeiwrfTLfoi4K557rgrOkc4hmIx51zd6He8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJT13a001880; Wed, 28 Feb 2024 19:29:01 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h20n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSoQr032336 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTO015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v14 06/26] libstdc++: Optimize std::is_pointer compilation performance Date: Wed, 28 Feb 2024 11:26:11 -0800 Message-ID: <20240228192843.188979-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 6KWuNf4UndaJcQURLZkIv1NLokDL7-fR X-Proofpoint-ORIG-GUID: 6KWuNf4UndaJcQURLZkIv1NLokDL7-fR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=356 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 60cd22b6f15..6407738a726 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3264,8 +3278,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Wed Feb 28 19:26: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: 86530 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4980385840A for ; Wed, 28 Feb 2024 19:32:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4980385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148776; bh=tRJvrRi8eLOmu9rmtjWVTBM9wV6TwmzSiK3xqsnXDtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Wz+tA3R7wjC4cnXudrMqHIBpI+SZQ4O9xnmARIFIHtagzqwjIA1GGEw5Zy2XNc1ch 2Z8CDJz4r5lV8anh1cDe0S5wm3HtcBfXNvZEIYn4zFiJRbXzKHlWRfem1OGbpS6UVk XcDxLv32UUA0MNM0tsNel2ZfdKdrvpsOvhvDcGjI= 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 911873858CDA; Wed, 28 Feb 2024 19:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 911873858CDA 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 911873858CDA 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=1709148548; cv=none; b=rk9vBPbQ83RTNtC/oYw0fOiSCfZaqvqvRA0Nn0O5KScUVe2kP8Bxv/LNvSlIItizFysVMPqqcb/voRv73lYIoHWUWg434WKo3wV4hqCloYIB4u6ncCybfAbn6mpKZXlNkh+/fWxrkHknOHAEXATlTkfqnCTZuHXyfSdXqNovWvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148548; c=relaxed/simple; bh=FE3LO43GDXdNQPKxpGM7ipYxwmM4Jf0MMU1aCJjsQ+k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VPUnPs5iKRbmMfE98H0cFyeU+HXQhoNB9CKuTBuJqLLh650zPkMYsoosbhxVotNs8OOfgGZt59WkH3HaspBLv8Pa08fjpAQ3x50jbzAh5LQ7686ON+jxtcjQr98UaGYGw1EwBmXkVocuGilAiq1GIk7SUokJ9XDi3gDBgLHDSvI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJJloG010615; Wed, 28 Feb 2024 19:29:02 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj8nusn0x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpql032338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTP015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:50 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 07/26] c++: Implement __is_unbounded_array built-in trait Date: Wed, 28 Feb 2024 11:26:12 -0800 Message-ID: <20240228192843.188979-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 1MvJ2INYvo0TtUWJSukBsrAL6uRBKI7g X-Proofpoint-GUID: 1MvJ2INYvo0TtUWJSukBsrAL6uRBKI7g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1034 mlxlogscore=599 spamscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 244070d93c2..000df847342 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3861,6 +3861,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 18e2d0f3480..05514a51c21 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -92,6 +92,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9dcdb06191a..1794e83baa2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12532,6 +12532,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12708,6 +12711,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 96b7a89e4f1..b1430e9bd8b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -158,6 +158,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..283a74e1a0a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +class ClassType { }; +class IncompleteClass; +union IncompleteUnion; + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Wed Feb 28 19:26: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: 86544 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A01A385829E for ; Wed, 28 Feb 2024 19:41:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A01A385829E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149305; bh=EFzDqAXEc0hD9OxGNDy7+Cs0o9rMGdOQbgxzn5p74wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RK3plzjnd+MMlLpPwcn9/DeK6Px84BUVO3zp48uPO3BXDj9j5k3FAtRR9FBUvR3y9 uMSpviKtF8UmYWgVfyz5u/2L1nGepVdOriYwIuT8+G8dNuSlw5syIJ7N9004+HvtnB p/JSvI7yWsVKtI4h52tg3tWTWCWeJLb0dFyPe8Ro= 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 5DE4E385800C; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DE4E385800C 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 5DE4E385800C 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=1709148565; cv=none; b=u42M9AnJTDP0wYI0ntXAeVeCFgjYw6O9xa7gR35pfGkHCWBvDM4b57rOSATFhKFFBkfvQ3K4+8l8PvOBkE4OVQQW0eEsdHdx6x2vQQdDyyPGeE32N42DYfnXROpluFCYafFMBrvzc1Vwbsp+DeImOedWkp2JaV85iM+ufy70eFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148565; c=relaxed/simple; bh=13wIOCyZZ0VvI/3vJQIUh28PkeSInImhy/DCyeMQ5NE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vT94a9UkU/R/YZpOLJOfdwA6qDRbJ49O3nEWECd7khPX1msvZxS5hy4VQpdO/SQxMri7YPMkKFkO7g3nbib8AfDTrED1M3ubnPGyb9LZITXXZmgCufn5LWzA/zziDMQh7xXqZGEv+2i+nHspIBxTqFBHkzoC/XdGdrmblWg72Ws= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJQWom009324; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj80r9ysh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpiE019396 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTQ015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 08/26] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Wed, 28 Feb 2024 11:26:13 -0800 Message-ID: <20240228192843.188979-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: T7QOP4Zrwo-E32XRLpgx3Eq91QC8muyp X-Proofpoint-ORIG-GUID: T7QOP4Zrwo-E32XRLpgx3Eq91QC8muyp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 mlxlogscore=507 mlxscore=0 adultscore=0 spamscore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 6407738a726..c4585a23df9 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3706,11 +3706,16 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Wed Feb 28 19:26: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: 86543 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E6DF3858434 for ; Wed, 28 Feb 2024 19:40:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E6DF3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149243; bh=IxV0PF8RWIvKirtbPs4zduZDfZhpZPp4WvS6ATQTDo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=kjKGNjrL2CahAsUHnMbP1j/wQW1O8PyedvgJjQiFUzXbmeYxkzPwYKmOVPQUXKfCk R7XxJA39ZIiWLcJS4j+3ulrKKvAhSPTRs36m9p35Myi17Jq39R/ncfxAtiHeUMWhlc AK6lD2DAFzJ5bdslhuV+72IknLjmwclyb9it/WOU= 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 5EF503858419; Wed, 28 Feb 2024 19:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EF503858419 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 5EF503858419 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=1709148732; cv=none; b=JrLUSjCXQizCWaRUmo0IHhUdm6JaE9ypZrmpBNpRuBKJguUEYwiMFHUGz/RXoO3hgqcp0wqItVNK8B2cIFHDJpTIKKrd0YcaChqPQ5Nv6G4bdINrDizxP8id0/BWSHNL9kEde+UkxLdFxOpac6lFV1p6ZiALxciML75bcx9Rfsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148732; c=relaxed/simple; bh=JQWUx86UYfEHkoy5ltIowRN7CWagJqahw136dz0ciLY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A6V4J63M4+o0VMmv8TG9FF5m1AkHbAQpLm9vIZUheX584EHlUPbXsx+5PYJQ85QCkFKECDCF2Eo1XmkfMNn4UYr3KtEwK0aqGGVoC6uQo0q4VdFKRDiZMSSGwGZCRhm99utDS6eJL2EPEOPecYMwTlpxLireeVXWxP/ETaZyV6w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJN38d023350; Wed, 28 Feb 2024 19:32:05 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9qqgxt0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpBb018990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTR015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 09/26] c++: Implement __add_pointer built-in trait Date: Wed, 28 Feb 2024 11:26:14 -0800 Message-ID: <20240228192843.188979-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Jf9iq8LY0d0brQk9NoaVGZAWlbSz39yk X-Proofpoint-ORIG-GUID: Jf9iq8LY0d0brQk9NoaVGZAWlbSz39yk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 mlxlogscore=661 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __add_pointer. * g++.dg/ext/add_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 9 ++++++ gcc/testsuite/g++.dg/ext/add_pointer.C | 39 ++++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ 4 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 05514a51c21..63f879287ce 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 1794e83baa2..635441a7a90 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12776,6 +12776,15 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_POINTER: + if (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE)) + return type1; + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + return build_pointer_type (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_pointer.C b/gcc/testsuite/g++.dg/ext/add_pointer.C new file mode 100644 index 00000000000..c405cdd0feb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_pointer.C @@ -0,0 +1,39 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_pointer(int), int*)); +SA(__is_same(__add_pointer(int*), int**)); +SA(__is_same(__add_pointer(const int), const int*)); +SA(__is_same(__add_pointer(int&), int*)); +SA(__is_same(__add_pointer(ClassType*), ClassType**)); +SA(__is_same(__add_pointer(ClassType), ClassType*)); +SA(__is_same(__add_pointer(void), void*)); +SA(__is_same(__add_pointer(const void), const void*)); +SA(__is_same(__add_pointer(volatile void), volatile void*)); +SA(__is_same(__add_pointer(const volatile void), const volatile void*)); + +void f1(); +using f1_type = decltype(f1); +using pf1_type = decltype(&f1); +SA(__is_same(__add_pointer(f1_type), pf1_type)); + +void f2() noexcept; // PR libstdc++/78361 +using f2_type = decltype(f2); +using pf2_type = decltype(&f2); +SA(__is_same(__add_pointer(f2_type), pf2_type)); + +using fn_type = void(); +using pfn_type = void(*)(); +SA(__is_same(__add_pointer(fn_type), pfn_type)); + +SA(__is_same(__add_pointer(void() &), void() &)); +SA(__is_same(__add_pointer(void() & noexcept), void() & noexcept)); +SA(__is_same(__add_pointer(void() const), void() const)); +SA(__is_same(__add_pointer(void(...) &), void(...) &)); +SA(__is_same(__add_pointer(void(...) & noexcept), void(...) & noexcept)); +SA(__is_same(__add_pointer(void(...) const), void(...) const)); + +SA(__is_same(__add_pointer(void() __restrict), void() __restrict)); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b1430e9bd8b..9d861398bae 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_pointer) +# error "__has_builtin (__add_pointer) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Wed Feb 28 19:26: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: 86545 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9C9D3858004 for ; Wed, 28 Feb 2024 19:42:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9C9D3858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149336; bh=aaZU/WEaPXym68byYiPPLg33qkHfBSIARTF28eRhxIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=t57atMLkZiwc2y7iqizZ2XB3NzJ8Cf06cmXHonJceo8C/PfmH+Hzfbh39mP8QVfXR Ca//PexYGoibjUNqiP/PhpviqcMvPyv4lDrquyBbf7yhPUKhdLkHTn77ulnlxoPd/X gNPvLv2mHbXJ0ORrYlj2cl04deBcoZRV9em4ZSOw= 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 8FDBD385842C; Wed, 28 Feb 2024 19:32:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FDBD385842C 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 8FDBD385842C 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=1709148734; cv=none; b=m9Thl5Hdi4DVtrxPGFf29wiD6HFBenClcFEjqbH7hRFg77VFyIV6OXioPcsmlDmlP8tsq0EDXNcznByowF8Xrqf49t5TpW3whMPGrJWyBIfXgdc7pEw8/uAPLZ3YNPkGZU/HDS5/WGc22Gzt4H7C1m9QmQ0MEahxGjqAzKtC08Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148734; c=relaxed/simple; bh=SMt1ATz5PvdGT88I7ZsWbD1XeEXls6sKBtZzFXaF04U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vF9d0hQeeoMjWEEym98P5JWe8S/95W4sKLRZT99ApIqaknawwV4zzzHotTZ+gGvHeacano56wSCqXzTadnM/VuVbbXHnFNesVH09Wwx1Wdjr+YxYpwMh7GCMVfKaymA9dBmw+fdmPnDBMmw3d9avPgONDZygfla9stFbLgPDTE4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJS9uj011519; Wed, 28 Feb 2024 19:32:08 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3whxdj4wax-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:08 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSph2018991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTS015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 10/26] libstdc++: Optimize std::add_pointer compilation performance Date: Wed, 28 Feb 2024 11:26:15 -0800 Message-ID: <20240228192843.188979-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: jUlYNH_FUafS5C3HC-bEP-IsL4ebP9wX X-Proofpoint-ORIG-GUID: jUlYNH_FUafS5C3HC-bEP-IsL4ebP9wX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 priorityscore=1501 mlxlogscore=625 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 c4585a23df9..6346d1daee2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2149,6 +2149,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; #endif + /// add_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_pointer) + template + struct add_pointer + { using type = __add_pointer(_Tp); }; +#else template struct __add_pointer_helper { using type = _Tp; }; @@ -2157,7 +2163,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __add_pointer_helper<_Tp, __void_t<_Tp*>> { using type = _Tp*; }; - /// add_pointer template struct add_pointer : public __add_pointer_helper<_Tp> @@ -2170,6 +2175,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct add_pointer<_Tp&&> { using type = _Tp*; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_pointer From patchwork Wed Feb 28 19:26:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 86535 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9AC3E3858288 for ; Wed, 28 Feb 2024 19:37:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AC3E3858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149032; bh=VCR1fZ5CXHZMm4uAmFxf42twY19+JZcVenK7BHozzMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=n6o9fyOdb+wfN+ptaLe9+PI6bdTbM4pXv30qJJh09uMSeKd3kVXB6OxNOmYs3GlW0 vJFZsLzJwPV8qIx+hQdufG3wXiS7H6Mn+99bvzZmjVq8LqwFJJLx1X3M1QjQN4nRMo yHBel+DK2yHenk+ZdYuseOMZiVOZXv7m98ILa7Ek= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id A0F413858000; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0F413858000 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A0F413858000 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; cv=none; b=xEGEyCKZNUjz1Z8xDz1dCvE9Tz6XelvbMjfctZ72te14HCI43cgb3XSl9m7Fx9Fs4mOPiQh10VygOP0ZY0JNLzHqXb+mYb4lz6RP27uB3ksAsp95/Ee7Vrj4kuCsi571q+nD1w5xagmuQ7pc+Ujhb9CvQC20teqZjq0McyOCTjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; c=relaxed/simple; bh=VtQnoussf2bSaiJHSc6oXahNbkNP+zD4tnolaN02p84=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tz3LvUXohN5q6wKTiPH8ZTmqEd3Aywr94Rt7ZxvOR5U0r5UZr2p6uO/YqZ3isH/6aCJXb9s1wQqmLrh+XyyH+7vihYYZ0GK1zQbtXvoLZUpfUcB9+R2Jzqid4Sw3ho9ziZUORvqQxf+C3325AE40iZUXSj5X19DkUfVOZcu5eQY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJJloL010615; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj8nusn3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpWM019397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTT015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 11/26] c++: Implement __remove_extent built-in trait Date: Wed, 28 Feb 2024 11:26:16 -0800 Message-ID: <20240228192843.188979-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1034 mlxlogscore=464 spamscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 635441a7a90..58696225fc4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_EXTENT: + if (TREE_CODE (type1) == ARRAY_TYPE) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_POINTER: if (TYPE_PTR_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 9d861398bae..5d5cbe3b019 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -182,6 +182,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_extent) +# error "__has_builtin (__remove_extent) failed" +#endif #if !__has_builtin (__remove_pointer) # error "__has_builtin (__remove_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_extent.C b/gcc/testsuite/g++.dg/ext/remove_extent.C new file mode 100644 index 00000000000..6183aca5a48 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_extent.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__remove_extent(int), int)); +SA(__is_same(__remove_extent(int[2]), int)); +SA(__is_same(__remove_extent(int[2][3]), int[3])); +SA(__is_same(__remove_extent(int[][3]), int[3])); +SA(__is_same(__remove_extent(const int[2]), const int)); +SA(__is_same(__remove_extent(ClassType), ClassType)); +SA(__is_same(__remove_extent(ClassType[2]), ClassType)); +SA(__is_same(__remove_extent(ClassType[2][3]), ClassType[3])); +SA(__is_same(__remove_extent(ClassType[][3]), ClassType[3])); +SA(__is_same(__remove_extent(const ClassType[2]), const ClassType)); From patchwork Wed Feb 28 19:26: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: 86536 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A9C63858C3A for ; Wed, 28 Feb 2024 19:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A9C63858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149061; bh=Y3KwK4UariaDhMlg1CtRZTUxb0YlxPX1cgnmNYjjmho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=m0tKDpcRGgdCi5ivy+i/A8WEV3Um+mbsnK/hkflsv53txD09PdJYSxeuJqNDf/MC9 3utiwPSolWjKPtLhzP6BGphMIqHrUiGwKgwcvuCqga5a5Co1VwTcrCdSjoYpFtxbpT //1D0LdR6ahxdieogYutgHfH9idoxxq3P/iP355A= 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 7C6A5385840E; Wed, 28 Feb 2024 19:32:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C6A5385840E 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 7C6A5385840E 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=1709148739; cv=none; b=Eiw2xfRZPfo5V4C4xA6VP04IGvCnp8P7/+6SNM6ZUXcSXBQQOu9Iub+OXE+f/aldnvxrITIV+eJ3EkJutgAlbl8zQ2c9N8LDk9nrThMK6E1yOaUziL0DwRaVJ2JMhkE5USWrvDEkAcVaK9Q3vzBnq/T2S7SqyYjY4egr4D2xZdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148739; c=relaxed/simple; bh=C7tTcuEH3hAPeCXwLyEk4oZBzyNN8xqMGlQcsxtt6hQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=b7L2ZPJvFnpXVqFEQVOWcjDTIf7VnjlGQ7+CKaNpwmYLpkdgBWrJSPLJSi7A/Vezw0KVCqmf0g7AkGV4X6LP5DPNZwZS5EF42UESGn9168fp7pdz2H7bTTdx1xK0F2BEVcgTbiLb2ZIphYkNDPeMThcasNEqhPanv7II8aJWLKM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJS7R5020946; Wed, 28 Feb 2024 19:32:13 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wja2y8p52-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:12 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpOS020754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTU015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 12/26] libstdc++: Optimize std::remove_extent compilation performance Date: Wed, 28 Feb 2024 11:26:17 -0800 Message-ID: <20240228192843.188979-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: v605bkapRHUKfIob-uirlpUrs_mSyIF1 X-Proofpoint-GUID: v605bkapRHUKfIob-uirlpUrs_mSyIF1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 malwarescore=0 mlxlogscore=655 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 6346d1daee2..73ddce351fd 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2092,6 +2092,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Array modifications. /// remove_extent +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_extent) + template + struct remove_extent + { using type = __remove_extent(_Tp); }; +#else template struct remove_extent { using type = _Tp; }; @@ -2103,6 +2108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_extent<_Tp[]> { using type = _Tp; }; +#endif /// remove_all_extents template From patchwork Wed Feb 28 19:26: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: 86541 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9138D3858285 for ; Wed, 28 Feb 2024 19:39:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9138D3858285 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149173; bh=v7vcdja1ul05ur34H0TmQ/T48IuOguGZkR/jvozE0RU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mglDysF3wt5Hf9yYVPEKxf1v+6iQi5jAU1QfIGvthm7CQ9IZO6SdcihEV27GMuXOX R678Tqi9H4JwVF35lwtS1cGa9VtC0K7XfFANY6bWl8gJ291YKNanqsDxXoWMpoBYse Sw/rJdOsD1BtXzzjY4AJtRzgDYjyLJSa1xVCynd0= 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 8EFAC3858C52; Wed, 28 Feb 2024 19:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EFAC3858C52 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 8EFAC3858C52 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=1709148747; cv=none; b=U57DVmSP3v8eJtuC2u2qCYo4BbjyJXeCBBz/PmKs04smxDDQ7yf6pNIbvz+JSnWqxhxzLNyGNDflaReOoFwgq3yLiQQL1dtBecijJpBww2/3p3d+/lKQywWalBV30jnWyWK39frwbt3vpR48Brn8J2y0F626651Ht0MdZAn770g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148747; c=relaxed/simple; bh=7xsCjy9x4pnlmK9RG8lwUMTYkh1i/PXbFIZBXj0ZriU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QPbJxIfnSgzJ4n6zr40Qt+AyWvvIC+cOeXW9ApOu0+fydEBSetXUcUeFA41N9VA/OOjLqjH1O2Cj0ryeG1dML+9jf0YMJDALAl9pFtQCHte7jTL74urQ+hIxRVBUW+bNrIfV4D4be13RsXHft58Vjyq84rm+zHYlcvb7HASb4K4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJU4hZ010341; Wed, 28 Feb 2024 19:32:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9qqgxtc-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:14 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSp4r020755 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTV015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 13/26] c++: Implement __remove_all_extents built-in trait Date: Wed, 28 Feb 2024 11:26:18 -0800 Message-ID: <20240228192843.188979-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 5-Gzx_XZxpJ6WK2-SejNbQJ4QyeUPb8X X-Proofpoint-ORIG-GUID: 5-Gzx_XZxpJ6WK2-SejNbQJ4QyeUPb8X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 mlxlogscore=433 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 58696225fc4..078424dac23 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12785,6 +12785,9 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return build_pointer_type (type1); + case CPTK_REMOVE_ALL_EXTENTS: + return strip_array_types (type1); + case CPTK_REMOVE_CV: return cv_unqualified (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 5d5cbe3b019..85b74bd676b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -176,6 +176,9 @@ #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif +#if !__has_builtin (__remove_all_extents) +# error "__has_builtin (__remove_all_extents) failed" +#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_all_extents.C b/gcc/testsuite/g++.dg/ext/remove_all_extents.C new file mode 100644 index 00000000000..60ade2ade7f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_all_extents.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__remove_all_extents(int), int)); +SA(__is_same(__remove_all_extents(int[2]), int)); +SA(__is_same(__remove_all_extents(int[2][3]), int)); +SA(__is_same(__remove_all_extents(int[][3]), int)); +SA(__is_same(__remove_all_extents(const int[2][3]), const int)); +SA(__is_same(__remove_all_extents(ClassType), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[2]), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[2][3]), ClassType)); +SA(__is_same(__remove_all_extents(ClassType[][3]), ClassType)); +SA(__is_same(__remove_all_extents(const ClassType[2][3]), const ClassType)); From patchwork Wed Feb 28 19:26: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: 86532 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 680A83858438 for ; Wed, 28 Feb 2024 19:34:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 680A83858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148884; bh=3t2NKsrNHoK6JH4mvSW3eH0lqgZun8CNHli3FIpNshE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=m6G5QAEwsoh29sYBNXomV1CP2KCmowNNgs9spV0casnNpVYJzAP4FziZ6E+Rf9oGM /oF0ndTY171YZBKk7i5b18gEO385N96jOe0W2LRKTM2AC95RsMtpHFfNViUQRtkjeO OzMRwnq7yLmrrqUXTDpEWN1uTQdbOoxrZi43v6co= 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 8DEA03858CDA; Wed, 28 Feb 2024 19:32:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DEA03858CDA 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 8DEA03858CDA 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=1709148727; cv=none; b=l9ry3kNtdQH5pxAWRhYxkW8ZdgOZ1bZKKGDwH733tqouJgJevoyT+xfvr/PFvMVxyCmHrPExr5hicS/mjQK+3/7JIOsOH8z+9HqJyOMSIU3EFd9wXF4ek49FDN9BeT+neP7eB6jlHjc8IaCZQ2XkUGqHEmH2c2DWG0pA9KRuXRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148727; c=relaxed/simple; bh=wD4wEX2ZPJI2oSMSFb2W49Aue7gy5ilTVn0uvzEEG40=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Epk3QyAjl7MSqCBh/riD3d5602D6IqCapjzfvEkwKzVM7gS+LOlSRvhprHL19OOdDHqy4xmZRHrqLF8iuLQBKH/bkTNckSQkpIRoH+Lkgt32MbnoeAYrZabccjk4JVWy6vrkq9Vri2ebW8BDZEnl91zfQbV8q1H5ouveVfYFCHw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJN38c023350; Wed, 28 Feb 2024 19:32:05 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9qqgxt0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpMi018993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTW015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 14/26] libstdc++: Optimize std::remove_all_extents compilation performance Date: Wed, 28 Feb 2024 11:26:19 -0800 Message-ID: <20240228192843.188979-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: RQ9ZwjfNqmWmazBBen2a0zbwznqNbcbu X-Proofpoint-ORIG-GUID: RQ9ZwjfNqmWmazBBen2a0zbwznqNbcbu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 mlxlogscore=802 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 73ddce351fd..34475e6279a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2111,6 +2111,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// remove_all_extents +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_all_extents) + template + struct remove_all_extents + { using type = __remove_all_extents(_Tp); }; +#else template struct remove_all_extents { using type = _Tp; }; @@ -2122,6 +2127,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct remove_all_extents<_Tp[]> { using type = typename remove_all_extents<_Tp>::type; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_extent From patchwork Wed Feb 28 19:26: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: 86533 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F083338582A3 for ; Wed, 28 Feb 2024 19:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F083338582A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148964; bh=tKvRVq7l6vwbsPH6YkVrujeRBKeLUCM65oxAufp3rDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UYj4AjER/TR1B8UA8APjMINCopUaEUo1gvFIrI78DYEpzEEeEY6OcNZnzSSZA4CLi l0z5l9VoQelso6dOu1DNDItGcQrb+CcRdACVQUkAhHq19abrNOP8lwuMZDZZkZa86G NLTTo+vlZVk7yToIZkAbIrYghO2yOfSNW72sLJCY= 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 A103F385800D; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A103F385800D 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 A103F385800D 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=1709148573; cv=none; b=VpplyUISFtfUEQeqvENKIy0UERv8If4w7ImAi8k+dcq6jsME0ajGGWYlBeCwbbUWTUP4TMNoow3OAfMg0kmUnOKLlWWbe5PbR5Fw2V+gVepyLINwbVB+s6r+cjKx9oSV6/abwga3NEqCrl39OVcylxms4EFKmk6qA8RP5Hl38Rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148573; c=relaxed/simple; bh=T+eF/ckLGijloNSkdNnsGtm2fWD7Gp2Q3TVqEDOcdTI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kIjIotMtVFnsHhqrn3NT09cP5oz5B96NrmM5KSWLZrI1XejtKd/ELGsFYw6ltunBnlmZCGkrqFi5TnnqcvdXspltKiOGzUe/z8tPRwNFxe2gEjDfV7nQY74MFPdA/jh0TqeOlZulyUaFHKpMbs/Xn+wl4kmdUwM2NpJdR2quwFo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJDFPa021389; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9nb90vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpe2019399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTX015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 15/26] c++: Implement __add_lvalue_reference built-in trait Date: Wed, 28 Feb 2024 11:26:20 -0800 Message-ID: <20240228192843.188979-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hSk_dRoubolV20U8LjAiY3dMWb9xU-yN X-Proofpoint-ORIG-GUID: hSk_dRoubolV20U8LjAiY3dMWb9xU-yN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1034 mlxlogscore=769 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 | 8 +++++++ .../g++.dg/ext/add_lvalue_reference.C | 21 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_lvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 933c8bcbe68..9a27dca4ea3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -48,6 +48,7 @@ #define DEFTRAIT_TYPE_DEFAULTED #endif +DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 078424dac23..05f5b62f9df 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12776,6 +12776,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { + case CPTK_ADD_LVALUE_REFERENCE: + if (VOID_TYPE_P (type1) + || (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE))) + return type1; + return cp_build_reference_type (type1, /*rval=*/false); + case CPTK_ADD_POINTER: if (FUNC_OR_METHOD_TYPE_P (type1) && (type_memfn_quals (type1) != TYPE_UNQUALIFIED diff --git a/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C new file mode 100644 index 00000000000..8fe1e0300e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_lvalue_reference.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_lvalue_reference(int), int&)); +SA(__is_same(__add_lvalue_reference(int&), int&)); +SA(__is_same(__add_lvalue_reference(const int), const int&)); +SA(__is_same(__add_lvalue_reference(int*), int*&)); +SA(__is_same(__add_lvalue_reference(ClassType&), ClassType&)); +SA(__is_same(__add_lvalue_reference(ClassType), ClassType&)); +SA(__is_same(__add_lvalue_reference(int(int)), int(&)(int))); +SA(__is_same(__add_lvalue_reference(int&&), int&)); +SA(__is_same(__add_lvalue_reference(ClassType&&), ClassType&)); +SA(__is_same(__add_lvalue_reference(void), void)); +SA(__is_same(__add_lvalue_reference(const void), const void)); +SA(__is_same(__add_lvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_lvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_lvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_lvalue_reference(bool(int)), bool(&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 85b74bd676b..3fca9cfabcc 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -2,6 +2,9 @@ // { dg-do compile } // Verify that __has_builtin gives the correct answer for C++ built-ins. +#if !__has_builtin (__add_lvalue_reference) +# error "__has_builtin (__add_lvalue_reference) failed" +#endif #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif From patchwork Wed Feb 28 19:26: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: 86538 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1327385842C for ; Wed, 28 Feb 2024 19:38:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1327385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149088; bh=n5wLONU2u6JlIhFT8HIAB40eZiuJ42IeVNr0AnCccHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=C68YHrYmjhscyLom+Ime54m43pdYGK3ogEKspAVA5v6voc0Fi6bTzDzBaqSVqFRiH zMxvoQOj1MrZR2AKrdr4MLgJ1YmAOu2zZVcvOBk76Rc/KGOwTLfNp/OVT5eKdo3Etf l4YthtRH5sS/zBCXfBj9qZ6TCRGktq/lyHPyXYVE= 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 A889B3858430; Wed, 28 Feb 2024 19:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A889B3858430 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 A889B3858430 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=1709148733; cv=none; b=q/XVIKIhmwL5i9eptkt0SMsEib9Vezr2tf5e6/mFbwLyNYOVVm3boNqe677J+Bh995NDcM9fhP6MYlBjUxOt0j4BGAJmnV6EFKSKLO1WiYkHXI8BhhtCnvEoWiYejrv6mNyIgPCMbe8NSFMLB0R5JsChdZQMvE1Mw/uFiU3biKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148733; c=relaxed/simple; bh=ueYe/7FEcEzM4jDKaJtjXvZjWBm91DDzYCcCLh+8Oxg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZR883V/Z3dqqGaPKPqlcGlXN783mC37j2G6gwgqzbJWWu9jJDk4iQm25Qa2sNbeVJBATH9O9OpaI0UoZBooz8w9cS1aE4UabNmAKG74pgcW5VLSgBlyxHQZ9Rvf55ehj2lf3Tvqan/atEpZZcJhcUiWIqFBR/axKgjLlWMA0Gog= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJVMHQ022168; Wed, 28 Feb 2024 19:32:06 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3whxdj4wbf-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:06 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpYb025225 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTY015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 16/26] libstdc++: Optimize std::add_lvalue_reference compilation performance Date: Wed, 28 Feb 2024 11:26:21 -0800 Message-ID: <20240228192843.188979-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 3e8fV_KcqBxjfgYH4Z-wfJ5tx3Qs0u3Y X-Proofpoint-ORIG-GUID: 3e8fV_KcqBxjfgYH4Z-wfJ5tx3Qs0u3Y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 priorityscore=1501 mlxlogscore=577 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 34475e6279a..17bf47d59d3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1157,6 +1157,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference) + template + struct __add_lvalue_reference_helper + { using type = __add_lvalue_reference(_Tp); }; +#else template struct __add_lvalue_reference_helper { using type = _Tp; }; @@ -1164,6 +1169,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_lvalue_reference_helper<_Tp, __void_t<_Tp&>> { using type = _Tp&; }; +#endif template using __add_lval_ref_t = typename __add_lvalue_reference_helper<_Tp>::type; @@ -1731,9 +1737,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_lvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_lvalue_reference) + template + struct add_lvalue_reference + { using type = __add_lvalue_reference(_Tp); }; +#else template struct add_lvalue_reference { using type = __add_lval_ref_t<_Tp>; }; +#endif /// add_rvalue_reference template From patchwork Wed Feb 28 19:26: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: 86537 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 360653858291 for ; Wed, 28 Feb 2024 19:37:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 360653858291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149079; bh=3EZuA1B/ksPpfjZ2xh9r7uKZL3aWvZmmSEkF39VTjSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QPdu9ychIpmNC+G3CLC5Pke8QcNZXzX7LLRJovbig97naQ44eeHMcM4IYC7ivuGHe UOiFYsfZ11GZC5erj7JcePZ872enX2HzGEADLZR8Bj8jqtWdELNsoWXO8gScPpOYcU 6m3ZLE6CTxLmDS4jjB4SSpiL8BmzFN1AyX/MrmuY= 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 A45EF38582B7; Wed, 28 Feb 2024 19:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A45EF38582B7 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 A45EF38582B7 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=1709148551; cv=none; b=Yu//ImiIi+4vo/wYRJxEGXb3cXX+7ZmzInX73jBMD/FgFUCl9hwoZLkqCAX0rvy2ZCOxFi7eaEwlGeoOSoqrYHH3u+EAqwrmqy+/dzq1/nKoLDeBlzW2JzIkyx026GhnM1PpJPp64pHMnCTzkzusOz7l4n3ctlawURWka7DAcY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148551; c=relaxed/simple; bh=Cy52qonx7cmWVT63RHPOoDcdAI6F8a0OdY6rJhb75IQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=S7zFVetQ3QugaFctVkOIxszfTeRWaqCj5fV3a8vztlU69sLdoEzPsvpQtBbvHvlOkn1LL/fYYORQQ16sVMYQyZ8QIEYhLCBUeyMXZ3cyB+Z2H+wUYh+iJIUCQuhJq8JF+wqWVNng8Eh+/LQCM8m8zr+PEfwmLOyaogfpNvM6/jc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSh9F001591; Wed, 28 Feb 2024 19:29:05 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h219-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSppM010162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTZ015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 17/26] c++: Implement __add_rvalue_reference built-in trait Date: Wed, 28 Feb 2024 11:26:22 -0800 Message-ID: <20240228192843.188979-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 1mdR-SRJFrRQTnTiIHeQ1m7leZToe-BX X-Proofpoint-ORIG-GUID: 1mdR-SRJFrRQTnTiIHeQ1m7leZToe-BX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=324 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 | 8 ++++++++ .../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/add_rvalue_reference.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9a27dca4ea3..173818adf79 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -50,6 +50,7 @@ DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1) DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1) +DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__add_rvalue_reference", 1) DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1) DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1) DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 05f5b62f9df..19d6f87a9ea 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return build_pointer_type (type1); + case CPTK_ADD_RVALUE_REFERENCE: + if (VOID_TYPE_P (type1) + || (FUNC_OR_METHOD_TYPE_P (type1) + && (type_memfn_quals (type1) != TYPE_UNQUALIFIED + || type_memfn_rqual (type1) != REF_QUAL_NONE))) + return type1; + return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C new file mode 100644 index 00000000000..c92fe6bfa17 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__add_rvalue_reference(int), int&&)); +SA(__is_same(__add_rvalue_reference(int&&), int&&)); +SA(__is_same(__add_rvalue_reference(int&), int&)); +SA(__is_same(__add_rvalue_reference(const int), const int&&)); +SA(__is_same(__add_rvalue_reference(int*), int*&&)); +SA(__is_same(__add_rvalue_reference(ClassType&&), ClassType&&)); +SA(__is_same(__add_rvalue_reference(ClassType), ClassType&&)); +SA(__is_same(__add_rvalue_reference(int(int)), int(&&)(int))); +SA(__is_same(__add_rvalue_reference(void), void)); +SA(__is_same(__add_rvalue_reference(const void), const void)); +SA(__is_same(__add_rvalue_reference(bool(int) const), bool(int) const)); +SA(__is_same(__add_rvalue_reference(bool(int) &), bool(int) &)); +SA(__is_same(__add_rvalue_reference(bool(int) const &&), bool(int) const &&)); +SA(__is_same(__add_rvalue_reference(bool(int)), bool(&&)(int))); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3fca9cfabcc..c2503c5d82b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,6 +8,9 @@ #if !__has_builtin (__add_pointer) # error "__has_builtin (__add_pointer) failed" #endif +#if !__has_builtin (__add_rvalue_reference) +# error "__has_builtin (__add_rvalue_reference) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Wed Feb 28 19:26: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: 86548 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2C5B385802F for ; Wed, 28 Feb 2024 19:43:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2C5B385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149439; bh=mhyIzL4Sj+mEvMzs7UihcDPW8bBe/aUpC3W8N0ZatRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oCsSHFW3Mz5BT2lpXC75IfaWe/C/vXxlx9yZ97Cv1OTKJi+63zTa2DyNEQhLaV/Yk kvgqx/W3cd5J0/vo/A1yYW5GuQX9Dd+yWqj0yXvK5xLcGN0+96zecn+IS3212hKtD7 6lYi5ifmTyxUZfIYiTprKFJzAqadg0+QqRXKJCv8= 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 02ECB3858D39; Wed, 28 Feb 2024 19:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02ECB3858D39 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 02ECB3858D39 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=1709148738; cv=none; b=uUy55jaXO1hhbsrZDmVW6563c08ewOziDe6MyhPKsAb2/92/sr1iKOod8lg+zidwW6fbWjmwQmjx2mQraW6sDXNIlnyol0QG7D/Ob5bgAIbkg/48n8JqxZI0WFEDupG0eBjxYeN0KA8b0Abp2V+C1IZH3fbNanwOCUEZ4HltKkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148738; c=relaxed/simple; bh=GR4C/VikleajHIGf9ST8I1Du5JpbKOE8dwSz6LX1G14=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qmNbrFY6OvECnYHPr4P9PxpgJToprLLxP4WzyeTPxyGdlJ2w2+L/84FUh6c/WbYeofuahVQ3mqxmkXVLM52BIDrJ/PQoX1F5q1lXC90mJ9gAfQJP73hWkLwTSCWY7d8ADH1c052vZcaMb9uKRb8bgagruk/tokASzmhuB9HK1ZI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSL7X011810; Wed, 28 Feb 2024 19:32:06 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wjaey0dyp-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:06 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpan020757 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTa015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 18/26] libstdc++: Optimize std::add_rvalue_reference compilation performance Date: Wed, 28 Feb 2024 11:26:23 -0800 Message-ID: <20240228192843.188979-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: LW8xFqKHOIG8yGFbwAoHgA0uSEAyWhOp X-Proofpoint-GUID: LW8xFqKHOIG8yGFbwAoHgA0uSEAyWhOp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 suspectscore=0 mlxlogscore=720 mlxscore=0 spamscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 17bf47d59d3..18a5e4de2d3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1185,6 +1185,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference) + template + struct __add_rvalue_reference_helper + { using type = __add_rvalue_reference(_Tp); }; +#else template struct __add_rvalue_reference_helper { using type = _Tp; }; @@ -1192,6 +1197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct __add_rvalue_reference_helper<_Tp, __void_t<_Tp&&>> { using type = _Tp&&; }; +#endif template using __add_rval_ref_t = typename __add_rvalue_reference_helper<_Tp>::type; @@ -1748,9 +1754,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// add_rvalue_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__add_rvalue_reference) + template + struct add_rvalue_reference + { using type = __add_rvalue_reference(_Tp); }; +#else template struct add_rvalue_reference { using type = __add_rval_ref_t<_Tp>; }; +#endif #if __cplusplus > 201103L /// Alias template for remove_reference From patchwork Wed Feb 28 19:26: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: 86546 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1866238582BE for ; Wed, 28 Feb 2024 19:42:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1866238582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149349; bh=ojQrwrUDSh4TIReeQbQMTeMyDmid3s/o5ImN5+m1U8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X5CDyXRVeiYauMEI5f1wRgeYk9WK/fBnia46FVuIs8gygIqbb1iLPYLuX7VZHoY+x mLsNFA1FhNltxNNvL+iJC/Hdy2M1I6jPn7vEFTjBHKEtATx+q2+s6QqfsI5BmJygG2 OaznU5+vlpwXQkDDtVTtyITZpYMaX3oTtpZJRkiE= 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 579AB385800D; Wed, 28 Feb 2024 19:32:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 579AB385800D 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 579AB385800D 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=1709148727; cv=none; b=yGGYvsurdHA7w0LhdKN8AGLS603EkZN3qwpzOcWWodseK+mvwgp9HsHXvGyONAAnd0vJqKtWlW32g8myFRJgSnDG0Q/ZM4fZNahhWtdjA8XqB26evnBvdKFcce7d7vKNcnn0YKwWTAvG4/skug1xXKGWCqnthv1ju1LspVcAnEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148727; c=relaxed/simple; bh=2IcNCwYFjJS2/+7jFd3egy7vP2hEqpSX6M9lHtv3I2g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DaJw4ACU6Wsl6YEvGT1xjYE0mp7DYh9KnXzM7w3OUtTltcXfFgQZDa+cTDoaaHmVBzczXSJZhSg62O5pzJ/B6Ab368KaHFFjF0XlHWxLjT/Yv3tqBviMh1a3YztfqCWzc8ObXuYyyPkFhj71SdtCsFG7ohsAg6O7kZNLsLlKURo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJI6jf022810; Wed, 28 Feb 2024 19:32:05 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3whxdj4wbc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSq77025231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTb015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 19/26] c++: Implement __decay built-in trait Date: Wed, 28 Feb 2024 11:26:24 -0800 Message-ID: <20240228192843.188979-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pP_KAcF0bDIz15CxYZPmKklZTldijAlb X-Proofpoint-ORIG-GUID: pP_KAcF0bDIz15CxYZPmKklZTldijAlb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 impostorscore=0 priorityscore=1501 mlxlogscore=405 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 19d6f87a9ea..45dc509855a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12801,6 +12801,18 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, return type1; return cp_build_reference_type (type1, /*rval=*/true); + case CPTK_DECAY: + if (TYPE_REF_P (type1)) + type1 = TREE_TYPE (type1); + + if (TREE_CODE (type1) == ARRAY_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, TREE_TYPE (type1), type2, + complain); + else if (TREE_CODE (type1) == FUNCTION_TYPE) + return finish_trait_type (CPTK_ADD_POINTER, type1, type2, complain); + else + return cv_unqualified (type1); + case CPTK_REMOVE_ALL_EXTENTS: return strip_array_types (type1); diff --git a/gcc/testsuite/g++.dg/ext/decay.C b/gcc/testsuite/g++.dg/ext/decay.C new file mode 100644 index 00000000000..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 c2503c5d82b..3aca273aad6 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -11,6 +11,9 @@ #if !__has_builtin (__add_rvalue_reference) # error "__has_builtin (__add_rvalue_reference) failed" #endif +#if !__has_builtin (__decay) +# error "__has_builtin (__decay) failed" +#endif #if !__has_builtin (__builtin_addressof) # error "__has_builtin (__builtin_addressof) failed" #endif From patchwork Wed Feb 28 19:26: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: 86534 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D737D3858417 for ; Wed, 28 Feb 2024 19:36:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D737D3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148978; bh=y8LsNZKy6kMQm1J0qzNqNC8bZqkzX7m2KZgi4+l1wPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=clCN5MYMxoKNoHsl9GpoIqyZZ+Nrtu2D1TkXT37jXtp4oh/YdGjmzmbBdVcbqF0CE ttcIeQK+4A+jUu6U67tVSQaHB3GUSXmzXvs+VGup6q0w4fP09MCz96hZH5ZrLxJO9B lQItVuP4zZ0VdIjenw5Q+NvHheWKQ3lJ559M6JW4= 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 8E7CF38582B4; Wed, 28 Feb 2024 19:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E7CF38582B4 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 8E7CF38582B4 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=1709148550; cv=none; b=w/3Ejz1/uO9oGSCW+VSgjCfJ46ppN7TRo7IGY+Uqiva/dF3xZ1cBxf7Sz562KK/WJMkq7+OX6pS2Bp+YJDnWeTwIbSBUAW2uQSBk+l2UDMJzkeABSktnjvY5Bb749ThMZ2klIvK4lS+7gPJsPQROhN7bQxCxmMmsBV9/0l9JZqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148550; c=relaxed/simple; bh=TjfqqNKnkQNIZBUx0q9VkuYTDidE6SEyaROxlFn1DT8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=exp0hiCiA2we5rgCfhYQEz0iSRUfsqoAMlubVzJabiz7DU9TVo06PAektsb1eSRCwqnNRJ75FrWFUUS//nfreAgcwE/lUVsxoVrn/bFNyZdu+eNhOjY8v7dcuXoQvjPwPOJl7TlJuXVUPIktEsZNV2nvVgzSND2VjUVGl0M60Rk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSh9E001591; Wed, 28 Feb 2024 19:29:05 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h21a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqjR010164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTc015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 20/26] libstdc++: Optimize std::decay compilation performance Date: Wed, 28 Feb 2024 11:26:25 -0800 Message-ID: <20240228192843.188979-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: IEgjlqAN4HTW6wSb8ISDx_C_N_UDP1jD X-Proofpoint-ORIG-GUID: IEgjlqAN4HTW6wSb8ISDx_C_N_UDP1jD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=627 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 18a5e4de2d3..2f4c8dd3b21 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2316,6 +2316,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @cond undocumented +#if _GLIBCXX_USE_BUILTIN_TRAIT(__decay) + template + struct decay + { using type = __decay(_Tp); }; +#else // Decay trait for arrays and functions, used for perfect forwarding // in make_pair, make_tuple, etc. template @@ -2347,6 +2352,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct decay<_Tp&&> { using type = typename __decay_selector<_Tp>::type; }; +#endif /// @cond undocumented From patchwork Wed Feb 28 19:26: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: 86527 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 106AF38582B2 for ; Wed, 28 Feb 2024 19:30:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 106AF38582B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148633; bh=KXfHU6FbC22eYHezJGmFUEjgXJtyqXcEcFUk8XWNhKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=POfGUid69Y5qd6EUWskOjN4M9EoVdcSxRqtW1Gp/1Y9tFpK1f3jqd66CRrpLlC45E KdOwx7H9nb81dK6cSdXagv2cZ8hzetoh4szPSBAmOqTppNorIhdtFa94+Ib7RrTAJF CALUqHLIVtqSrm+/LSMuSRRPGRc2Cv2gEZQ3ohgg= 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 8197838582A6; Wed, 28 Feb 2024 19:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8197838582A6 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 8197838582A6 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=1709148545; cv=none; b=Jj9EBuXQ+csXbcWHRAKtB0G1DGzFaL8qT63HbgbnBn9Y8MOWv8Fkj/H/NcVmuC+Agt1WigCVUeCuNV4lWWiJBK/IDyxu+M6AfjvVJfCvFpXJ3SMEfvDODbShnOH3qA4mN4c/mck51qUUszHWaNRnwHpFAx7loFZD/jDXT1/UPDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148545; c=relaxed/simple; bh=ceIeq6Gr176hvlzee+egwHkScdc3ll7rPLnYRkqL4lU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=j3L6Q4jCUC07H4DxdWW2OdC8NNDyh0i4+34IFSgZry2HERcM93vCsrMCa8pcvvwdTj/NoejSOksJwjtsaKjJDIeIiP1JAiue3SC5Mh75e6Fs3WF0VlyBu+EWBcxVqhMn+kwKSl+UJzLTeTboG7dcyYVXuR63/4htLSituMF+gwE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJNdFt022099; Wed, 28 Feb 2024 19:29:01 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj9n6h20m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqd2032341 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTd015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 21/26] c++: Implement __rank built-in trait Date: Wed, 28 Feb 2024 11:26:26 -0800 Message-ID: <20240228192843.188979-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 3BcYfmgoqZMjFXKRMkU_9xM0BIHW5-X0 X-Proofpoint-ORIG-GUID: 3BcYfmgoqZMjFXKRMkU_9xM0BIHW5-X0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=909 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This patch implements built-in trait for std::rank. gcc/cp/ChangeLog: * cp-trait.def: Define __rank. * constraint.cc (diagnose_trait_expr): Handle CPTK_RANK. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __rank. * g++.dg/ext/rank.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 23 ++++++++++++++++++++--- gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/rank.C | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/rank.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 000df847342..23ea66d9c12 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3870,6 +3870,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; + case CPTK_RANK: + inform (loc, " %qT cannot yield a rank", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2d1cb7c227c..85056c8140b 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -99,6 +99,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) +DEFTRAIT_EXPR (RANK, "__rank", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_ALL_EXTENTS, "__remove_all_extents", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 45dc509855a..7242db75248 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12550,6 +12550,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_DEDUCIBLE: return type_targs_deducible_from (type1, type2); + /* __rank is handled in finish_trait_expr. */ + case CPTK_RANK: + #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" @@ -12622,7 +12625,10 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) if (processing_template_decl) { tree trait_expr = make_node (TRAIT_EXPR); - TREE_TYPE (trait_expr) = boolean_type_node; + if (kind == CPTK_RANK) + TREE_TYPE (trait_expr) = size_type_node; + else + TREE_TYPE (trait_expr) = boolean_type_node; TRAIT_EXPR_TYPE1 (trait_expr) = type1; TRAIT_EXPR_TYPE2 (trait_expr) = type2; TRAIT_EXPR_KIND (trait_expr) = kind; @@ -12714,6 +12720,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: + case CPTK_RANK: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12745,8 +12752,18 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) gcc_unreachable (); } - tree val = (trait_expr_value (kind, type1, type2) - ? boolean_true_node : boolean_false_node); + tree val; + if (kind == CPTK_RANK) + { + size_t rank = 0; + for (; TREE_CODE (type1) == ARRAY_TYPE; type1 = TREE_TYPE (type1)) + ++rank; + val = build_int_cst (size_type_node, rank); + } + else + val = (trait_expr_value (kind, type1, type2) + ? boolean_true_node : boolean_false_node); + return maybe_wrap_with_location (val, loc); } diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3aca273aad6..7f7b27f7aa7 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -179,6 +179,9 @@ #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif +#if !__has_builtin (__rank) +# error "__has_builtin (__rank) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/rank.C b/gcc/testsuite/g++.dg/ext/rank.C new file mode 100644 index 00000000000..28894184387 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/rank.C @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } + +#include + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__rank(int) == 0); +SA(__rank(int[2]) == 1); +SA(__rank(int[][4]) == 2); +SA(__rank(int[2][2][4][4][6][6]) == 6); +SA(__rank(ClassType) == 0); +SA(__rank(ClassType[2]) == 1); +SA(__rank(ClassType[][4]) == 2); +SA(__rank(ClassType[2][2][4][4][6][6]) == 6); + +template void f(T) = delete; +void f(size_t); + +template +void g() { f(__rank(T)); } + +template void g(); From patchwork Wed Feb 28 19:26: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: 86540 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E10A38582A3 for ; Wed, 28 Feb 2024 19:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E10A38582A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149140; bh=lgq21uAVEPa2C3JIU6RomScvjjiMeucDEYgXRa1a1pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QIjxfnIZdLRt8YIeQzRyI4ZV3/1Ds1GtKmPK+DJgu7E4n2EWtnzl0krMtoTUVrsYT xyleBdpGjSeMMWlh+Xlc5+zr9VeOrjRGQt1xOT9y/tnNh1vjV7mFP/3/f5HYXHyUWG AWRf6UcNFKb7xMumOWUn7Uw7xUc7yhC6RKH9zpjQ= 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 812AD38582A2; Wed, 28 Feb 2024 19:32:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 812AD38582A2 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 812AD38582A2 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=1709148729; cv=none; b=Yqo6gDykT9/a9+PjR3HcxwKsr9pUVNVdPCLsXUU2042/04w7YOn5BoGYvl54AuyNm69re2c6nQzL9Nh2I8Io/hXjK1teMwzl+myNjU3ARXSpsk0LnpVQFB2LYzHcUt999OGWaAtsSnQy2FV7VvalTR30ciB7jQGOfzVERemnAD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148729; c=relaxed/simple; bh=gXCmRB8005/Ugz7Z3lirnPY6Ia6StyAIz2HP/NLttjM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xZLky4szbRqsZccuYwIfpHNW1Gl/3rFWEOrvTKcX5yujiVqvWjcASPumBLlWlwJmM8mZrFkoq5eD22BjQs+LFWEr0WcO1+4laZ7LqPsf1iyZlCQ5w5Nk5ZS9lBiDs/UdK5YwB2Ix4L6bx/Zn7sRjIK7WdDv3YR4QI6KYQsrMqOM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJS9or021030; Wed, 28 Feb 2024 19:32:06 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wja2y8p4m-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqgH018997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTe015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 22/26] libstdc++: Optimize std::rank compilation performance Date: Wed, 28 Feb 2024 11:26:27 -0800 Message-ID: <20240228192843.188979-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: o2LjdjdIHgjtpQglGMp-o4V7kPJZ1ioQ X-Proofpoint-GUID: o2LjdjdIHgjtpQglGMp-o4V7kPJZ1ioQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 malwarescore=0 mlxlogscore=782 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org This patch optimizes the compilation performance of std::rank by dispatching to the new __rank built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __rank built-in trait. (rank_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2f4c8dd3b21..1577042a5b8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1473,6 +1473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// rank +#if _GLIBCXX_USE_BUILTIN_TRAIT(__rank) + template + struct rank + : public integral_constant { }; +#else template struct rank : public integral_constant { }; @@ -1484,6 +1489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct rank<_Tp[]> : public integral_constant::value> { }; +#endif /// extent template @@ -3579,12 +3585,17 @@ template template inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__rank) +template + inline constexpr size_t rank_v = __rank(_Tp); +#else template inline constexpr size_t rank_v = 0; template inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>; template inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>; +#endif template inline constexpr size_t extent_v = 0; From patchwork Wed Feb 28 19:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 86551 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53DA73858288 for ; Wed, 28 Feb 2024 19:45:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53DA73858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149545; bh=SCyVl6CzuGlTr05a3akgmNFWytyOyJCddWqTC9s4CP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=rHPoVA6B9LLTu2QypYQfmKUAB6cYX4ILYiRhCeWedr+wH+VpVzEJQWiPg1d7j6Gk8 5pnUZ9bscE/xylR767DHitB6nr3Zs65o0hh0poPUukfEjYbW2bOjDedW4AimSb9KJT XFYKgLmIqvUxecFD6fiV2LklhuS8ghSpJRPfNAVw= 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 D72553858C62; Wed, 28 Feb 2024 19:32:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D72553858C62 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 D72553858C62 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=1709148738; cv=none; b=TQMf8QtXC75eeRRO7A5JuzPKIX3cQ3uueQYDRVp9KSjyMxXOUax5raitzYijdzS+zFMTxU0HzM9zH0d0R1uGnsJOnNGErUmm1mdOWlgS/4EHB+fUa/+tFazBom+j0oK153GmLaK6rGdtRVLwKLozaA0+ERuq88IrogfOKTogMs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148738; c=relaxed/simple; bh=njAAkyIWUNUicwQ+G7NB4kAg9LMjAP/kky9UuTKnWs4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=g6/zy6kEjQ8okmxlTVA+oD55CH9YEMCvRAChrYC5Vge6ypbTOBS33w+naxKnA6+KxKkXLMXkJhRgHINWPrCz+fJok8x5moizODhEMdcsvH7AObwMaEwqdMtNd1lGKt3f9DD8nYHX/BJv58PjxQe1eXaq59UEfeJv32B7ZlrqW2M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJTbrI009119; Wed, 28 Feb 2024 19:32: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 3wj9qqgxsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqKT018998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTf015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 23/26] c++: Implement __is_invocable built-in trait Date: Wed, 28 Feb 2024 11:26:28 -0800 Message-ID: <20240228192843.188979-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: qb3MdB4rTL6wTooBZ_qP1ii4sllCrRX5 X-Proofpoint-ORIG-GUID: qb3MdB4rTL6wTooBZ_qP1ii4sllCrRX5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 mlxlogscore=999 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 | 132 +++++++++ gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_invocable1.C | 349 +++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_invocable2.C | 139 +++++++++ gcc/testsuite/g++.dg/ext/is_invocable3.C | 51 ++++ gcc/testsuite/g++.dg/ext/is_invocable4.C | 33 +++ 10 files changed, 720 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable1.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable2.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable3.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable4.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 23ea66d9c12..c87b126fdb1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3791,6 +3791,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_INVOCABLE: + if (!t2) + inform (loc, " %qT is not invocable", t1); + else + inform (loc, " %qT is not invocable by %qE", t1, t2); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 85056c8140b..6cb2b55f4ea 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -75,6 +75,7 @@ DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_INVOCABLE, "__is_invocable", -1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 334c11396c2..261d3a71faa 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7334,6 +7334,8 @@ extern tree get_copy_assign (tree); extern tree get_default_ctor (tree); extern tree get_dtor (tree, tsubst_flags_t); extern tree build_stub_object (tree); +extern tree build_invoke (tree, const_tree, + tsubst_flags_t); extern tree strip_inheriting_ctors (tree); extern tree inherited_ctor_binfo (tree); extern bool base_ctor_omit_inherited_parms (tree); diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 98c10e6a8b5..953f1bed6fc 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -1928,6 +1928,138 @@ build_trait_object (tree type) return build_stub_object (type); } +/* [func.require] Build an expression of INVOKE(FN_TYPE, ARG_TYPES...). If the + given is not invocable, returns error_mark_node. */ + +tree +build_invoke (tree fn_type, const_tree arg_types, tsubst_flags_t complain) +{ + if (fn_type == error_mark_node || arg_types == error_mark_node) + return error_mark_node; + + gcc_assert (TYPE_P (fn_type)); + gcc_assert (TREE_CODE (arg_types) == TREE_VEC); + + /* Access check is required to determine if the given is invocable. */ + deferring_access_check_sentinel acs (dk_no_deferred); + + /* INVOKE is an unevaluated context. */ + cp_unevaluated cp_uneval_guard; + + bool is_ptrdatamem; + bool is_ptrmemfunc; + if (TREE_CODE (fn_type) == REFERENCE_TYPE) + { + tree deref_fn_type = TREE_TYPE (fn_type); + is_ptrdatamem = TYPE_PTRDATAMEM_P (deref_fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (deref_fn_type); + + /* Dereference fn_type if it is a pointer to member. */ + if (is_ptrdatamem || is_ptrmemfunc) + fn_type = deref_fn_type; + } + else + { + is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type); + } + + if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1) + /* Only a pointer to data member with one argument is invocable. */ + return error_mark_node; + + if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0) + /* A pointer to member function with no arguments is not invocable. */ + return error_mark_node; + + /* Construct an expression of a pointer to member. */ + tree ptrmem_expr; + if (is_ptrdatamem || is_ptrmemfunc) + { + tree datum_type = TREE_VEC_ELT (arg_types, 0); + + /* datum must be a class type or a reference/pointer to a class type. */ + if (TYPE_REF_P (datum_type) || POINTER_TYPE_P (datum_type)) + { + if (!CLASS_TYPE_P (TREE_TYPE (datum_type))) + return error_mark_node; + } + else if (!CLASS_TYPE_P (datum_type)) + return error_mark_node; + + bool is_refwrap = false; + if (CLASS_TYPE_P (datum_type)) + { + /* 1.2 & 1.5: Handle std::reference_wrapper. */ + tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (datum_type)); + if (decl_in_std_namespace_p (datum_decl)) + { + const_tree name = DECL_NAME (datum_decl); + if (name && (id_equal (name, "reference_wrapper"))) + { + /* Retrieve T from std::reference_wrapper, + i.e., decltype(datum.get()). */ + datum_type = TREE_VEC_ELT (TYPE_TI_ARGS (datum_type), 0); + is_refwrap = true; + } + } + } + + tree datum_expr = build_trait_object (datum_type); + tree fn_expr = build_trait_object (fn_type); + ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, complain); + + if (error_operand_p (ptrmem_expr) && !is_refwrap) + { + tree ptrmem_class_type = TYPE_PTRMEM_CLASS_TYPE (fn_type); + const bool ptrmem_is_base_of_datum = + (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))); + + if (!ptrmem_is_base_of_datum) + { + /* 1.3 & 1.6: Try to dereference datum_expr. */ + datum_expr = build_x_indirect_ref (UNKNOWN_LOCATION, datum_expr, + RO_UNARY_STAR, NULL_TREE, + complain); + /* Rebuild ptrmem_expr. */ + ptrmem_expr = build_m_component_ref (datum_expr, fn_expr, + complain); + } + } + /* 1.1 & 1.4: Otherwise. */ + + if (error_operand_p (ptrmem_expr)) + return error_mark_node; + + if (is_ptrdatamem) + return ptrmem_expr; + } + + /* Construct expressions for arguments to INVOKE. For a pointer to member + function, the first argument, which is the object, is not arguments to + the function. */ + releasing_vec args; + for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i) + { + tree arg_type = TREE_VEC_ELT (arg_types, i); + tree arg = build_trait_object (arg_type); + vec_safe_push (args, arg); + } + + tree invoke_expr; + if (is_ptrmemfunc) + invoke_expr = build_offset_ref_call_from_tree (ptrmem_expr, &args, + complain); + else /* 1.7. */ + invoke_expr = finish_call_expr (build_trait_object (fn_type), &args, false, + false, complain); + return invoke_expr; +} + /* Determine which function will be called when looking up NAME in TYPE, called with a single ARGTYPE argument, or no argument if ARGTYPE is null. FLAGS and COMPLAIN are as for build_new_method_call. diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7242db75248..149c0631d62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12467,6 +12467,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_INVOCABLE: + return !error_operand_p (build_invoke (type1, type2, tf_none)); + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12682,6 +12685,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CONVERTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 7f7b27f7aa7..d2a7ebdf25c 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -104,6 +104,9 @@ #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif +#if !__has_builtin (__is_invocable) +# error "__has_builtin (__is_invocable) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_invocable1.C b/gcc/testsuite/g++.dg/ext/is_invocable1.C new file mode 100644 index 00000000000..d21ae1d1958 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable1.C @@ -0,0 +1,349 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type_v0 = void(*)(); + +SA( __is_invocable( func_type_v0 ) ); +SA( ! __is_invocable( func_type_v0, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( func_type_i0 ) ); +SA( ! __is_invocable( func_type_i0, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( func_type_l0 ) ); +SA( ! __is_invocable( func_type_l0(int) ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( func_type_ii ) ); +SA( __is_invocable( func_type_ii, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( func_type_il ) ); +SA( ! __is_invocable( func_type_il, int ) ); +SA( __is_invocable( func_type_il, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( func_type_ir ) ); +SA( ! __is_invocable( func_type_ir, int& ) ); +SA( __is_invocable( func_type_ir, int ) ); +SA( __is_invocable( func_type_ir, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( mem_type_i ) ); +SA( ! __is_invocable( mem_type_i, int ) ); +SA( ! __is_invocable( mem_type_i, int* ) ); +SA( ! __is_invocable( mem_type_i, int& ) ); +SA( ! __is_invocable( mem_type_i, int&& ) ); +SA( __is_invocable( mem_type_i, A ) ); +SA( __is_invocable( mem_type_i, A* ) ); +SA( __is_invocable( mem_type_i, A& ) ); +SA( __is_invocable( mem_type_i, A&& ) ); +SA( __is_invocable( mem_type_i, const A& ) ); +SA( ! __is_invocable( mem_type_i, A&, int ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( memfun_type_i ) ); +SA( ! __is_invocable( memfun_type_i, int ) ); +SA( ! __is_invocable( memfun_type_i, int* ) ); +SA( ! __is_invocable( memfun_type_i, int& ) ); +SA( ! __is_invocable( memfun_type_i, int&& ) ); +SA( __is_invocable( memfun_type_i, A ) ); +SA( __is_invocable( memfun_type_i, A* ) ); +SA( __is_invocable( memfun_type_i, A& ) ); +SA( __is_invocable( memfun_type_i, A&& ) ); +SA( ! __is_invocable( memfun_type_i, const A& ) ); +SA( ! __is_invocable( memfun_type_i, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( memfun_type_ic ) ); +SA( ! __is_invocable( memfun_type_ic, int ) ); +SA( ! __is_invocable( memfun_type_ic, int& ) ); +SA( __is_invocable( memfun_type_ic, A& ) ); +SA( __is_invocable( memfun_type_ic, A* ) ); +SA( ! __is_invocable( memfun_type_ic, A&, int ) ); +SA( ! __is_invocable( memfun_type_ic, A*, int& ) ); +SA( __is_invocable( memfun_type_ic, const A& ) ); +SA( __is_invocable( memfun_type_ic, const A* ) ); +SA( ! __is_invocable( memfun_type_ic, const A&, int& ) ); +SA( ! __is_invocable( memfun_type_ic, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( memfun_type_iic ) ); +SA( ! __is_invocable( memfun_type_iic, int ) ); +SA( ! __is_invocable( memfun_type_iic, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A&, int ) ); +SA( __is_invocable( memfun_type_iic, A&, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A*, int ) ); +SA( __is_invocable( memfun_type_iic, A*, int& ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int&, int ) ); +SA( __is_invocable( memfun_type_iic, const A&, int& ) ); +SA( __is_invocable( memfun_type_iic, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( B ) ); +SA( __is_invocable( B& ) ); +SA( __is_invocable( B&& ) ); +SA( ! __is_invocable( B* ) ); +SA( __is_invocable( CB ) ); +SA( __is_invocable( CB& ) ); +SA( ! __is_invocable( CB* ) ); + +SA( __is_invocable( B, int ) ); +SA( __is_invocable( B&, int ) ); +SA( __is_invocable( B&&, int ) ); +SA( ! __is_invocable( B*, int ) ); +SA( ! __is_invocable( CB, int ) ); +SA( ! __is_invocable( CB&, int ) ); +SA( ! __is_invocable( CB*, int ) ); + +SA( ! __is_invocable( B, int, int ) ); +SA( ! __is_invocable( B&, int, int ) ); +SA( ! __is_invocable( B&&, int, int ) ); +SA( ! __is_invocable( B*, int, int ) ); +SA( ! __is_invocable( CB, int, int ) ); +SA( ! __is_invocable( CB&, int, int ) ); +SA( ! __is_invocable( CB*, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( C ) ); +SA( ! __is_invocable( C& ) ); +SA( ! __is_invocable( C&& ) ); +SA( ! __is_invocable( C* ) ); +SA( ! __is_invocable( CC ) ); +SA( ! __is_invocable( CC& ) ); +SA( ! __is_invocable( CC* ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( D ) ); + +struct E { void v(); }; +using CE = const E; + +SA( ! __is_invocable( E ) ); +SA( ! __is_invocable( void (E::*)() ) ); +SA( __is_invocable( void (E::*)(), E ) ); +SA( __is_invocable( void (E::*)(), E* ) ); +SA( ! __is_invocable( void (E::*)(), CE ) ); + +struct F : E {}; +using CF = const F; + +SA( ! __is_invocable( F ) ); +SA( __is_invocable( void (E::*)(), F ) ); +SA( __is_invocable( void (E::*)(), F* ) ); +SA( ! __is_invocable( void (E::*)(), CF ) ); + +struct G { E operator*(); }; +using CG = const G; + +SA( ! __is_invocable( G ) ); +SA( __is_invocable( void (E::*)(), G ) ); +SA( ! __is_invocable( void (E::*)(), G* ) ); +SA( ! __is_invocable( void (E::*)(), CG ) ); + +struct H { E& operator*(); }; +using CH = const H; + +SA( ! __is_invocable( H ) ); +SA( __is_invocable( void (E::*)(), H ) ); +SA( ! __is_invocable( void (E::*)(), H* ) ); +SA( ! __is_invocable( void (E::*)(), CH ) ); + +struct I { E&& operator*(); }; +using CI = const I; + +SA( ! __is_invocable( I ) ); +SA( __is_invocable( void (E::*)(), I ) ); +SA( ! __is_invocable( void (E::*)(), I* ) ); +SA( ! __is_invocable( void (E::*)(), CI ) ); + +struct K { E* operator*(); }; +using CK = const K; + +SA( ! __is_invocable( K ) ); +SA( ! __is_invocable( void (E::*)(), K ) ); +SA( ! __is_invocable( void (E::*)(), K* ) ); +SA( ! __is_invocable( void (E::*)(), CK ) ); + +struct L { CE operator*(); }; +using CL = const L; + +SA( ! __is_invocable( L ) ); +SA( ! __is_invocable( void (E::*)(), L ) ); +SA( ! __is_invocable( void (E::*)(), L* ) ); +SA( ! __is_invocable( void (E::*)(), CL ) ); + +struct M { + int i; +private: + long l; +}; +using CM = const M; + +SA( ! __is_invocable( M ) ); +SA( ! __is_invocable( M& ) ); +SA( ! __is_invocable( M&& ) ); +SA( ! __is_invocable( M* ) ); +SA( ! __is_invocable( CM ) ); +SA( ! __is_invocable( CM& ) ); +SA( ! __is_invocable( CM* ) ); + +SA( ! __is_invocable( int M::* ) ); +SA( __is_invocable( int M::*, M ) ); +SA( __is_invocable( int M::*, M& ) ); +SA( __is_invocable( int M::*, M&& ) ); +SA( __is_invocable( int M::*, M* ) ); +SA( __is_invocable( int M::*, CM ) ); +SA( __is_invocable( int M::*, CM& ) ); +SA( __is_invocable( int M::*, CM* ) ); +SA( ! __is_invocable( int M::*, int ) ); + +SA( ! __is_invocable( int CM::* ) ); +SA( __is_invocable( int CM::*, M ) ); +SA( __is_invocable( int CM::*, M& ) ); +SA( __is_invocable( int CM::*, M&& ) ); +SA( __is_invocable( int CM::*, M* ) ); +SA( __is_invocable( int CM::*, CM ) ); +SA( __is_invocable( int CM::*, CM& ) ); +SA( __is_invocable( int CM::*, CM* ) ); +SA( ! __is_invocable( int CM::*, int ) ); + +SA( ! __is_invocable( long M::* ) ); +SA( __is_invocable( long M::*, M ) ); +SA( __is_invocable( long M::*, M& ) ); +SA( __is_invocable( long M::*, M&& ) ); +SA( __is_invocable( long M::*, M* ) ); +SA( __is_invocable( long M::*, CM ) ); +SA( __is_invocable( long M::*, CM& ) ); +SA( __is_invocable( long M::*, CM* ) ); +SA( ! __is_invocable( long M::*, long ) ); + +SA( ! __is_invocable( long CM::* ) ); +SA( __is_invocable( long CM::*, M ) ); +SA( __is_invocable( long CM::*, M& ) ); +SA( __is_invocable( long CM::*, M&& ) ); +SA( __is_invocable( long CM::*, M* ) ); +SA( __is_invocable( long CM::*, CM ) ); +SA( __is_invocable( long CM::*, CM& ) ); +SA( __is_invocable( long CM::*, CM* ) ); +SA( ! __is_invocable( long CM::*, long ) ); + +SA( ! __is_invocable( short M::* ) ); +SA( __is_invocable( short M::*, M ) ); +SA( __is_invocable( short M::*, M& ) ); +SA( __is_invocable( short M::*, M&& ) ); +SA( __is_invocable( short M::*, M* ) ); +SA( __is_invocable( short M::*, CM ) ); +SA( __is_invocable( short M::*, CM& ) ); +SA( __is_invocable( short M::*, CM* ) ); +SA( ! __is_invocable( short M::*, short ) ); + +SA( ! __is_invocable( short CM::* ) ); +SA( __is_invocable( short CM::*, M ) ); +SA( __is_invocable( short CM::*, M& ) ); +SA( __is_invocable( short CM::*, M&& ) ); +SA( __is_invocable( short CM::*, M* ) ); +SA( __is_invocable( short CM::*, CM ) ); +SA( __is_invocable( short CM::*, CM& ) ); +SA( __is_invocable( short CM::*, CM* ) ); +SA( ! __is_invocable( short CM::*, short ) ); + +struct N { M operator*(); }; +SA( __is_invocable( int M::*, N ) ); +SA( ! __is_invocable( int M::*, N* ) ); + +struct O { M& operator*(); }; +SA( __is_invocable( int M::*, O ) ); +SA( ! __is_invocable( int M::*, O* ) ); + +struct P { M&& operator*(); }; +SA( __is_invocable( int M::*, P ) ); +SA( ! __is_invocable( int M::*, P* ) ); + +struct Q { M* operator*(); }; +SA( ! __is_invocable( int M::*, Q ) ); +SA( ! __is_invocable( int M::*, Q* ) ); + +struct R { void operator()(int = 0); }; + +SA( __is_invocable( R ) ); +SA( __is_invocable( R, int ) ); +SA( ! __is_invocable( R, int, int ) ); + +struct S { void operator()(int, ...); }; + +SA( ! __is_invocable( S ) ); +SA( __is_invocable( S, int ) ); +SA( __is_invocable( S, int, int ) ); +SA( __is_invocable( S, int, int, int ) ); + +void fn1() {} + +SA( __is_invocable( decltype(fn1) ) ); + +void fn2(int arr[10]); + +SA( __is_invocable( decltype(fn2), int[10] ) ); +SA( __is_invocable( decltype(fn2), int(&)[10] ) ); +SA( __is_invocable( decltype(fn2), int(&&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&&)[10] ) ); +SA( __is_invocable( decltype(fn2), int[] ) ); + +auto lambda = []() {}; + +SA( __is_invocable( decltype(lambda) ) ); + +template +struct can_invoke { + static constexpr bool value = __is_invocable( Func, Args... ); +}; + +SA( can_invoke::value ); + +struct T { + void func() const {} + int data; +}; + +SA( __is_invocable( decltype(&T::func)&, T& ) ); +SA( __is_invocable( decltype(&T::data)&, T& ) ); + +struct U { }; +struct V : U { U& operator*() = delete; }; +SA( __is_invocable( int U::*, V ) ); + +struct W : private U { U& operator*(); }; +SA( ! __is_invocable( int U::*, W ) ); + +struct X { int m; }; +struct Y { X& operator*(); }; +struct Z : Y { }; +SA( __is_invocable(int X::*, Z) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable2.C b/gcc/testsuite/g++.dg/ext/is_invocable2.C new file mode 100644 index 00000000000..a68aefd3e13 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable2.C @@ -0,0 +1,139 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle std::reference_wrapper correctly. + +#include + +#define SA(X) static_assert((X),#X) + +using std::reference_wrapper; + +using func_type_v0 = void(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); +SA( ! __is_invocable( reference_wrapper, const A& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( ! __is_invocable( reference_wrapper, A*, int& ) ); +SA( __is_invocable( reference_wrapper, const A& ) ); +SA( __is_invocable( reference_wrapper, const A* ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( __is_invocable( reference_wrapper, A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, A*, int ) ); +SA( __is_invocable( reference_wrapper, A*, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int&, int ) ); +SA( __is_invocable( reference_wrapper, const A&, int& ) ); +SA( __is_invocable( reference_wrapper, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper&& ) ); +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper&, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper* ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper* ) ); + +std::function fn = []() {}; +auto refwrap = std::ref(fn); + +SA( __is_invocable( decltype(fn) ) ); +SA( __is_invocable( decltype(refwrap) ) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable3.C b/gcc/testsuite/g++.dg/ext/is_invocable3.C new file mode 100644 index 00000000000..8699b0a53ca --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable3.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle incomplete class correctly. + +#define SA(X) static_assert((X),#X) + +struct Incomplete; + +SA( ! __is_invocable( Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int, Incomplete, int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int, Incomplete ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete() ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int), int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int, int), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete(), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int(Incomplete), Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), int, Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( __is_invocable( int(Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(Incomplete&&), Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&&), int, Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&&), const Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&&), int, const Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, const Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int Incomplete::*, const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( ! __is_invocable( void (Incomplete::*)(long&), const Incomplete*, long& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( void (Incomplete::*)(long&) const, Incomplete*, long& ) ); // { dg-bogus "incomplete type" } + +template +struct Holder { T t; }; + +SA( __is_invocable( int(Holder&), Holder& ) ); // { dg-bogus "incomplete type" } + +// Define Incomplete, which is now not incomplete. +struct Incomplete { void operator()(); }; + +SA( __is_invocable( Incomplete ) ); // { dg-bogus "incomplete type" } diff --git a/gcc/testsuite/g++.dg/ext/is_invocable4.C b/gcc/testsuite/g++.dg/ext/is_invocable4.C new file mode 100644 index 00000000000..d1efccf08f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable4.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +#define SA(X) static_assert((X),#X) + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_invocable +: public bool_constant<__is_invocable(_Fn, _ArgTypes...)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_invocable_v = __is_invocable(_Fn, _ArgTypes...); +#endif + +class Private +{ + void operator()() const + { + SA( ! is_invocable::value ); +#if __cpp_variable_templates + SA( ! is_invocable_v ); +#endif + } +}; + +SA( ! is_invocable::value ); +#if __cpp_variable_templates +SA( ! is_invocable_v ); +#endif From patchwork Wed Feb 28 19:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 86547 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B9973858000 for ; Wed, 28 Feb 2024 19:43:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B9973858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149402; bh=RowP20RdImmrDFoNCo5/paRHGOcLwoYIvBOx+g7nxgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ZXImTXMEdaSf79L87mtuU1iSdoMIoQWcy//DIhpPiOgQnVwnlS7N5cufFqazVaIuq ox3um4L3BDW9pyybOdhre3o75cYDNmRWkRyx47RUoDejNFvdVSkTFdfKkh45gLRKls XKWxgoErXrVNsJv6M4hZQU6GgZYMzrB5yQJijHEk= 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 5DDFB385800B; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DDFB385800B 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 5DDFB385800B 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=1709148565; cv=none; b=Xy+vJ/vJJBcE5R3Cj9mDaNClfVkGtXmP8ERJYP8bLwBj8BrYNkdtbzQGxOC9NfOQ+JPfEHQ8TEQbTuxf2XDuaOk++Z7eb0V690WGAk/HNbd+M1hbZD/z/sYi9ycVMeUkXBXb/VTru8nZZWEVb05jkko2JoXL0p27NKP2Fd/J1LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148565; c=relaxed/simple; bh=nPDKAFeYABHHUjGYGSckzOI/uBYHKo40Zydn9Zq1knA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TdINC8z4mE2HQXUpIhjLCODRdWjTelsi3TdeY5ICf09PkmYuHNChUbW+lXQuk52z83+Kuq84ewsjZkORtLKsyzt42WRXGwZEhagm8XyhTYJaZJCV6q9xzp1Bsb3YR1U4K4v8Il8vJnUdkO+YVMIQ3ov0RNtQec9Xbq0hbjs5I9w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJQKXZ017047; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wja2y8mtq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqfL019401 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTg015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 24/26] libstdc++: Optimize std::is_invocable compilation performance Date: Wed, 28 Feb 2024 11:26:29 -0800 Message-ID: <20240228192843.188979-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: j9V_Uv--_b1wOi7tQdn15CzZmkSW3RWF X-Proofpoint-GUID: j9V_Uv--_b1wOi7tQdn15CzZmkSW3RWF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 malwarescore=0 mlxlogscore=936 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 1577042a5b8..9af233bcc75 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3235,7 +3235,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 Wed Feb 28 19:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 86529 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26A3E3858024 for ; Wed, 28 Feb 2024 19:32:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26A3E3858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148727; bh=54vhQvY9u89chF+BfVzqqGMOWm35HeE38x6xc0xZHIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=K1ASfYD/b0Ga5/jKwZ/cJbt0ZxVEc5I1p7Z/MxuOwNRBM0Pq3wqicRnfwJb5Bo6qW IvHfQuzLxq5vIsaqz8Es5F8sVJPhaI9mQnDgP4vVFXXWbGthFI5S5NpmPjK923hj/O MYCKP6SQcxnAf3yzQP+mgi9f30mgibs7up5rZOP0= 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 9B8FD385842C; Wed, 28 Feb 2024 19:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B8FD385842C 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 9B8FD385842C 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=1709148545; cv=none; b=cD9XPDyeVif1Fx4pe4qld/1Mnk3BjnKmxBdCKI0s22Wl2eLP0ox+vhFvMNGHtBkp9w5x376BpCLAANEb/tP7szumue6A08K350LP3YFPTfkHnoALzwSslWYzOhN7IBKv+zz0t+XP7UHk1fEC/oJg7czn3xadUP9uR4bqnFm8mls= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148545; c=relaxed/simple; bh=fR5N/yEaZh3DXAV+m49zSFdR2KDSPVlC/3ioevoYGVo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CvSiBDTQi/t2xBzkheK7aKi86mBQ1EeW1l2jN1peWhk7KLgiXjGGzYTZNHlSiUXJ1MaQ3g6MK21jaZUOYUtoz81jSaEd1AZ6GZx21fNthkwZSr98DOFQQyl776VOODaVkA2yzo67sBh67iL3+nuvYzW59loaeiDTQPWmNv1B/6g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJSLAF012810; Wed, 28 Feb 2024 19:29:01 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj80r9yq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSq29032387 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTh015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 25/26] c++: Implement __is_nothrow_invocable built-in trait Date: Wed, 28 Feb 2024 11:26:30 -0800 Message-ID: <20240228192843.188979-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ZpYWMXcRSEzqwEwu1wm01IUa0poh1xuF X-Proofpoint-ORIG-GUID: ZpYWMXcRSEzqwEwu1wm01IUa0poh1xuF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 mlxlogscore=856 mlxscore=0 adultscore=0 spamscore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_nothrow_invocable.C | 62 +++++++++++++++++++ 5 files changed, 76 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 c87b126fdb1..43d4f2102d6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3824,6 +3824,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 6cb2b55f4ea..a9714921e94 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 149c0631d62..dba7b43a109 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12494,6 +12494,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 (type_code1 != FUNCTION_TYPE && type_code1 != REFERENCE_TYPE @@ -12689,6 +12692,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_NOTHROW_INVOCABLE: case CPTK_IS_TRIVIALLY_ASSIGNABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_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 d2a7ebdf25c..624d3525f27 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,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 Wed Feb 28 19:26:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 86550 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 828793858421 for ; Wed, 28 Feb 2024 19:45:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 828793858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149532; bh=fbQXEZhV+pEH4pI+jov70pRPAIFo2gBWL0kSdx7WUSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WeSnco8/2PHOJf78BYPNQ1Hhtm6pwwvsoq2RXU8JG4fxC6FhHHbcEoVX1icXX6fvr Pv+YsRpjnijFo9MHMkYJUWG42/KWbe64V6ZA9dbc0a/PPIPctAeUeU5l3jbbclb2Db 5OvHpgXTRgqUNiFSF4NEc/IF/UsNBmXLctgJHFkY= 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 77E453858C74; Wed, 28 Feb 2024 19:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77E453858C74 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 77E453858C74 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=1709148748; cv=none; b=kR9pa+uyyBXYkZy37UHskw/wsL1vEvQWt0wZkQ4r9TzodvMV3K06KYea0M59Nq/ZczTtPw85FZ3KG55ZCLE8goQB+JCEPcuMO2qTUu68cYa6J1FebUBq+MaupEwwXGYXnIi8JI0e3Y9IG+I9dWuuvyiKlfgaGcYTg1KrrLdyMEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148748; c=relaxed/simple; bh=NOgdPAKPG+LYKb0ocEqV5BdDVLZa8uXgC8tHCekYLtw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ROn6P2WbA16aqOlnNAFISH6GjvPXXtKJOLk1Cyjn9ZCIyzK4h+LtZNnk5Jdb5TrC9q/Z3TRLWvFnAV+jeFJPjUiorNyT8EeN1nXcitYx9U3lYYrDde+vXE8iM3OqgJRD4+IeFtmZ+DUufdhWeV57t0zzCklHbFmMF8KrofMWTjI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJQKZA017047; Wed, 28 Feb 2024 19:32:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wja2y8p53-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:32:12 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSqlN025232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:52 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTi015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:52 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 26/26] libstdc++: Optimize std::is_nothrow_invocable compilation performance Date: Wed, 28 Feb 2024 11:26:31 -0800 Message-ID: <20240228192843.188979-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lGj-LxwfSfLq2mVOXgAM5vfrbd8MSQGm X-Proofpoint-GUID: lGj-LxwfSfLq2mVOXgAM5vfrbd8MSQGm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 malwarescore=0 mlxlogscore=841 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.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 9af233bcc75..093d85a51a8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3265,8 +3265,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