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: 207979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3564523dyb; Wed, 28 Feb 2024 11:31:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUpIrxegNw8FMEWmDkwgQ3r6O+8aSM5p7dk2s8hq7XstU/IQWTGgDonWGWfC+OE+k/Rze4FP0skLimN8YCODUjGKboehw== X-Google-Smtp-Source: AGHT+IFE5NEn4FiPdFKDBKBgzp+saF/kEEezYOFao0Pp4UWWHii3l322mvx664OxtVAG6ZG9pFgX X-Received: by 2002:ad4:5a4f:0:b0:690:3066:858 with SMTP id ej15-20020ad45a4f000000b0069030660858mr25920qvb.44.1709148666864; Wed, 28 Feb 2024 11:31:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148666; cv=pass; d=google.com; s=arc-20160816; b=jyU5FGHDefESKOj2IiR8Cq4ZeGqHWMr4Vk1umwpt5M0cTRRfycJ1vRGGtqTCLPBEEW TgMTASK5gM43yLfScJFAzFWXaz/7yUKVx41j2wbR7QpENELHvYN5ej8Ud2yINnvNExuo /0cCLVRoxDDxwzWOmBxUgrEV5T/86dHfNRLrQ+s182JQVyhvrgie0jzja0T8JZRwJtPw Ezbp7y1uObUlw05XAE0ZjHlo3kBmVEFF+1mGd9LgUyukN10/usa0FpKnz1EiLeiFkoFe oVkvb2QEV3F40YG78yV8Xi1r8zekkV/S9BuZXwQJud4MFD5MPjEWAhzqyAezbbGkQLp9 MGzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=QzdwplnNRx1VgA2ze/PqqCUx+7t9yXY7z440OlggxyE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=R1TaEA27CWBe4RgYT/XhINLMfMpaJxnvJB7f7erjLSoKagIzXMWkB+BhYBWmTmPgR2 wUvINOliSepEoJys4VX9jrtlrhy2oP0qFQOqQKKtIriu3PrcOqDAoD/7F/hc0iv2KlKW dGuwf+D18giLvQG731AL4dJvB57UNefbvysH3i9hWPM2S0Wj6Fl+BW+98GrInzs1khWv OIrHXgLpV38NYPfi1iDbqT48u8MzhcdLs1VOmWkbj9Xg3LT/ywzifTg19sZIcN/X/ed7 AUFQhGXISoEM+u+eoy+reeFZINnYwUL1Ri8XllzouFThWrwhYUmTx0ek5QnKr/jKxnJ3 zmeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HtT8X6sv; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c6-20020ad45ae6000000b0068fe58389dbsi186292qvh.536.2024.02.28.11.31.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:31:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HtT8X6sv; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79A63385828C for ; Wed, 28 Feb 2024 19:31:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79A63385828C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148666; 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=HtT8X6svlZ0KEWa7a8+6VnSH2LtOSbwOoolCgMyXd8UL3kLvphNe9E11HNEPzLDoV LmF38A4ZHyniKthEnRUzyi/tABC1a2tCFQzF5wiZ7hNcZing3va2kpuM2zntN0yf7u nPFJhrHBvejjsNkNm7paFe0BUandploR8hRJAYGs= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501245075839133 X-GMAIL-MSGID: 1792172272328530034 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: 207988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3566692dyb; Wed, 28 Feb 2024 11:35:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWXA8k94AqOrIlY8ZxBQGHwvU8Z56/xg3pVRqnP1aNjLI3qzsUhJVw0lmBdabfeiJ48qBq3JX1qzTgBKpdFeFTbOdGF2Q== X-Google-Smtp-Source: AGHT+IGTYfSTRmZHn9nIIJhrF0vXXxrkIIM9l45OLKvP0WwtLrq/e9f7QzkTxeuvKeVpQUL46RMg X-Received: by 2002:a25:2:0:b0:dc2:2d0a:4d55 with SMTP id 2-20020a250002000000b00dc22d0a4d55mr146666yba.63.1709148903101; Wed, 28 Feb 2024 11:35:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148903; cv=pass; d=google.com; s=arc-20160816; b=iq7lgxypRaW0l648cjWgEeYg8r4Zpd4l56X3WWhscp5RClhNr6olHoVBX0iQBAYw6I fsPot9gVe9HX4tuUKFoluwBO0lGySh0Re9nJyVUQ2p6DjzJvaoGSFGl9jVD0LbeF68Iz nIy6UGCIE6vXq0oFAQkFPlcPN2zt6d/BoSs2OCj/Zo+ab20x2/ZPgNL/jkC9KvJbsEmc m71GaB6P+C78+NFmwYK/77ICheCBw2bK1LraGMBAo88AYhase+rAdAfRScP58VkdsB6L WJTBf81V/zzpPk2ktV17kkRBQ+sy2nDDRZZoQ3P5fGHAe0w6ssek75Tn1JLdE0i1hKhu K10g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=3U2RMIKqBuZBalWG7iXOQ5jbvnmTSxsGGfC56O4MG5U=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Kkzko1Rn5kVPnvJhEFNIpS1wiLAngBgZgr5UNneHYbz2xpME21CpA2VtGY+i9DMQzd s/u4Qk431NcVyhEDj6q6OVEP117ZIOy5DIoov7Of2D3DD9aN3MmlaLyX357ZePxebhHL kwB/RNb0tIK3MFkcfJ8rZChdffq9tn+Zn9mD5kNCAAIipssFAiMMJTnbGZAqUWHDt1fg Vrz/aatjviNTIbMp6G3bI/f4eU+w8WAqs4sxPs6BKtXfN5lvpunyYKjKLnDVwQwO2/RR TD+G3t5jeLLqjCUqJvaQ7sr5DwR83OO0AEkJw+rkcKRaPI3uFF2OwHl7ND/9MV11NVwh iQsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VVpaZiwF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bj35-20020a05620a192300b00787854dfd76si228347qkb.350.2024.02.28.11.35.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:35:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VVpaZiwF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4DBC3858291 for ; Wed, 28 Feb 2024 19:35:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4DBC3858291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148902; 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=VVpaZiwF8w7NnmpXhRHDL7GNz2YmZJHjs3MblvSP/zjF4V/0O8M4L50IRA5x3L7vJ +st6nSGjrxQwNt5RNa9L7ULX5BAZVzCM8YzrsR9o/SVLBqnJykw4h6ylFtq5aU3oix ss0ukSs3rhAmBuxm7tBvZ6bugmMqT+o9nC0TjHNo= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501873116249185 X-GMAIL-MSGID: 1792172520428470367 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: 208008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3569455dyb; Wed, 28 Feb 2024 11:40:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWO+4WMVSMOjRoZawrrj7g4879DxtOfRx62shrylbw2/cPO40O0Kpyb4LGKZE1Y6jIn4EN8RfJdrrfTBZlZC6SsK1pvrg== X-Google-Smtp-Source: AGHT+IGQ9lw4v+CIJq1YsJpMdYFTFnSzGt19F8gQfbjJTTxZt6RQ0nqwoS3EOPziy2GGd6K6DnNO X-Received: by 2002:a05:622a:64a:b0:42e:6409:695c with SMTP id a10-20020a05622a064a00b0042e6409695cmr17735516qtb.29.1709149250667; Wed, 28 Feb 2024 11:40:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149250; cv=pass; d=google.com; s=arc-20160816; b=wRdXJzDiK3Mc/qasrjFkV7X2I7LTcrDbv9XWmkI5tE7W7kptTRVVrY8gYGbvGyXYhH IsgIqepRd4n+kcsM2ECcawUP2Aoj/xGkLLM5FnFssAw1UMU1xaYNbeOaE9UZ4hyt1NrC p4xrwb05zXN5afDW7V1GYQX9UMw6M4qC46pgGNHEq5WBdpEFd420r/e5SuK2ISy9tUeQ fXA4TYP5caoxASt6r2cHxAh5pdzMaQaGAaPV/YoKAzuWyuQ1n8ZFMB3jD5yibm1ebz6u 19CQiKjehP1nagWaaxtKTsQ0TAdsQq5DLjR/UqjidSlR1yOI9t4V8NCHK+KVmZ0jylOQ 3ZaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=HBScI1zRLDi1AtkU5VDWARmsXMViCe7KgBnxnQ4EvaM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=AcYYnCJjiA0ZpRlXqpgBMwZBm8hMcGTdEuqFkpy6LgBjrn4iCJSJ0uBIeDb7tFc87f 9MPXnM0mDYDXcQl9CTXEV7VOtxFgk2qNjAW8VwdFImuaW1HTJfHezs5zw/lT7stIJJaa g/HD/ETlD2nJeWLv56hmcnGs6GJwYDlR3VqdMuD8z2Rgrt1sJh61ztiik0HhR6nK3j9h RebFx6dPMKkUpCINP03XTFjBeprfJTih1j7YNvCGr7LFt83PP+axXxEQN8k8T1WCjUCQ UvTWxE27+ARmdO7otaXQGgRfYz3qmFiNn22ZX84XTWTO8a4kC/9MYz2S6x4HoNh+A0yY o0rA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2rFcduS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d5-20020ac85345000000b0042eb163e7dcsi125621qto.237.2024.02.28.11.40.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:40:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f2rFcduS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C91C3858436 for ; Wed, 28 Feb 2024 19:40:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C91C3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149250; 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=f2rFcduS/k0ca+/5mdiE2Su42c+/89IIN9vLeFuywZaDGx18py8RORGC2SVbuN3Rd RQsprRRkLYWDQHOUg3CLiTW3t/7XYmCuf+MIKrYG3JVKs0+mCWMc0GmScVW/itlaJK pjr+fXxmxEimctz8NpCTu7dRLR7puRacJ7S2Oaj4= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501990196591959 X-GMAIL-MSGID: 1792172885060010859 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: 208018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3571451dyb; Wed, 28 Feb 2024 11:45:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUYaagR9Ipf2xwP7+47S1oKcOooLkFnBwmrWfP0h2cvoK1yC8MYwnksyTU+vaUZITwGkE8LXq10BiNMwwQFJJfqJycoJw== X-Google-Smtp-Source: AGHT+IFwOqMpc5WObCvoH+TLCr4R+Ehy5pPZJYtNMvzAeifh0XuIJNgkY3Wy1iU+4KM6oAuS5Yhg X-Received: by 2002:a37:e109:0:b0:787:f8c3:dda7 with SMTP id c9-20020a37e109000000b00787f8c3dda7mr54938qkm.24.1709149537105; Wed, 28 Feb 2024 11:45:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149537; cv=pass; d=google.com; s=arc-20160816; b=ui9VSHGFAF6Wx6pNC5nDm5y26bCjeKCGg4MMqWHRPlPeDn0BxLXHoq0t3BO9mNKAKR ATky3wDWtpqzAGrf/j6i2Qd90a9c5oH+VeZqaDg25V6uwYqnauhBKhVAFvHv/eIZBs/m 8WEDOBQ4zvLfeY6OOfVjEUxny62BGJSiZyRYRs/GWDaN4dpBUGf/wqOOlJpQ0k3EGLkF 0qrGlQnwLNo8cWGy5KJQOCxAQSGN/Z4Jpo3Y80LX7a6I6BiBn8x+zCEnGO2aol+zEkZb TemGSFqt0BCmSlnhVW9GvEcasL5sVY6n14OfvJOrz0F5K9HDW+sO11SjQeazvd+hVK9W tP7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=R0Tatz7ePYJcIzsreplYFv8WcbL1iC29nvSKwqOABYI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ix7Y8dDKnv6TXIR3HOpFryMLlZFfZYlR9i+g9xy3V6O8Ap6rvWje27XrvDwR9Bxs3h Tl9PdPI4XsQclHWE1OkhEYjWgXmwSCm41p4JZlD3ZKiAEpO2jIjzrAdeS707gziqMz1d I5e33QKFa9N43X46MWfB59pF4uKheOFlNZXLM5lafRrmZI6P6Sa1oSBqzTXOd03BoEKb rM2rhLhfszZd5HYiF9dEMBIItM9PVdEum7r0QzGHNYqgkORNe7C1T0VzKvmmmMOuOYkV f8tCIEs+Lkh9jYEQD2MoDjGm2NMJYe8dyNuMbrsolzAOsJ2fOhw/p81/23JVQ0CQ0+Q8 6mpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l++SxGkQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id vw11-20020a05620a564b00b0078797f43f04si196421qkn.556.2024.02.28.11.45.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:45:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l++SxGkQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5E9E3858414 for ; Wed, 28 Feb 2024 19:45:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5E9E3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149536; 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=l++SxGkQlUXke29z3qAbao/39viVtmb5gM40pRtIa80jr7aVGRN5qU11ua4GSt7XV lYDZXmU+t+T6X74lhuLG/g2vUFxrQ1Ka8COgTXorYKiE0ejlbz1i40YgA4x5gxqmQo ETYUtd3/QoGbOcFG7/smAweSAL7yTzuy863Y7Brc= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501482996198141 X-GMAIL-MSGID: 1792173184667120813 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: 208000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568729dyb; Wed, 28 Feb 2024 11:39:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUx4U6DzomNEBmQNBzXH+LYlnNwvUo1kqp6JSDcV3VgGnFkrrIr72M0o0jbrJW8vFQ28CF+Mku6TFK2zkeqjBSbquRykw== X-Google-Smtp-Source: AGHT+IFrlUXtRKF44Zka8oRNWCd9wsQW+OSGQZP62N0gVIoxxEwNx5ngXtiWdbmD5lDHZskDO2D/ X-Received: by 2002:a1f:ec83:0:b0:4c8:90e5:6790 with SMTP id k125-20020a1fec83000000b004c890e56790mr687957vkh.5.1709149162637; Wed, 28 Feb 2024 11:39:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149162; cv=pass; d=google.com; s=arc-20160816; b=LsOktsMY5qWGb7hMR1AK+YkiDhMhtdzxPeec1b1/ILfZ9z8EgqtJ9g++tPRxuDxEb0 hmlc8GpAOJkLMDMWQIKw+IBbwAJR5D84YiwIvlJAhLOGy+RyYLGW/1cwJYwQTk+GDGmc ZqEX460XJvqLHbrcdDfSwat8mmDwR/F8ViU0ihd9CBZIW+c4QvPR94CMTthCkA/GIpNb JDeMsQKktZ+GYWBIbR37/XsQ7m+Bpv6rvRkZqx8TOzAMgtH4PGkOM4Z2GcuPppAIQMht uD4oY0eVCf05yVhOLzy/UFO8MeFN687G+ezPNXOplsuEPMsLNwMqQyRZruySTXMuBJrU SLtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=AIftVXz7P9+yYxHYmZBy0i3IOufAxvtBjVtbM2qGcFc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=SWKxaOaTG+AjMC6wp8obLauZCH1r4A4zv4NKb5s31ZJyTyuoxBuCz00A4y/Zv5i2tC 5pLTBPcQzyL5/5p01UmoZZ3xs8PSLQpbgmpqTCUWdL/+DSQ8WwIxbeR1OkRTYtdBoTGu Mrcdz87UejkqzvsKqt8sX9mA4m+b7l4aUzPn3tUmrNUEaW6kQEjvb857qHkZr4eDVmob Wkf01m0l/MoSTx9DORzIpnZirypymW5pwLGlcYYoRij74zYWfsD5q8dySoJXcrIW1Ngz 7radPuDZ9ZX1DexmltxCwQlNkXukmWT4BSZwRADI6vnEMefoc+oygEWJZl35Pr0GETa8 8A7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FpjIZMvj; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w23-20020ac87197000000b0042e64ca9522si130902qto.187.2024.02.28.11.39.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:39:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FpjIZMvj; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 348EB3858422 for ; Wed, 28 Feb 2024 19:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 348EB3858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149160; 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=FpjIZMvjFCrqan1FGe0L7Kf0ySnGIFT6f3hqoJG0SkRf49ipDYu8mIelOq9osvgnt 9OE6hVNdZ5jukjHVPdGwVkrpzfyBQHKm4gfrD++Z+/oBirso+Fjo8zceZsfhYisiIR wGGDImvFPCBM+Y/C+iALEXze3mP/jCv4lv0UOUEw= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501567463493597 X-GMAIL-MSGID: 1792172792535157923 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: 207981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3564625dyb; Wed, 28 Feb 2024 11:31:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVmXFaXmddop26ACj6LgPe5/V+k12pj9zncynESz+03f1a36SoIxWXxgIyIps2jHZUuC8Ofmj0PWnLYgWme07t10gtDg== X-Google-Smtp-Source: AGHT+IFxXRnPjw1l11FjI3LHQQ116U06VmxxZK8qziy+j44RJV+NVp+wcRL0hBMwZp72r9c4LC7e X-Received: by 2002:a1f:db04:0:b0:4c9:75c3:e79b with SMTP id s4-20020a1fdb04000000b004c975c3e79bmr649101vkg.6.1709148675409; Wed, 28 Feb 2024 11:31:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148675; cv=pass; d=google.com; s=arc-20160816; b=B41jYkAC7j6b1zZsbF9KTtoOpZ2WCmtwuIPe15K17HC/g1HWX27X0X4mI7JXViNXhA dM/ligyhSvNHp/Zpxi+sM2LTGUucBsRyp/QC3CM8U2w3CsJKnEAliGac2DienwV0miHt f+CtKjP4fz5NB1I7gkuhoE+AjhBCt1mQI8OCAvBtlcnBshQcMX7fVjgAieCYHVBfXYmP TZQt4IJu+2IVOTGcI/u9iRzBhTdyrwPRMtYVCKc8GsXvW59vMU6rky3rYnfil+m3CUXq Z46QBxk9qL2jT7Fm++pTsVgmu1iNNKb6Xg8V09Rozaf9tMt0L0+/xnoqVmwAPzwI0myy 7BZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=6TOjuO3hQcoYF7+rvKp1Xl3PQK2Pwpro6u0Qv+GbRuI=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=RHAs5hcWFWjOcYfEBquhgdwbnlp4i7K9r3fVkRDF0UH8JMiwdmcHkHu767heCj2sDD 3zBs6MZb3amHNPrDrI0GDFWufbXS6BV0t8cdj7tyinajYFd6hzfBgyW/NPoZsoAa6tl5 Yff/WkihUHf0/lCGkgQTzSioY8thA+kgPZ7nYydwTfeEP2QNPESnJD504dAohj/4yn/Z ntndUwcC4xrQdcozi6z/h668vW3IE7PAvZDg404K5bBFHdeO4JjKqxZW89aVyWtxc+fg XAGw0RgXM/1MNXg+f/02n5yKByd5JxrFnQ7L7ubOwuVXCiIJvV5T0+l8SJuHmJQ2WxyH hyDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aigNw8ia; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j22-20020ac85516000000b0042c075c6f4asi108950qtq.569.2024.02.28.11.31.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:31:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aigNw8ia; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FC01385800E for ; Wed, 28 Feb 2024 19:31:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FC01385800E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148675; 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=aigNw8iaIWfRfTz4UJOIccH3lPUq6nyCePGk11s/CHiMBJrYpIN7iD1dfCjm1/zFb Cz5+JTRhoHMVuAEH4NyyyraNQEZ/pCeFP7ZNErmLxaORjeGU+TkD9/89hfptvpbSIF zdHU1E1LdHZNf3Ywtzs1PanFvO7jURNLmHv7IoZo= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501116397652173 X-GMAIL-MSGID: 1792172281124617776 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: 207983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3565888dyb; Wed, 28 Feb 2024 11:33:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWF2Tie/gzqsXXK9sNfXxG+ay0TALIhjS/8YN2b/RTEnAG7kqVfDHVXzdB05EOslAAokHr6qU8Rbb2w+Tc/k2SXjlBqRQ== X-Google-Smtp-Source: AGHT+IELWe2062HdbKLJxOZrb0np7jXWpwyRUY1IF96uDMzUh2lK2U9BaknmAP3t46FEygGPYLZV X-Received: by 2002:a0c:da86:0:b0:690:18ff:9e70 with SMTP id z6-20020a0cda86000000b0069018ff9e70mr33661qvj.60.1709148811431; Wed, 28 Feb 2024 11:33:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148811; cv=pass; d=google.com; s=arc-20160816; b=z41gXEjcUZU/TWiBm89ntt9XY8jaNzSCyyD9yVLwRki7V/Ppp8BeNRIjtZ4sFblI3Y JveGxIIuOKm73Zyj7HJPMKPIMy43kF9wUMyFhekS7h0/cBpe/7gthzn+T6EVxVFO06qB 16Y7PaGH7Z2jXgieHNw+cHmOBzBtfoVPHGVHQuZ5EMj7wm1XvMcOkPUOSJdMhW1GUu4H gKkrKzM+rYVcOsLNu7xpWOhOVVvYCyCxVTaIK9XugCa/d/vi6gzxZsPA4jHL89iY9sBI i+ow0kXhViSBQFzdVMcKqTvQuvXvHRIqoVQAWgPEwMwkDdPSFCDardz7mCmShaqUIqGb Ealw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=tRJvrRi8eLOmu9rmtjWVTBM9wV6TwmzSiK3xqsnXDtY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Nf6di89km6MZU6OZH/Gc/2a+JIrdnFb9T5IPkZg13d1P7x9B0bXv7jviKrVUBaoK6z es1I51GCGteOOV8fb5Ukn6zCeMdcBNnxQoDH+ds/6xxYTqpLgsSXZoLh1RQx8KDvIxUa LYmh7lyQCE9K5a1W7w3uRBrWQlhg3PI3+CITNzqXlvhUTjGk9x1HxDUJeGzGYPu5C8/m Ad/cl8fBcw1WPqU1YEvLcUdBMXvxWRPrMtDCntQ3RZ+K9q5FWeYP65ph7uGx6M+Y0jr2 3GJurRrHtpCmCg5kR/jtOPvm8gQ5/XIndN/xwV+QJGYqtPCJg37Q3I2ebxe0aKheASas D3dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yxDgC9jU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 8-20020a0562140dc800b0068ef926c952si223187qvt.17.2024.02.28.11.33.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yxDgC9jU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A93F33858C35 for ; Wed, 28 Feb 2024 19:33:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A93F33858C35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148810; 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=yxDgC9jUwUIHjUpgNtmrfY7hyTLYIP90sJAlivF5bJsRhR7y9cTs8tPdLhu1uERJ8 sl4ppFOOwIRUE085FtU8iPSNHZ5otHno8+JTOgPRXQMf9XqR6ezezQNMlLEsLRdsPc gPiGlSiST1IbrYqEUzuRy731XIbrt51CS5ITtItg= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501295938539753 X-GMAIL-MSGID: 1792172424115756383 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: 208011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570033dyb; Wed, 28 Feb 2024 11:42:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXVJarHWXg8frAUCLmzhMd80t8QeE/MD1WOBTb9M+n6qQJMyXwNnU3a3oKxyPtfY4E5rXSGvgL2M5uJtmbOG3MvaT50Aw== X-Google-Smtp-Source: AGHT+IFHCT6Vah7ZM7AvsPFLqMry3U21wyw5YwyrXaOHbSlVsfPMsnnw4sC7cZyZdVTT/ceotJxd X-Received: by 2002:a1f:dec3:0:b0:4cb:2662:3651 with SMTP id v186-20020a1fdec3000000b004cb26623651mr621116vkg.6.1709149329386; Wed, 28 Feb 2024 11:42:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149329; cv=pass; d=google.com; s=arc-20160816; b=MmR/QVadDf47ZFGGHe2zO4ICvx7QYe3es3dWir2o/cmiFfkThclNWJ/WM7GajnmeO3 yjv/j/mYnONkR4q7PCQoivu20OyvuRooLL7fHj3BVNs/+8JG9pz6fcZF85qi6T4vYgow yG7rWjfWUu5c02/kYCFppAHfwIcMkaNcyyIYg+skZkT+1lDnz/nUDsk5scvzQZD8S2f5 r2Yi5glIDL48vNgjNpRLlmzJ81Z0L0tDffzb8n1egf+j8W4sLe4E+lCHaO3ATd56zmMm GbZYgRcpST7eN0S+eudngLWKGK2tYxjmJxDgXb8+2sZnVGsW4iE4tXy05MK1skxZkPwM tqMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=EFzDqAXEc0hD9OxGNDy7+Cs0o9rMGdOQbgxzn5p74wc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cFP8mZaVI4oOgFLGcGbjSkvGQb297vvBtmm08Xf+SmYRWI5JWf3TVdm+mh3i1GJ+Ix n58CEmtZQU1oo0CocpdJVbtXlWZt5ERhhU90IZpzDDpE/8cb5ytFpw1NdbBwiK0gnPFn ydh5oKPg5pKU0OvtArPlZhYL8OCTuysI1TQjPJg3qi5WHQ10Yk3DFZd2CR1ty1rCd5GJ 6hC4/1nA2ylg3WctovQiwk9Q0kXCCBVwHo8KRS4cNtpJ9Mo8ZfrtWll2PS90VwBdudpO fD8hgCeH05e+cKKMMxcxE5PGRW1ABGDW6ZvyTWiFuIb5zwbUl8Qh+b8dZhiJl/ECcZbk C6RA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UUW3zZwg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s3-20020ac85cc3000000b0042c145dbf0asi136186qta.540.2024.02.28.11.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:42:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UUW3zZwg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DBA038582A1 for ; Wed, 28 Feb 2024 19:42:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DBA038582A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149329; 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=UUW3zZwguKHSrAivc6muc3CN5mtlPll8lbEKRAOReJpKmbxK4KP5++BzkwFtORQYI fhF6sY5Rv4aGr7tQNWUkzSPLuSyK6kA4l2FWaJeVgQ2EJIGedYSbMcx0kQBTZWeO5f ol3uUOrFNWHjwX29PApUsO2o942ZowqeZWZazQLU= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791500972180597094 X-GMAIL-MSGID: 1792172966798169226 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: 208009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3569574dyb; Wed, 28 Feb 2024 11:41:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVon8smIHvOP4SiEGjJ8g0KC3VJN8cOfKKDpP4Vox3f3IckvkKAgvkl9GSEy53cpqoDIurelh7r7kGutBYb2kJRizErkw== X-Google-Smtp-Source: AGHT+IHTWBNeJ6tBxby4QEhuLBxCWNwqkJEfZub1KMK9HuNJXaY1W5AyawM30940xl8fFn/KpKIJ X-Received: by 2002:a25:2:0:b0:dc2:2d0a:4d55 with SMTP id 2-20020a250002000000b00dc22d0a4d55mr160007yba.63.1709149267312; Wed, 28 Feb 2024 11:41:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149267; cv=pass; d=google.com; s=arc-20160816; b=Uqfy9F1xPdk+Zop0loyQsU+X53vL8wcaoFuz+gX7EZSMl8aA1z8FbqUpyXb/ceXfr8 G4k7Z4RTa0vLrSIVHKP6ZNXntNZ9AiEgxdR07GbisbIaG+bnHyUALBVuzXjzId4LyCRH k+U7A7re+oIoq6Td7enK33bJXBEBVqZD5iJNmPARVovHw3yNPJpp7mUn9fZ7q70sd2cW utclanyc+OebF7bwcSL9VE/2wC6TleT3hqhBJlSQB4PQ2CvzopRZVyLjdmzZ5M5FlYzD 3x6tUVXyiTlrpy1qdCSHwz0hJVrdbgl9lRc229ey4kT4wqGgKezJPCjitNgXkyR4G3TW jSTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=IxV0PF8RWIvKirtbPs4zduZDfZhpZPp4WvS6ATQTDo4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=rxqNrVAD9noyhCYujRvHxzM+WRY+eUsQjmbTviOsVs8/+YB6eHTk0u4i7l+fluqDFc SzkGLn482vHjEHcCiSzAQIBpTdJN9o4y4fWcYm9B0ubfXY6NKp4oB6PoXa+gE8MWBktf c8nLJPzz8sNUfFNj29N1YsKby2N5U+27Nd20NCB1P6f78Z2Vt3X66rpzOAXf3Z3Gnh8k asrLZtdzel4Li2+BtlyqRZY3QUuv86gJdvKSy6sFsoiiUYJqE50W+dYycbilzPFE7xEo feU0CUW+zCJA/ZDqQHuLY0zUodXvhMAnnSwLQPN51KOwyLdqpC41uql7Tx9QUpJmI6sk 4Ztg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fF9eUd76; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s3-20020ac85283000000b0042ea0a2fb20si118152qtn.570.2024.02.28.11.41.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:41:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fF9eUd76; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFB0638582AC for ; Wed, 28 Feb 2024 19:41:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFB0638582AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149266; 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=fF9eUd76OUUc0ZXaGjFuE+5fg8ZpEzCRi9FIUXyS7QI5PuruHytC/noMu86NxDXeo o2i+MbRtX/xd3pix7MXcleWd0b9bQbw/3Vgk3F/czVXsLZ2rpc7Z40fs42/orNt8UN PdB8v3KcjN5HaiSY5e64oxyEn/Zt9rvxrGHuXTRY= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501767153837701 X-GMAIL-MSGID: 1792172902056231306 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: 208013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570303dyb; Wed, 28 Feb 2024 11:42:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTJzJYp5b1TgqrccLBlAEiulWjfwCiLgZTTabTRj6Xh1zxpFkJ2cYlk9S2l8Pfw53h1z0xD2zAisQ3bXlMZkSvpt/CwA== X-Google-Smtp-Source: AGHT+IHdwgKeqM0cJNfErmtsT2Qn3ya8RvHt1JSoUg3GUf5rotK95DFKqWdZeWp0JfmKTIM07l15 X-Received: by 2002:a05:6214:5842:b0:690:4f5:1e97 with SMTP id ml2-20020a056214584200b0069004f51e97mr69468qvb.7.1709149362538; Wed, 28 Feb 2024 11:42:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149362; cv=pass; d=google.com; s=arc-20160816; b=sV1teKa7kDB3mf7kmje6Y0ksjks81S4a5amniX+rqHSgapUAnPca4rdYa6jhRPmEAY syAQv6fBjewF+McZ6D7NHsu1Eu5gnc0lJ0z4TaopjrOoMbIF3yULNWoIXqd/rRoemyL0 EjF4Z4KhcJtwn+GS/OlZxvDOcA4pHq/Cm9wpTHb6FiHF84IezcpZkE1qGon57NY+u9bR Y116criryNbOQZTsc9AeIUI54HLqMRWzulZ/zYI5tRG7Yecc7e5OQ/yhrkwqUCXUTKA/ qD36tdAa2QbjizWHssOzonvKae7Sn5mY8Yk07oqtz3mkNA58cJfHWbl60H0hlw5KSJXi 9pbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=aaZU/WEaPXym68byYiPPLg33qkHfBSIARTF28eRhxIU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=OTaF/7BCIJ3nad8qXcvVzLrPt3mQKkTDSCANhJR44MBFdpSXmvPxrlJLfraeh7InuR lWVN05gWLbd2dvxhqFUjTqCw2HhHebtFtRnwPEVwSzjLmQ51TYyn9jzHkHEaAPLRcKnt VIcmFYUPTo5JOaZaMordcRq/Ma8SQ4CTpBnX+UB3iB3VsUtH4mCSj5HM3iYELQ9Rt7sA eDzEwgquGL7CL0qEdpDsyxI95gKhvWMCIFM7f+po9qWnG/PPMFp46L9tHPkK0NpvN6PX js3EhGCxwK4XQzdBETfoAkBSU2Fc167jjzVSHh+05JWMjSLTLzHsctKkOYhnVGbZy4Ln AHuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gWbkTYxW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 3-20020a0562140dc300b00690047b8128si235010qvt.190.2024.02.28.11.42.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:42:42 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gWbkTYxW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 644743858009 for ; Wed, 28 Feb 2024 19:42:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 644743858009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149361; 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=gWbkTYxW0grRnE5siRESfNpQESfMifDC104GD4qN6zJdNfOHrcCHMWFXZUi4+M1FW geBU1OcE4u56Czyu6YeSeHX4jnrs3ld5lbaDS5he8/Ekd976NYBg4FNGROMZMroUnQ pQ9UautAXiUQ9VivnYdvggpGhSb83mesdw5GS3bI= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501354705491267 X-GMAIL-MSGID: 1792173001899336185 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: 207992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3567913dyb; Wed, 28 Feb 2024 11:37:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZsirUsyzZrzy/6MtmeoRn9qcEbC42/jOH11x8NulwJclaQRXInplDypH2JhXQbnMMzLaRh7RuSyj01k2AEBqNEpmuOA== X-Google-Smtp-Source: AGHT+IH6Lw4pa6HaIMSVZFM+9FIujWaQGBkgrCcSAlMcqhPtXvwPnF7L+lVFnguZSy5/G/GYTSUp X-Received: by 2002:ad4:5143:0:b0:690:299:1909 with SMTP id g3-20020ad45143000000b0069002991909mr31253qvq.50.1709149058770; Wed, 28 Feb 2024 11:37:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149058; cv=pass; d=google.com; s=arc-20160816; b=pFGg9GBICqVw29H0/G7/vpZY2m0VFZQd/CgQbNZgZqlZtnHsfVGJeh+qPOw5pp72Wj gZEO8lBs9ivcU+wOiTcKE+YRzcG54Ar4LGu5b6WX+sd+GsBYq3ODI8dGQXWyQ3UHNfgQ pj9PZw2FkSeHc5nv0rTiCfriAUie7rLgU8ylEF3r9AmQo13cYbdKs29n8T+PB0cYe6al aYGdiMDlA8AfvW0dk+H0A+uYcXfiI2jWZu+SR2a4eCN1tDG9W1LamcK59dCj+dPzpnn9 jhatw2wWM/F2+4xXaLD7Wrf5xa2d5QerUBCuIsTbiYPW/k/3EeazQquE1aqTQcOlNxUu KUCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=VCR1fZ5CXHZMm4uAmFxf42twY19+JZcVenK7BHozzMk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yYd3I4NQvj82ho1mBsRYw1BVK+tIIustOheiFMxwAWZwAsuIN77Ls/YLdx81ZHpgtD 4SDOM2DbcsmxXBhJveIU2pz9UblxdFq0G1xjBfxfUu7PXwGWAR8c/7DXDAsSHJJ8Vq9k iZJrFJS8LY0J0QIpLdInOLoHMJ0XsVtvLXsVCXwD2U470GwGQrrrpjOkPzR4BF0u7zen NIOhoYVJirRQK+/2gImeDAvpa3+uxq63tSdHz9muU8iLPTqrRqO2jZHNefllTYanBFWe JmTHAbmKIE0cCOohDW0qUVHhn7ruLMJ3a4YQlUiSGAif9PkKLTZadnO3idhT3vfjV+Z4 Kmaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gkzy7Bdb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 12-20020a05621420ac00b00690011ff09csi195861qvd.393.2024.02.28.11.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:37:38 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gkzy7Bdb; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12AF238582B9 for ; Wed, 28 Feb 2024 19:37:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12AF238582B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149058; bh=VCR1fZ5CXHZMm4uAmFxf42twY19+JZcVenK7BHozzMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gkzy7BdbB3DreyjSrDi51LvPE4uYXds4mQPBJNTVdK7nD+nF6UxB+fEi25nPHR9Vi P6aji4Nz+mE4YiJriBtx4M31aGl0MO/M2E5EKpERFUaHkxhbfFMdy3NbAdT326GfCQ AnmHSDBgrbCXS1Xzc7RodSaUnusQhOHwC9KUDy04= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id A0F413858000; Wed, 28 Feb 2024 19:29:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0F413858000 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A0F413858000 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; cv=none; b=xEGEyCKZNUjz1Z8xDz1dCvE9Tz6XelvbMjfctZ72te14HCI43cgb3XSl9m7Fx9Fs4mOPiQh10VygOP0ZY0JNLzHqXb+mYb4lz6RP27uB3ksAsp95/Ee7Vrj4kuCsi571q+nD1w5xagmuQ7pc+Ujhb9CvQC20teqZjq0McyOCTjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709148572; c=relaxed/simple; bh=VtQnoussf2bSaiJHSc6oXahNbkNP+zD4tnolaN02p84=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tz3LvUXohN5q6wKTiPH8ZTmqEd3Aywr94Rt7ZxvOR5U0r5UZr2p6uO/YqZ3isH/6aCJXb9s1wQqmLrh+XyyH+7vihYYZ0GK1zQbtXvoLZUpfUcB9+R2Jzqid4Sw3ho9ziZUORvqQxf+C3325AE40iZUXSj5X19DkUfVOZcu5eQY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41SJJloL010615; Wed, 28 Feb 2024 19:29:21 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3wj8nusn3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 19:29:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW24.02) with ESMTP id 41SJSpWM019397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2024 11:28:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.74.128]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW24.02) with ESMTPSA id 41SJSoTT015429 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 11:28:51 -0800 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v14 11/26] c++: Implement __remove_extent built-in trait Date: Wed, 28 Feb 2024 11:26:16 -0800 Message-ID: <20240228192843.188979-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240228192843.188979-1-kmatsui@gcc.gnu.org> References: <20240221093616.4001742-1-kmatsui@gcc.gnu.org> <20240228192843.188979-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-GUID: kVza3X61Q2_ra92SbBdHUaytvTAzvtNe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1034 mlxlogscore=464 spamscore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402280153 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791502124479822517 X-GMAIL-MSGID: 1792172683449439914 This patch implements built-in trait for std::remove_extent. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_extent. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_EXTENT. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_extent. * g++.dg/ext/remove_extent.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 +++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/remove_extent.C | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_extent.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 63f879287ce..577c96d579b 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -100,6 +100,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_EXTENT, "__remove_extent", 1) DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 635441a7a90..58696225fc4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12793,6 +12793,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_EXTENT: + if (TREE_CODE (type1) == ARRAY_TYPE) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_POINTER: if (TYPE_PTR_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 9d861398bae..5d5cbe3b019 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -182,6 +182,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_extent) +# error "__has_builtin (__remove_extent) failed" +#endif #if !__has_builtin (__remove_pointer) # error "__has_builtin (__remove_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_extent.C b/gcc/testsuite/g++.dg/ext/remove_extent.C new file mode 100644 index 00000000000..6183aca5a48 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_extent.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +class ClassType { }; + +SA(__is_same(__remove_extent(int), int)); +SA(__is_same(__remove_extent(int[2]), int)); +SA(__is_same(__remove_extent(int[2][3]), int[3])); +SA(__is_same(__remove_extent(int[][3]), int[3])); +SA(__is_same(__remove_extent(const int[2]), const int)); +SA(__is_same(__remove_extent(ClassType), ClassType)); +SA(__is_same(__remove_extent(ClassType[2]), ClassType)); +SA(__is_same(__remove_extent(ClassType[2][3]), ClassType[3])); +SA(__is_same(__remove_extent(ClassType[][3]), ClassType[3])); +SA(__is_same(__remove_extent(const ClassType[2]), const ClassType)); 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: 207993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568074dyb; Wed, 28 Feb 2024 11:38:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWKnr2JikbjL1NPg6U2b/IFh6zqkePWbhxXNlIGxny98lFylSKeSoJ6n/aOlQJ5bXlObj/FDRmKVMVZZdzxOtbar2yk8A== X-Google-Smtp-Source: AGHT+IHdkFsGwoFPMwAJfVb5DfSVYapU5MNMVIcpUxqZtKDcl+oS36EgoKDBHrUBdN3UoMRvuimm X-Received: by 2002:a05:6358:9895:b0:17b:5dd1:a38d with SMTP id q21-20020a056358989500b0017b5dd1a38dmr308441rwa.1.1709149084857; Wed, 28 Feb 2024 11:38:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149084; cv=pass; d=google.com; s=arc-20160816; b=onlvo0OiMdF3JUNuWpqnZpWQVslIAwcylR6S/aPLJu6AwA3hNcqRaxAMgk/R/NsLgc 6KY+//PiDz4ujTEAj0u+Dr+DmnWWCuMX0dYudITyPJUgX/XvHPN401wKYiD60CcMOHFI BXpDdzkpEKhsAVZveLaDzEwegmBZLks2BvPR65+fjAHv9XXjnRoywrYkKW/houzqdyiI ++IpVSRicFvXEKv0Nntnp11Fc2r5H9jnbtFOWvR9Fd/tTikSIL1mj2oir7P7WVJcXVLY +QxtS4wq7ilBR9FCwtF7qs+Rnk3ZT7/nao7S+fgWy0DkdiEa9BcFscMcKELqUPdlxrxG +OjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Y3KwK4UariaDhMlg1CtRZTUxb0YlxPX1cgnmNYjjmho=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=k3UoBjdpWPSzOomWO2IEdggVcS4nYfSYtrFGpL3v8aiuG4Gya5bAM/cDIkRHiuzFjD CSEEMF+ir0kFUxIcX7gSpsdtvn4pMet3BVtppML2+QIF5/SauKyZlaceJafED+5QSfsX VHPv854beYSMQkkEdZz/ND4qwCObnKFLefS7RYNcb79gaz2fuWpoLAmDWEV/wjGTQijv fnw17vXOz8a9wioEHLEc7aVAUxeTDPckOleX6eflGxFM8YCIR38Z5f2ceWk8eUTPf6Ut oW7EedLWQ1gzOk8qdhfUCA1ULEF3hWnDCTWw06UygcKytu8lEHQmRSHHdCCtU6HT7cK2 oWdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rd2IczYx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id eq15-20020ad4596f000000b0068c64a838b8si182592qvb.417.2024.02.28.11.38.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:38:04 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rd2IczYx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E32938582B3 for ; Wed, 28 Feb 2024 19:38:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E32938582B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149084; 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=Rd2IczYxAZLHoV/V31n+7Pfuanp4tRCeJZ9uqMIg84zVmP/cz82VgcoDvSWolp/CM V6pfQFK+ZiwekGdtCAtsaPivxJTWnFE5v0tTrE4GM60S2A0lt1WwegqwPJvRtgY0Ri zB5or7ns1Rwqtug4PjwbF3ehtUJ8gp6nw1P24Vok= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501400727160498 X-GMAIL-MSGID: 1792172710648076671 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: 208007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3569050dyb; Wed, 28 Feb 2024 11:40:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVz8bvhzA3muBoco9Ku5o6h4EWbPkb30d3WRjPYvLohGJG5gUmJgDbBIvT/jqJTtfcOQ1WPE4S8RVIe27MIXu0WBoddIw== X-Google-Smtp-Source: AGHT+IEIFbEU4n3Yh9JZcWQizURScNGQCYlK0+oPS41iQ5r7bVE/P1DTWUaiHLkoKjik9LVtlnoo X-Received: by 2002:ac8:7490:0:b0:42e:7036:9bef with SMTP id v16-20020ac87490000000b0042e70369befmr12503166qtq.38.1709149203092; Wed, 28 Feb 2024 11:40:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149203; cv=pass; d=google.com; s=arc-20160816; b=Cuz84DkkrZtXz9NS6DWdJLiIay3CWKHDTHmTbdhqaHgJu/KXnUQa+VueLOAs8QKuw9 eCt+Xv46+6XTuSaBiDF+RZVnekm8I4o+xwuud7J4c8+WEhP91K72ADgK7gZkZ2MYVSTc lXts9gbcARSmvoHA8ZdTvL7eklw2lWxFLeizUcQXu0UP9gYeOzLyjoGjXgfL9QRPsX8E hG2wxNR8tsXe3NIwvcab66YJd9yrWK2z3vfYC1oy+fjOdqJ7TAszAMAjEF8U9VDoiIi1 nGGaHN28y4rAXU1bgtYwYcU1qqXoP+N+RtBvRx8KJKKxrEawT/WeoYLdIgvR6Ko+RFiT O5JQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=v7vcdja1ul05ur34H0TmQ/T48IuOguGZkR/jvozE0RU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lpGxmk436rnozZpwwdPVFbS6yTTUS6JCw7+sMsYIxLjWg0mC9wjK2yJovBd3/kFe+M nJVCtImL7ROkwH3K/kuXGPPjLoNkxyz1wGF8qTC2c9sYH36+XDfM8nFgp4o91EIyfW77 KuZ+2SY/Yzx3cpiiQN2icvsCnjwFF5BO/OW47n309qA/pnBmmkndoTqh0DjR18Z2yUpC s6pN8K6/HGVYG355f+d8EEcTEz3KUgv9Cg7SC2k5w899A/5j+0IcEBPXwLqB2Bxegfor yR2I6o7YuZudfpvKXC17M5hymPsponzzaRS1XaLmy0uQ+S+E7RrbuLALaDy8nPzwr/5d W6gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=waDrhGVS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i13-20020ac85e4d000000b0042da9e828adsi143631qtx.381.2024.02.28.11.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:40:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=waDrhGVS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B86143858C3A for ; Wed, 28 Feb 2024 19:40:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B86143858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149202; 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=waDrhGVSUD2hKB7+2NrCKNbICpsFb0sbszOqwSCy+62fizhD0sBPQMqmqycvv2haK 6DmCsceQGgeIk6OeHPrBx9Tc1lj90I36ZdRKaJSiDqU+wzmvT3aXuRU1ysyaM6k9ZN zlFL84awqrpz4yjTSQNhVrsFQIqObo/b+/7jkzpc= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501585627122158 X-GMAIL-MSGID: 1792172834667508155 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: 207989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3566909dyb; Wed, 28 Feb 2024 11:35:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX1x0AswoGXEVbCYRuWfTyDBmwnjoyTXw/T52SkR9cExYvRrR0/zajyxWGY4hb7hzUufxGYYSlYiJipMqR4Ug4ZWLUaWQ== X-Google-Smtp-Source: AGHT+IFWTzB3NFfp7CLakJH6WWKmBbxTivz+DPV6JxqlGAbNOgTNOc50P1czROrW7Yffy8HBEqau X-Received: by 2002:a05:6214:440d:b0:690:1e52:dc23 with SMTP id oj13-20020a056214440d00b006901e52dc23mr5036015qvb.17.1709148911008; Wed, 28 Feb 2024 11:35:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148910; cv=pass; d=google.com; s=arc-20160816; b=kxduq+hzugSXf7r/i7tuqTmHBgOr9KNr5JYea2xzLYLjd1zopv8CpRB02cLPHiVzpQ InBiUucH5IUNIMsT4eSpRdU9pnXV4Vree4QFyPp62fZGb1c4x0RmkdVVkgoxP8F9ALBv PqHOkM6WALlluq8uY2RnQvPFB/ZaQxCAf2hPoyXEfrWUIPS17oXf43K6ws9DXbZDA1q7 ACvaKgHgEBCdkJgst1ANTLunZI+kfv0Yt11ZEjEu82ICDvxH0OaVIIVL/x7Nab6ju9T/ Bp+taUB6B2QH+y6kEMBF9j9BMmZaiX1scBClEx0MeaueFQj2Kgf4qJ7Y2iGjslSZkIL7 jhdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=3t2NKsrNHoK6JH4mvSW3eH0lqgZun8CNHli3FIpNshE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qVmMZTvxNb4R5f3FerTtuIYNl86Q/LL14z/Tf0UgwPrJoqtrR5208YHbssen0AXXVM eWFLo8yIE8K1WKFZPpt3sEEhJe+4FBxkQ1yM1LP5yo92KxscrUmPNWVnX1RBnCRkDDuA p4NWQ7kk2ZrBKyv1HCrwKFxN9+1QY4l7kIQAebl5CioUWqnfYQz/M9Vdt2KhYzFryHD2 hDmkYgw6fBx19sG5kOdoyYoOdrYB9+SY2+tNZxuMUzaQZQktFi8mKhQO7FT3z/uQadtv FgKHWY69d1y8XvLkd/RgCPQD9FwosMwc/pBbY99Br/xP+VggU3gw9bAncmmZZ3U+9ezE jlmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UI5NnaeJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u11-20020ad45aab000000b0068f550eb9fasi188176qvg.413.2024.02.28.11.35.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:35:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UI5NnaeJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99DBF3858401 for ; Wed, 28 Feb 2024 19:35:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99DBF3858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148910; 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=UI5NnaeJRHg14Pn8RZ2PyrjRQSgYIpAxiG3Spc6vQr8WfW4WQpoS1XiWhQYu4iDkg meNZBJyEnlIAREQHSMpkGOwJq/68ldAs2ACtVVonF99WZ6W3HccfEYu1w7pA4c+g5N 949W7ObLxQ2hWIdINlW9cA04ETHXjNzmq+A3FuYQ= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791500987091372203 X-GMAIL-MSGID: 1792172528385949396 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: 207990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3567379dyb; Wed, 28 Feb 2024 11:36:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXEOHNocXVs0XJaZ/UyA8bd3rGwg9s+qgdEG0V72e/7hMxihDdwN6rKlraPtvY+E7ODSnxsMW1HYr54VGe96OhkIn+gdA== X-Google-Smtp-Source: AGHT+IEwp2cUzwLU4LddOMuFJh/Et42ItjNMwd5cbjYx+/qfN3xHVzSDC9w5p8jCKqtW7vmiDzIG X-Received: by 2002:a05:622a:1b9f:b0:42d:dd8a:e63c with SMTP id bp31-20020a05622a1b9f00b0042ddd8ae63cmr16137768qtb.5.1709148992204; Wed, 28 Feb 2024 11:36:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148992; cv=pass; d=google.com; s=arc-20160816; b=XrCpMJTmIO+Kk3ylVIApFKYtetexaVRD3RqvxRHWvhoGzZg4UGA6ftU2VGM25otRz+ pr34mxx1iCxwZfdS0U3uR7RWeeyHZzd+DGDD/QGfF+BZWWY/zi2qouZf1aZ6lFAmM9wM GAFMTKXogk8Umc3aj3e8qvVWUl4vPGRcSb+ti2wblBR08H+feaNYjjb+ZWOsior71GrV z+0ThAQkDjPkSFQB3QaV+uA/R/kYijMmy/PQcwVbVwR1eqm9e6GGWxEOwLpFpaW9nYPt blPbcxtBuAwyKcaorcHSQYvuQ7lvFkPs/RTj4UJ5+ztCnilqk+D28HfG3aRRZY+ocJs0 oFWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=tKvRVq7l6vwbsPH6YkVrujeRBKeLUCM65oxAufp3rDY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mIjDxrkBaqdloqgFCWV3ao/NieCilwc8J2t9F0q0fLCHHRPxSVbJizxeLqoWUVUKlP /Uu6mMzw5MAOk8yb59ILQvomI6Kz59WvnES6tb0PlAU6yjpjRnCjfz4dK6b0/BjOWLA5 l/FIz3+resR5zKdjNK0ukADBhvBtm7ZWODjIuYxqghOiDncG5E84l85+8pdAWCxRJmlI pOtDvjlE5VI9EpQTL+EE6VgO5Cw3yrQ7dkEzylLeHJ7mDTJAyXNmAyv3nZUpGCN6p4dl 2BBL1sfYKMLGl9SeweQpjoz7b4n48Mg1dhCo99vpX19RKjr+p2I4nMQgwf40pHb2s1W5 a0sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U9WvT9Bi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v6-20020ac87486000000b0042e8b562c2csi118049qtq.425.2024.02.28.11.36.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:36:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U9WvT9Bi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2E0A3858438 for ; Wed, 28 Feb 2024 19:36:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2E0A3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148991; 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=U9WvT9BiA5YlRn8jI0p3yVdCphPM7Cuenrb51wbiL0yQGAcUAfhtxZVqyHZen7Xyl ozJZfGAMH4vbo2LhW0LVlZ5tBi3BEdRmPfcK81ph/+WX9IQ1rTS1TwxdDoQxsJN08u 6NXVXZCWbo1UZLTW6sm/Xp5ler0mnZUC0qOTYlUM= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501217722010132 X-GMAIL-MSGID: 1792172613946966146 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: 207997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568360dyb; Wed, 28 Feb 2024 11:38:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7B2oyDDD73JwTxvsaSt79kIF5WgP8QWvr2Wgkx0W28y8+n8379oasc4i0jyW4A1No2ctr5el9oLUGjr5kMPJjyrqRBA== X-Google-Smtp-Source: AGHT+IG60Ka+stgJ1+JUYa1kORAAEeTHlgsuyJXoT5Q+jhEUc/IV7ueuusl1kelgJN9p+OX30180 X-Received: by 2002:a05:6808:21a6:b0:3c1:b3c8:fbf3 with SMTP id be38-20020a05680821a600b003c1b3c8fbf3mr5131914oib.3.1709149117970; Wed, 28 Feb 2024 11:38:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149117; cv=pass; d=google.com; s=arc-20160816; b=PcRbXbHqqYTcX39fgHnqkMS5yvfvLBbboOF62X6qU0qSgZJIN6u57mnBSX5bHHFZtG f090RswAGd5VekXHhc/QNzAth/2lGz8/Xzdcu6lAUqeGjFzFDBdc2IP39m3d5GPpbOVB tCbP+D6fScFU51Uxav1DVic8KCYHanhslpmPPh+EJRF+YV1vfEc4OQ7VQevLkn3SjaNq yUORK9+4uetPN0X3HxZWAUE3UaiDo9y+roXNoNnwSKKxSCFVpXu3saYLN+8WBr7RAb3w 0HSjz1pdmfzxgoYJnwUHtvRoh4jVMoULl03XjO0jY4h07wuPSx+4I1P6forYn7PEL48F dYpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=n5wLONU2u6JlIhFT8HIAB40eZiuJ42IeVNr0AnCccHY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CQSp/UrWUX/MB8dyB0R38OCvoPL7CJDb0ytrgfrNH4mPkRNbmp0yOC23Bp1B2MCz1a 20oz9YSq6sSH+xJ+9vlDqpLG+gS9tv/+oPmPeL69lX2WuaS5WytoVJjL1NqfrC861a51 J+23pubYWgMOnggFHZVexyWlgXC7MXyO1ItnfIH1/XoESB/kM4N2Zzp8PSbidDBF7uA5 AOqMfIjkDwiCT5BKVY/ILLT5/BfKGxWj1HPWraylcQKlGFXNmWG8QDTCQzhZ4FnElES2 0tCRQlplPBXjVMHjwXGHFEIT7Kc0S+Kfy7dvju97qOON7k+lyz5KQxabveaEbWQmrcI9 011w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TushYXc5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g7-20020ac87f47000000b0042dd999bd19si161639qtk.63.2024.02.28.11.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:38:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TushYXc5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F75F3858299 for ; Wed, 28 Feb 2024 19:38:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F75F3858299 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149117; 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=TushYXc5C+gsK49PQWm4Y0cnhcPoKve0L9yVURC18Yw7YT4qCwP+A/w1EPJjbGblc ayWmax9J05oRnYX7yhgOS0qSP/bRTldJgElVo2WGuENfzqgxMzF7Qq1H3PWlW9QpYa LtY9q4RgUC8ZFAqVxtKuwFqHeAhZAoBfi+zamWbM= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501072374307009 X-GMAIL-MSGID: 1792172745407475621 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: 207996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568263dyb; Wed, 28 Feb 2024 11:38:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVCAD2MCUsnNbrE9KzyzOiO5z5WyimIMf/X3t2lSKHtvBjK1UrkZAmaOdceZBQ8TC9vQLVBqOUlVLBldCEUEt4678QjVA== X-Google-Smtp-Source: AGHT+IFb1wSTfCEbvHkz5b2VM7b2mH7yJH05Jj2tZBF/DNLdEJgrbbL+Z/dqa2gb4qjKB3VxS53l X-Received: by 2002:a05:620a:3712:b0:787:32a2:ac24 with SMTP id de18-20020a05620a371200b0078732a2ac24mr26486qkb.59.1709149107750; Wed, 28 Feb 2024 11:38:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149107; cv=pass; d=google.com; s=arc-20160816; b=LaXhNrPK+d1K3uWEV6zt+iTcmWvFkgp7N4NqbY9qLfURXau9iQoZTDCe95nHhgNeAf iA7aMzBbA33HiHA8xxQJ2/Qcn4pHjQuQ199XvYUIjEZhN92ixTjrA6/AsraiVlIaX7AL 8uPlo77LLQyNj6X7ts7oqpajHv1Rneec2Ubs7J9RFOYjbfdRmSNj4kiUZuMKYjKp18CB ByMsSdrctN4E2SgiyP1NuZiCTedE/N3m3lb0y6sreWcezTTBlZ4VaVL7DxBrsRRaRh42 wB4LFzp4uVEKZXrBXymOR3Oxtp5AGi5Qfzy4SYwalRYMtjoMo5WDKFGBf4X9q3bIUYdQ a2Jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=3EZuA1B/ksPpfjZ2xh9r7uKZL3aWvZmmSEkF39VTjSc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=IPc4wixSnIuOVtLik1NBOo6Ti1+hIQP5cXKf/0HrCvxQY5X/iFInqqrNj21t0Z6W2V GpX0nPW21pheYN2H7YARepFGUJoeWRdqQA7UNRprKN1Cpa/i+DSHd9SCJCO61PPJms+f ATN//+rar5SDzhg5ooSyCjO+UUZ5F1w8mSCa8G06kcZOP80Uv0emV4u/QRZXAwYwjYA4 443cM67/psysYqyfUDCW1fexOJF68yK3cRdpQlY78ZMN5HMakfuggYYgAV2JtSY2zvC0 EcmSE170xbqYDwoffv+ogQAt3QVVHuou/w0xlzXfD4cvoqQEo0GOOL+Civ+qwOxBRiD/ +WIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hgDPOe4L; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id po9-20020a05620a384900b007874ee5955esi187852qkn.475.2024.02.28.11.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:38:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hgDPOe4L; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4994B385842C for ; Wed, 28 Feb 2024 19:38:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4994B385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149107; 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=hgDPOe4LsWoVwsYWfhKpJuMoxhLpoGtOJG38sxOiZJuKHuApjwBN1NnRc+Ds5GSuQ ZwUdmAIV7Yy7Fovwu0u6UJTuVu+gi8FtX9tazXo0JYquMSCJBtLuk7qZaPjf0r98kg EeY9Fj2bqWlXG8CF4Z6PxTG2V9NEDVhT2/CyC+HA= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791500829273767658 X-GMAIL-MSGID: 1792172735075390129 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: 208017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570943dyb; Wed, 28 Feb 2024 11:44:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWqr6y+M+zU46kKOIpkwVvQZYdK82AoHXFMGtfzz9rIf4oqlRnra/k/iDxWFxKNrYsDgJu8z8q5lSnSu2WZ8w8kNDUN2A== X-Google-Smtp-Source: AGHT+IEUOcoCd3guK1Ols14umIFplRQQ3eXwB46SEYB3Q5vrml1/NKzVW1MnhrZNsaIhrwLLLVXP X-Received: by 2002:ac8:7cb5:0:b0:42e:71bf:fb92 with SMTP id z21-20020ac87cb5000000b0042e71bffb92mr12009099qtv.40.1709149466225; Wed, 28 Feb 2024 11:44:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149466; cv=pass; d=google.com; s=arc-20160816; b=ZYpmmNW0W4vpzlGMhPXRvyVoipzyWVHPDoMrhKb+QguCCiMcRFUiTWioVWoh5y1ZIp ajniTM/EldYGspKwH9LhlaytqupKBWA2gQUTRl1Qr1GtsjYlyAwIH7GXC/qwrSKGVCGD 0tNRgogKfjSAiIqDxVtSs2TE59d4IzfsEP599QY2Al1iu2D6H6z5aXqcGBbVykmLBtTR b3uCPLZnDBBo5Hyijr82fr40KBrxRuERLo9JKbJbB/rhUbc/LsuWaXBaKiTt6THO6aLA lizzuSBz7S2o/0A60x6hNDWXnRUhhAaQR3KtuZF1Iw0wH9GZ5iYfwY5acpwAqU9F69qa NUPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=mhyIzL4Sj+mEvMzs7UihcDPW8bBe/aUpC3W8N0ZatRo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Fie3DGNs7+mgAVL3NYii3JLP8MsPYUQ0JMnO3de/8NGakyL6C32SX3fNewj2mY3AG4 5Cz4cWet95p3mlbUEcuuKPwX/cnSxekhWnOGLkP8wEc36PRFVaZtdaq2fvqaArZxwVU5 T/ioTYiEas+ct1oDw5D8Pvd70zSzf5XCy1awhN1yhuuG/PGZZO2M3eWMBrRQN7R0AYKy vyzCMdjEGFti2LOaqoVaVUZKmv875eMXpMPN3G/1Twxd/YV4FoVuoE8VFxwOcAjFmxAc 0smHg73F0BYx/sHfw28RAtDn8FtDzoZf3yoWVWX40AuvUG75fmU+zRYidGPjNJhExIPg s3zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wMjHjfNp; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j13-20020ac85f8d000000b0042e583a16e6si167184qta.168.2024.02.28.11.44.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:44:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wMjHjfNp; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C98113858431 for ; Wed, 28 Feb 2024 19:44:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C98113858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149465; 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=wMjHjfNpIvA1C6sGIhRSbCmuDxeKz/Z+oSDrHc4TXHNIhbkQPJJ6oQuFi5Kwcgh48 Fa+RumeDVxMet8xJ1nrbf320SwZMpaJ46wwGBJ4gleZNCc5U2oi1TGv+A8x34+hKVA ff/4ZAEavDrt2DYO5lbaoIkf3lFdJj8DA6oFbekw= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501088327021339 X-GMAIL-MSGID: 1792173110885065271 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: 208014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570413dyb; Wed, 28 Feb 2024 11:42:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcTb5IlmOWDuJxtEVQnqISAZhsPWPMCPSSmjRNhorNX68EbNoZFXD61YXZA22XmxxkkiYG4Fq+tC0DaWRCaWRWMNyeOQ== X-Google-Smtp-Source: AGHT+IHo7VpoAvOje386QJLxhap9+tL4Jm3p71mLBQT6P8m+AA7cCjppjmumdAlJ+DbY3QnfwNwV X-Received: by 2002:a67:b44b:0:b0:470:54fa:b37b with SMTP id c11-20020a67b44b000000b0047054fab37bmr477983vsm.35.1709149376244; Wed, 28 Feb 2024 11:42:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149376; cv=pass; d=google.com; s=arc-20160816; b=ttGALUtG3L5rfh9gVWBL+6o2YxTTOcMdfdvndJa9IvdZ802q0PwDRBFaTtQW9i1YWk nstZFUO4R1drTE7zhf0/vu07KjBjO0kVIwAJeB3URgIkq8pBveLAKAFCri5sWPJCZAlY pcHLGUhatJFdafv5JheKtwKTsyi7isJ6ThXM2z+xWy2Q4O0bFPR6rg1+LCwQrmfcEHdl Z3FhE3yOZBs4JaQfzHEILYpBo4ourZXmGkaFJYAgNSOrYEyYHcUWwndpZG9nFt5WgXJb +WOtVAP5Mbp/tz0jJqj0fEaRv/v82z9unuH2WxGsFRJGQ49vez3PCAQBNW7AWrMqS4pd P0Mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ojQrwrUDSh4TIReeQbQMTeMyDmid3s/o5ImN5+m1U8M=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=X9kstDx5kkWbCsc/xZ9tHvLY6rgLRrFEJRRoI6Yea9yBd4tpJ9KrPtXRA3EfJlgAqc RtMNcJqiYyV5L94F8Onw14AlQfpgsOWTCmas6ncLhWUw45gOGgGaywCS92f2lxvG+AZz 7r7u9r8mMaW+NGMZMHDI8L40aRN4dm2juDuICOQzoEJSWkqANrSvT7WDrkpyZwuTFcaI /aKxCliPlxdcL5HLS5Tdu0x0MI1TjeqjIar4Ede95Cxk10gMinqrgzuGrcEL/9rmiGL3 6VTLeDFYh1uUWY0Ng849O3vDZJ/1nNXsiGLCfGzXj+Bz/ygPLBEem5ZBidATVlhiwbq+ WQGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=suOe0k3H; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s26-20020a05622a1a9a00b0042de974538asi146963qtc.236.2024.02.28.11.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=suOe0k3H; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC5CC385800A for ; Wed, 28 Feb 2024 19:42:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC5CC385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149375; 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=suOe0k3H9CND28cEA32supejCdrk84qp32Lrh7V2oAyPDNMeve/bwOENboFpqIZqV 7WOvc5oulN8FlMorPACtoUCQSAXVIbHV1KZNCdnVp67C+0T3qZ3D2qWOyZV5YOO/AJ gvOwAW+MFlPlrKAnYjzmnw9jBELNg8nShg1htA6o= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791500851546587803 X-GMAIL-MSGID: 1792173016092194278 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: 207991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3567480dyb; Wed, 28 Feb 2024 11:36:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUw/OOrWT3235Ydq7Mo4YXwRY6J/JeFdXpPD0RfT2WwotZOI82P4ITJrPdrlWAZIHJOZ4Q+9bpK5ZUNz84hvmOe3sC/SA== X-Google-Smtp-Source: AGHT+IFxEMDry8zG/Ysp6DNgVsa8elWIvAOvP39szfcIh59kcyAWspQH8TqE2SokOzqZjtA5pkfT X-Received: by 2002:a1f:62c4:0:b0:4d3:32c5:17ec with SMTP id w187-20020a1f62c4000000b004d332c517ecmr716696vkb.6.1709149005031; Wed, 28 Feb 2024 11:36:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149005; cv=pass; d=google.com; s=arc-20160816; b=dRC3gOT0zGL54d92h6cB47VDb3cTS8jSA/vYhDhqQshT+LJz5VUKJ9FoU9VNsAslTg s4YckPpOALhvpHZxG7aJMYMW3FIXvVONrAsoDHcI9L57lM4LT785EWsaljxZZ7VNT5zU +H4rTQMN5nmcGT9Ym3kNyktE1wkE4lqGLe22dPxkSrVLG/ap3ufIplLYP4iDMdcxVtRN QTQf1ZXOCz3JCsudoHzHya0RUVrD+ea3N2NVf3UYHQkv864pGVzd6cXSIrIVr6fhuY01 JJ2Qqb33eItIgeTVHxCd7YRQHgigvUidBVFltDesiub3HjvemVbOUiPFRGmWjA8dFDn1 q4dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=y8LsNZKy6kMQm1J0qzNqNC8bZqkzX7m2KZgi4+l1wPg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=WNsZe9Rkq6NFUi/RJeOrFkDIWX1ee9bsHBtwxtiIMNDvgefss50xfPJHyCnSZp+s2c OHH9SzqPcn07rfkIEPsZOdopq36XYEPVL/liukrbxbx0Pty2SASMwXhtBs/6eqvFEdMP +yEi0NsEagWntJHN3epfdh6oVv01/JmpuEi1adqc+K+Ehs+PDG0F8anRZZ+Vy6KP8Twf EEX21IkBBl7ce68JdCgy8Lcc9FF2DyDoCVZoI+YNdyxAnsFI4ztn6shUSZBkyK0tf9dM T2ZjGynBiMmrtwFll2ORmIYlJVZlRvHQbJIkg841QALXuTrLMi84kShnpfSgkuFDe0zF BYsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aXkJ0BgL; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q10-20020a05622a04ca00b0042dc2aa2568si124326qtx.635.2024.02.28.11.36.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:36:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aXkJ0BgL; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A64373858C52 for ; Wed, 28 Feb 2024 19:36:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A64373858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149004; 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=aXkJ0BgLsDWPfiJze6OJo+rgwR/6CdrnNXdnOtmhVJzUytf/jy5RvkZucGfRmAjlQ qyH/GgOh1YBOsA5EHkGlcVO0stinj0uXbSjYu7+9wX4Jw7whIJ5XX7Y51q0hVgNoxo xXSA4Cu8F6kpYFBJ2eKs3EdsOSK5PQTEG7sFQtMo= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791502042706991076 X-GMAIL-MSGID: 1792172627292086904 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: 207980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3564554dyb; Wed, 28 Feb 2024 11:31:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXF5z0hXjDVfe7GpRUyvKaKuJbmRr9BJ4430fzJuY/EihfStIb/sD+79bE7tW+zrJFpjtyZF5NWD49GH5XbEmqSAVMGdg== X-Google-Smtp-Source: AGHT+IG4wd4Q0j0ngw/2YLAIVwFlmNI3wtHJsJuO0Rlq5JWslrtgzRVpi5cCEKvvKgPvLD0mchnl X-Received: by 2002:ae9:e64a:0:b0:787:f920:35ee with SMTP id x10-20020ae9e64a000000b00787f92035eemr29921qkl.4.1709148669269; Wed, 28 Feb 2024 11:31:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148669; cv=pass; d=google.com; s=arc-20160816; b=phny+7rCrqDCx5YSaV2rzocNVDl5A9lJ5id9ZkRgO3QRM5A8oU4ZvgkksDFEMhfVbg 056TwKSiATYS3J0+6l+B7OySoidXAXuypk9B+UeeY5BSuD9tSFfBWByxDfBSAFtQ2Gas pK1L7ZIjIy6zUgzQ0Rw8Lbx26eHwN6jLvKjHKPNFu4As+hs+Bg84qddaSkk8a/ms4XC7 NpB/JKlYMXaGVvQyMcYn8Hu9JFKL40xYdGXsKW17TsyL8Sa1wRmIbBsWuR4lnt6QPFxM HU3tVv9wWn2F9oZyT7QC850Gya6IzU7b9BdG7ewXGgqOKbzHDPo4EnfF9UNLSy4/NRbp zcxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=KXfHU6FbC22eYHezJGmFUEjgXJtyqXcEcFUk8XWNhKY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=r9BMyLR0d8fvK1nOhF0I+xdKb259062YvGd8jLLEuIvXcWkpq4nsfQ603rR4ofxIai AHf0GTuQL4v1mDMGBmSDyCxfCLLmrJDyfevTAz4BgI3VZMCtrWJd1LmKmwMtDQ/w5Wpk RtGZZKZ+UdZhTQ8gXvCU9zwdxPkVHpUgq9LRRc3hMoqT15nPEetB+ZE97n5fzrOI4W87 qzO0HceY+cG5oi6mkz7+H58nqutlIv0HY0zCU+rXiN6wXQbL0YVP/mTEz2WMKIoHGxPL pJENQ3xOirV3EqT31KHBtdXw9TmcjapPgU3MGz9vFzFEQ2PFRphrvsiIxC22jFPuwu+f Y07Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=q3gWhjrn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l5-20020a05620a28c500b00787ef54aa95si214625qkp.240.2024.02.28.11.31.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:31:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=q3gWhjrn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B211A38582A9 for ; Wed, 28 Feb 2024 19:31:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B211A38582A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148668; 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=q3gWhjrni7LBd2+GpPbhiPHQhS0F9q4gd7wBuMaizmNGYW40eQIwj0dX/hvFxObCr +DCOtjO5f1y3Qt1K+CDE0V4dif4Syk5V3dlagV91alGUKYr3iRqRJTpgKVwsNzXu28 ZeLnkcaU7mVcEiJyiu43JFW/jLps8+RjhAlqwkLs= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501682708987942 X-GMAIL-MSGID: 1792172274759756544 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: 208001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3568816dyb; Wed, 28 Feb 2024 11:39:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX0yhRWKUV+d3wQPL+/Eod06zbOJHujdenjYszckm7gpIc5feWcnw4CUDX09F0MvsVVKuC0But2xab3VE3hjBPceK5UKg== X-Google-Smtp-Source: AGHT+IFdGBT9fcOnegK2Fhv6ZclHr8PsNpkwStEKuLpnqc+J+jT1AWnCyrZTLItT6y2eXqd7RdZ1 X-Received: by 2002:a05:620a:460b:b0:787:ec39:8210 with SMTP id br11-20020a05620a460b00b00787ec398210mr46831qkb.52.1709149170594; Wed, 28 Feb 2024 11:39:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149170; cv=pass; d=google.com; s=arc-20160816; b=e4rmRhqJiz8+PWfbxFhiEQumcr1dBr+MPX6b6j7+hfc36qyuytswYnuj9Q5By5VDyD TbHk3swsoSfS+B3YQcSwhdml2kRCsx2IwuRoWmgr8q6Up0YijitvvapnUBAZtJPTN9jw q9son1gv0S1bg3owe3AbSGFPMqncDY3KyBR/UI5mGFzEGEz1xPr4ZvsokMGMd16JWxDr NU4AUffgW6Bf3xJDwQUbG0kQlZ7M9sMoH0jaGUC4kbK6CCbTEIK39Btf6VApbtxP1zkT 1oKjmYKDrnkddI1fLWD6f9MMy5yLjbnTPywErP3vZ6q+a1zJRHF4gDosxL6mRICxV+uK YKjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=lgq21uAVEPa2C3JIU6RomScvjjiMeucDEYgXRa1a1pw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mbmwNV92fUDCO3Uo6HnTRgBi5awyN/l5dsUCi7GHXlqz/h4nOptdqqg3Ds0yQcwIu8 bzDeTFHM2VCf8bJdnvaaZ5A8xBKg4OxGXTs8t2ZAOOaURRgEozDNUw1CD/QTLyxgTktb WNDIo4VdYDhinVt9hemExF57sgSduYRebRUfYYZGdm5HfgvvJdiQlV6eFh8HDcO2SI2U V4BiWDv5ZLTYfl+M6ZMMQ/kRZENvSJK3VsFw1XH2XGEuXHLL1VCj2TJRm23wnML6+kLh /kZPg8VXT4iBjA9/JumeJedD+q40OosH35CrW5HjPIs39V7WQvxeCST5x5/U2kiWISe2 1fLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=X5OZiNzf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x17-20020a05620a099100b00787196ecd3fsi210412qkx.281.2024.02.28.11.39.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=X5OZiNzf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 009B9385829C for ; Wed, 28 Feb 2024 19:39:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 009B9385829C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149170; 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=X5OZiNzfkhD4d/4lVJnBp7+ZjUrV5a5d62ihOPA6Qxk/+lz/oUsKuBp6yYO1N1amN FEnYztLuqE3dHEYdljjpAvnq9a9uFP7VPUW74Wd7pRl75cyAgSInuROx+NqQSAPFCq HIIFbMP0LcpedgVLu5WBMy31/oLBIiYOsVFVgFCM= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501542396363549 X-GMAIL-MSGID: 1792172800508344566 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: 208021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3571730dyb; Wed, 28 Feb 2024 11:46:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAxLkxE8pCtzv/deerBjZkPcV0OFXP+RXgWs1A4hrHWMUBmjUwpxcKMI6lPhrsF1IQ4OgSBeuV40ux+H6j6VGdAQE6Yw== X-Google-Smtp-Source: AGHT+IGSgHzkflxktMIadE2hojWar1mPsr7m8D54o5VE0IQothNd04L6ziB9bOsJY+nnVjcFXSc+ X-Received: by 2002:a05:6214:186:b0:68f:2d21:d62f with SMTP id q6-20020a056214018600b0068f2d21d62fmr57867qvr.40.1709149571652; Wed, 28 Feb 2024 11:46:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149571; cv=pass; d=google.com; s=arc-20160816; b=Au0VA7CPrSmyQORW6bU9FcmRVvVzer0ojqHpzmTho4Em4lQhntyXftX9ISOCyO7xy4 zCyRX9qN+Qco4PksUwdYVEE2fJka6RTVchBnp4a7Wkm6FW5Py1CDSj8/Re337vQ/CAP+ G3AmD416RLarurD9/nMPwHb9LaB1nj4b4HhnncjDJvCNedkNLHVvWZI/7NTfKp2EVGOo CJMc1cAACZp+poL1evII227UjgX3XP2QxTTiSbLp3v1Iisp6uUIfodJLTITDrjwDCUQJ EvPnosP8lzcgaMRChctI4uScwHf1wBSJHzkJH4VaQ/yleRoUfcfAQGhBpDI5gG18Q2Yh XNyw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=SCyVl6CzuGlTr05a3akgmNFWytyOyJCddWqTC9s4CP0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=h1y1xHcuK9ehVCDIejkLLrMd7bgR9ungm9jtbomDR85lU4le7aNB2NTun6LC6WD498 eXRvKvWjliHDj5O3Cd9OadUTLRGfgmrcJEgp7RH3KCOL/NpHYUA8WPSFy6Npj+ZeKuON YYuUm9/d7YSWdbRGZsfWsb16C9oGx3IrmJTmSnsbSI+KsPGqc68cYsVarCvnFVX1ciC0 AIes5zPfMF4s+7E6xYFVCaVvrjkUpivNxsoIt/v29q2qfLqtJzB2kZinWgX5koBUWoFK UtTuLgGN6XsNlqB9w8Fq5UBrFMLBcwcfZKbC6YbZfze3YiGZH/6q+SKQdIWivyeQ+hsj DadA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e0OuxS7H; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jv1-20020a05621429e100b0068cfba18abbsi202500qvb.418.2024.02.28.11.46.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:46:11 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e0OuxS7H; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 362D83858285 for ; Wed, 28 Feb 2024 19:46:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 362D83858285 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149571; 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=e0OuxS7HkLAvXGCY1ZDzKjpOPrxd9S6HCxICLD+Dx/l/wFn3A4RXpgFndGRBrLTPa ibDyb4YsC/XNfezAowZIa1ju/XbVjOBai9FVZDocfj0b3Z1Wnp6dqmEVt1yWBR5TKX ni4ipgvFHtI3xYQXPGBUDwGa81N86z0/XXHAnMkA= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501363663289276 X-GMAIL-MSGID: 1792173221676986798 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: 208015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3570752dyb; Wed, 28 Feb 2024 11:43:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzi4RbJXFwdCukbaaWN5cGKC/uuxkIIsS9gKFQq/Nl1znjS12NkHIt57dtJBAVheBhmll8yzrwkeUlzRElQO4k+KwbrQ== X-Google-Smtp-Source: AGHT+IHLvfUMgY7hxwAfv3Xg39DnUuEeLbSk9X4xaeuJ2JstNpfvZGzKMls8KAJDu5i67gxnedxn X-Received: by 2002:aca:918:0:b0:3c1:86bd:ca8 with SMTP id 24-20020aca0918000000b003c186bd0ca8mr5622592oij.13.1709149430988; Wed, 28 Feb 2024 11:43:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149430; cv=pass; d=google.com; s=arc-20160816; b=A1oGUS7iQ3x3hfTvOfbdJxHIPtZAQv6OAtoPRrEaR9B4DkBBu6M2up5QmAfps+tb/S a7DG17OtMPRrQpu4qhrX/n1Te9aFnTUXFUcYi3LD/7bOVF5A4fdt50U0rvOm1DiIdixX pkKDdgA6RdQ/k/g8klrrAef6IFSVeDvf7TnYsK+938vUT8ZmiQwd18aMp5IOlobf0uCQ /beVb5ozL+8Bj82NkWGcwl1Dl/8CNTZHvIl9Ml2SmGvjiEJg2eb5TYctzxmS9wZ2I9VR lgWlZN53vLS4/W6xeLbmkY7vgN4lXayKWQD9nPrStHdRSBfObDc1abmGFFyVn52rNMna h4aA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=RowP20RdImmrDFoNCo5/paRHGOcLwoYIvBOx+g7nxgg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=sXACppyQrD8uoWpBr7/IIKVS0JFzecS2gRMg6eEczczAa06wyxi/xZXaLQ1u+8e7OO 8foYNXvu5HQTEtddP952ItKlpcFGOZEL+73Tuy2fdegOaeMyb3EgvkHUrUvp5X0JW8HW zGX1MXTMtH7UlyN/5mE1u5TZFDHcGHG6o5lDjMBoroVDKA/Fdy3Xr9CFn6LaU4WKd1U/ PGPsIPODQwjr8thZqtVFrUX2FINdDXjRqsSq6fLR9+/lNgBl/VCWv9pO3O6YuPzfqxYc gzPrUXjzLpiBIUN4goGiorVK/CozNwfdZZOFzh8dMd4nvwbqNoZK69i1WdVF0TtF8tQE xMEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wPzcecOc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e8-20020a0562140d8800b0068f5fe88aa6si225113qve.34.2024.02.28.11.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:43:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wPzcecOc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 985AF3858029 for ; Wed, 28 Feb 2024 19:43:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 985AF3858029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149430; 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=wPzcecOctf2b9SNdrwkVj2+ywhpd8e96BwaujgLUmJXi1hjF7S1Wr/jvCJQHX/OCy 2C9vs/AFD7gB0NYcNApevTCqQsK0UjDm/g2UyjmoqDFQ8rbMGgtt0wFsfvL4HW6HfK 8fPE4Cxh/7q85yjKwWTt/Zez7H9X7UFYmPgCjq2A= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791500994872286405 X-GMAIL-MSGID: 1792173073559414470 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: 207982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3565706dyb; Wed, 28 Feb 2024 11:33:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW3Ra4FIQ5TwAmlBYLtnzpMTrtQgQKl15F+nAgvczFf6LYdHIjww/VQhiiOeP8ixTYHFWqkqxCv0pCYgpkAQwO5d4x1sQ== X-Google-Smtp-Source: AGHT+IHfWK4AfApH8iFtfOeovjMNNcchhAtBc/YtiArODMs2I/R0+LpeqHA635HOvpcPJQSI8iER X-Received: by 2002:ad4:44a7:0:b0:690:696:6031 with SMTP id n7-20020ad444a7000000b0069006966031mr34791qvt.57.1709148787445; Wed, 28 Feb 2024 11:33:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709148787; cv=pass; d=google.com; s=arc-20160816; b=xBrYd28F77TZAqgO+bMU3qAX1cCUrnvDj0NO+R+3Tq8mSgGdpgKj1tuOb6O/D9vwMR IJZrJLpUQ+bYWRBO8LKVsqBjyh9mawUjxvLa0HZhfFmeXpnykishnllYzO+m98rwrYD8 JhpidqfIA4uSCOxtPYOMSAGlCQiwcrD85+0xcF7VY+5a+HwzXdiFmJxCJTBQL0OvwzMs ZDQAzhvhjftkwjaKy+v6f4mnr90DGSPVE0OjLYAXHIGY4ttQijcVI+1ID6pSACpt7Zgr I6jKD8laMAo90UIai7ym3qIfJbRwld+zceUAlaIQfsVdm/iKs/JEmT4ofNmpDAyJiSue Si1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=54vhQvY9u89chF+BfVzqqGMOWm35HeE38x6xc0xZHIY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=THFJC1Z46AoVwVWymlB46WFGKM22Ei9lrVBSUyQcgWrmxsNu6cjsDl7G2ovGK1fj4U re9TKKUYMQWnpjq0QMIln7D0nphhsVhvG8Ea+b18tq+vGYhyiK7ZtrhYfG0of6n2XLG5 XQ0trrEkrnv/IwgjlqSwFtZgD26ib47jIL/RVS8m0ChEG5ZgITSirLVmoCTF99d40pYZ W8W2Ro+HbkfTjrl8I6PgtVwFDNsXm2V0EFK5JqVXXdossX08aHeYP2U/nfZULuxqaY0x zl/bOwzOmx+obxMKgNCA8Q70opXDiPtpfu6tttU2BA29WwrOUBzESCc3x9Mw/q/DXGvp xgqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FdUH8CGl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id jt15-20020a05621427ef00b0068ffe744a27si201992qvb.63.2024.02.28.11.33.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FdUH8CGl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 059D8385828C for ; Wed, 28 Feb 2024 19:33:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 059D8385828C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709148787; 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=FdUH8CGlmqzNgB/Qo51QLLHAGWh6QQZcIjcrpKORQ4yp8245WmZMEWaWtHqUSV9/3 LxZ4rbcCZLr3Llfz/RrkehYXyU3RuUviSgNVQLJCFkdcLoFzYc1Fcm+zEHJn6W9F7h fMAf0t3HxxqghiM1mLACu9SemXlQxwMAF1fKMQyw= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791501072886437442 X-GMAIL-MSGID: 1792172399100528702 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: 208020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3571614dyb; Wed, 28 Feb 2024 11:45:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWVUVdZ3ZfawKVDbC3esQPmmixyH2mfigNQHXcReh8WbW0tMhfEw+B3+yit+g8ZJThvolIEcHUa9zesJqmxx9+aNQ4aVA== X-Google-Smtp-Source: AGHT+IEESZNfLgnh2T+7vL0kRJPHoiw0d/MCUCwntrVmcfCDBrzMJNNwydeVwyHo4fhIIFO7/5dp X-Received: by 2002:a05:620a:454f:b0:787:9862:b940 with SMTP id u15-20020a05620a454f00b007879862b940mr5533126qkp.35.1709149557499; Wed, 28 Feb 2024 11:45:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709149557; cv=pass; d=google.com; s=arc-20160816; b=Zh+fqpjpWSQTBwGmqbJlJaYVXtqI4NUbf7Y71d2+7c+UlU9R+2bbvTlcHITYtDgnIW +DMT9wNLM90PMtzkwKsIVaR8ExEAgV3ykNbuJR0ntA8olUJcmi/VOX0+CoNugVxJLRtX GI4DWoacykmybmrzw8ALiRwXvG9wgBbFr/8wCGtZwGpoA1YBdBdsuMRwG1/Ze2deqe8l Xo9z1qWOnEfeuqqv6b8qmB9zawrgM/LEbpza7lOYxUSO2vbZN68ArML3ItxDCHcPl3Pb tVM1peFAlJrYpBLRHvH/mxTwzb4SXYqEAoF5PZerFlXbEeS1cQYtncrItSiIzd+KGMk4 zIag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=fbQXEZhV+pEH4pI+jov70pRPAIFo2gBWL0kSdx7WUSg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=04GLifrZD2Zfp6kg2I2uDVARBIRxARz2h5Z0X6RO094/D2CdTJvS2jnhWGwR8eRFwf P6i+8uQ9slBUAa8Xa0bqsw8WRrw4tpW+VgI1MFYEgnhv9Od1/MKmBK2nG5lYudGoPuKB FbsYLNJEdBJWi6ru0/4BUsXXxmFGVsUSJYPQSGz8udUaciNa4u24TQmAdFjONmEGXwum NLlNsVb7GcMSsNTTqeiwPbi35N5jcRBRh1tjqz9iGHtuW+oDdA0yzEUytcGXhP26P5tC vLn32srv0NT7zYpaE3FG2PM1+R5Sevzfj/9RzYGGbSua+WW1f5P4cyd09HFZSaQYS2o1 ASzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mr+QfnGC; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p13-20020a05620a056d00b00787f536b70dsi187752qkp.665.2024.02.28.11.45.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 11:45:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mr+QfnGC; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2211B385829B for ; Wed, 28 Feb 2024 19:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2211B385829B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709149557; 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=mr+QfnGCnAeaA7zUznK4VriBLXL4DsA2piYt8GDoRgza4PqqPPf5IB7+jEuyd9D2+ Q3MtPTtf4RHl4Lk6/1asx47G/KpzOPFpUekQ+IJ2/AkrMD5SNOLkdXw1fqa7/aoJGh ivrm9lZPuxKfDdgX9yRlQw97rKgSftgU2mCZLdA0= 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791498019344210488 X-GMAIL-MSGID: 1792173206632479448 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