From patchwork Tue Oct 17 11:36:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074466vqb; Tue, 17 Oct 2023 04:49:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTbeCiZ+zfvKON47pglTU4Dnpor3EaxZ9O3UQPbRoumfkc4aiqZfYbuy09gYAd42WtVVEb X-Received: by 2002:a05:622a:11cb:b0:412:27a1:88d9 with SMTP id n11-20020a05622a11cb00b0041227a188d9mr2471928qtk.26.1697543394297; Tue, 17 Oct 2023 04:49:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543394; cv=pass; d=google.com; s=arc-20160816; b=0cW9J8xsEgU/m0n8cwnRMYYdJKOUGrFv0HhcyoDfM/gaoY/Ki34av+U0K4lwpRN1Jb mQsDkI+CJOHRdTrc3gpNJEzz384z98rJTlKeLV/xwZTsgH+ISWTKVXIrMULFdj70pnSc BZIbMN34ZV9ro4bSwOhiiW6PYlgst8GcNMvUgUpRsBdLkndMxFPk7ZmUY8g2a7PhCye/ OPq0xBRpPPFD4zIiwelKfR2NwBqIVPeg8JrjWdzVJWxSIVSKPJTOQtrEyLV0k+wzdUR5 nBkCE4XNYHVvxwTrozdGTYYPDBy4oAz8jxECXZT+P4yxp2WAfufKrY34bv7TOmS//gQA U4WQ== 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=zFrtC55StlM8iAKZ2nRsIs6qaxrdLE2Y5pqcjjhW/vU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HpQPa3+tdLE40KzYPGYicZVzGi94LD/I2IkTD8JiaRTnbAAOLuG51phv3eeJ+FBZpu UlqTAlgN+sV/vIrwhjVl/tD71VqcQJ48kieAuplG1zqV916rRw8aniB4sVMHpCu1vYCC qO8ShZ3Yhaq9M7ipUMNTDY301s7xjcVL2Y6kgQgLakYlygfSQlx10O7ghj2kqvVOKJTU vWevkzHn4hKDyepPfgGVNzilPpEuosIGbOeKYZYpI17/Ak9iVHNx1RgZ1ERu03nkhwAh vAkeSVnkAHvSROacBEFl0HKalu17oOCimFQo567Z0E3CdA3bxLsNlgvP5NS/LCYTiswI XgZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sf5GXccG; 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 18-20020ac85952000000b00417ce695031si975200qtz.258.2023.10.17.04.49.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:49:54 -0700 (PDT) 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=sf5GXccG; 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 05AF538AA243 for ; Tue, 17 Oct 2023 11:48:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05AF538AA243 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543303; bh=zFrtC55StlM8iAKZ2nRsIs6qaxrdLE2Y5pqcjjhW/vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=sf5GXccGKW/rxM1ETyRkoDQ8mPzWPBXlcRX9f0ac8NHqHwVYvj6OmNuxALmiGt0LO +b701oYKzhC/isJaVPoXwU81GoTrofov3oEiy4AQ7mDz4kFvX86ddqUlVNRF+Dlan5 LL5QvHg7Z+WX7C9wgwV1cieu2LCu/sfmTO7tKePQ= 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 ECFFF385C6ED; Tue, 17 Oct 2023 11:40:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECFFF385C6ED 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 ECFFF385C6ED 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=1697542805; cv=none; b=r8HlXlyD9hFWfqgZFOaS/MvAdF3elaPhw7N9n5Otb1mrdPpIEjt3p4hLywmyG7Iz+RsAGH/YLQYjPDIbgRpbgpVAdlOQcRVHyBLFK3MfNw/ZQRUrPzKToNcBp74xYNg1wYuRhWlhoxNNCOdyHuyGl6eKIjnsRWOSBe9OSzqL4Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542805; c=relaxed/simple; bh=7TvwmHW6fih2o51F4woPX+Nt/mu8wQlnBx0TFFC+I1g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bBZgxIjcd/4lODrn+zNOvKE4TIgtsaIbA3AACYpBeHw2qKV1/ihymh+WM9zyaYJTy2U5yaKtxYQL8TGKaROOCTKJYg6jjbKZLzkRAKuqTCrRJI5F5sTmn9hHcvlDaFlh3hqo4uZkOfcyEf6hPr2tm/R/9mKlbgisMDQRMpZM7NU= 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 39HBYKil023945; Tue, 17 Oct 2023 11:40:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rms90-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:40:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBdkCO004843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:39:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG4020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:39:46 -0700 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 v22 01/31] c++: Sort built-in traits alphabetically Date: Tue, 17 Oct 2023 04:36:22 -0700 Message-ID: <20231017113822.677344-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SitrHrSLY69fCE_fxFIc2jo1qItLmJio X-Proofpoint-GUID: SitrHrSLY69fCE_fxFIc2jo1qItLmJio X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003261967306099 X-GMAIL-MSGID: 1780003261967306099 This patch sorts built-in traits alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in traits alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 68 ++++++++--------- gcc/cp/cp-trait.def | 10 +-- gcc/cp/semantics.cc | 94 ++++++++++++------------ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 70 +++++++++--------- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 64b64e17857..41fe2812ac4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3703,18 +3703,36 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_HAS_TRIVIAL_DESTRUCTOR: inform (loc, " %qT is not trivially destructible", t1); break; + case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: + inform (loc, " %qT does not have unique object representations", t1); + break; case CPTK_HAS_VIRTUAL_DESTRUCTOR: inform (loc, " %qT does not have a virtual destructor", t1); break; case CPTK_IS_ABSTRACT: inform (loc, " %qT is not an abstract class", t1); break; + case CPTK_IS_AGGREGATE: + inform (loc, " %qT is not an aggregate", t1); + break; + case CPTK_IS_ASSIGNABLE: + inform (loc, " %qT is not assignable from %qT", t1, t2); + break; case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not default constructible", t1); + else + inform (loc, " %qT is not constructible from %qE", t1, t2); + break; + case CPTK_IS_CONVERTIBLE: + inform (loc, " %qT is not convertible from %qE", t2, t1); + break; case CPTK_IS_EMPTY: inform (loc, " %qT is not an empty class", t1); break; @@ -3730,6 +3748,18 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_NOTHROW_ASSIGNABLE: + inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); + break; + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not nothrow default constructible", t1); + else + inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); + break; + case CPTK_IS_NOTHROW_CONVERTIBLE: + inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + break; case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: inform (loc, " %qT is not pointer-interconvertible base of %qT", t1, t2); @@ -3749,50 +3779,20 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIAL: inform (loc, " %qT is not a trivial type", t1); break; - case CPTK_IS_UNION: - inform (loc, " %qT is not a union", t1); - break; - case CPTK_IS_AGGREGATE: - inform (loc, " %qT is not an aggregate", t1); - break; - case CPTK_IS_TRIVIALLY_COPYABLE: - inform (loc, " %qT is not trivially copyable", t1); - break; - case CPTK_IS_ASSIGNABLE: - inform (loc, " %qT is not assignable from %qT", t1, t2); - break; case CPTK_IS_TRIVIALLY_ASSIGNABLE: inform (loc, " %qT is not trivially assignable from %qT", t1, t2); break; - case CPTK_IS_NOTHROW_ASSIGNABLE: - inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); - break; - case CPTK_IS_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not default constructible", t1); - else - inform (loc, " %qT is not constructible from %qE", t1, t2); - break; case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not trivially default constructible", t1); else inform (loc, " %qT is not trivially constructible from %qE", t1, t2); break; - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not nothrow default constructible", t1); - else - inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); - break; - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: - inform (loc, " %qT does not have unique object representations", t1); - break; - case CPTK_IS_CONVERTIBLE: - inform (loc, " %qT is not convertible from %qE", t2, t1); + case CPTK_IS_TRIVIALLY_COPYABLE: + inform (loc, " %qT is not trivially copyable", t1); break; - case CPTK_IS_NOTHROW_CONVERTIBLE: - inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + case CPTK_IS_UNION: + inform (loc, " %qT is not a union", t1); break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..0e48e64b8dd 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,14 +84,14 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) -/* FIXME Added space to avoid direct usage in GCC 13. */ -DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) - DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) -DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) -DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) +DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) +DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) + +/* FIXME Added space to avoid direct usage in GCC 13. */ +DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) /* These traits yield a type pack, not a type, and are represented by cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 2a0cf963e91..144cb440fa3 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12090,15 +12090,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && classtype_has_nothrow_assign_or_copy_p (type1, true)))); - case CPTK_HAS_TRIVIAL_ASSIGN: - /* ??? The standard seems to be missing the "or array of such a class - type" wording for this trait. */ - type1 = strip_array_types (type1); - return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE - && (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) - && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); - case CPTK_HAS_NOTHROW_CONSTRUCTOR: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) @@ -12107,17 +12098,26 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && maybe_instantiate_noexcept (t) && TYPE_NOTHROW_P (TREE_TYPE (t)))); - case CPTK_HAS_TRIVIAL_CONSTRUCTOR: - type1 = strip_array_types (type1); - return (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); - case CPTK_HAS_NOTHROW_COPY: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) || (CLASS_TYPE_P (type1) && classtype_has_nothrow_assign_or_copy_p (type1, false))); + case CPTK_HAS_TRIVIAL_ASSIGN: + /* ??? The standard seems to be missing the "or array of such a class + type" wording for this trait. */ + type1 = strip_array_types (type1); + return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE + && (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) + && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); + + case CPTK_HAS_TRIVIAL_CONSTRUCTOR: + type1 = strip_array_types (type1); + return (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); + case CPTK_HAS_TRIVIAL_COPY: /* ??? The standard seems to be missing the "or array of such a class type" wording for this trait. */ @@ -12131,18 +12131,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); - case CPTK_HAS_VIRTUAL_DESTRUCTOR: - return type_has_virtual_destructor (type1); - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: return type_has_unique_obj_representations (type1); + case CPTK_HAS_VIRTUAL_DESTRUCTOR: + return type_has_virtual_destructor (type1); + case CPTK_IS_ABSTRACT: return ABSTRACT_CLASS_TYPE_P (type1); case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ASSIGNABLE: + return is_xible (MODIFY_EXPR, type1, type2); + case CPTK_IS_BASE_OF: return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) @@ -12151,6 +12154,12 @@ 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_CONSTRUCTIBLE: + return is_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_CONVERTIBLE: + return is_convertible (type1, type2); + case CPTK_IS_EMPTY: return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); @@ -12166,6 +12175,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: + return is_nothrow_xible (MODIFY_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + return is_nothrow_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONVERTIBLE: + return is_nothrow_convertible (type1, type2); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12196,24 +12214,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; - case CPTK_IS_ASSIGNABLE: - return is_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_CONSTRUCTIBLE: - return is_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_ASSIGNABLE: - return is_nothrow_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - return is_nothrow_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_CONVERTIBLE: - return is_convertible (type1, type2); - - case CPTK_IS_NOTHROW_CONVERTIBLE: - return is_nothrow_convertible (type1, type2); - case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12326,9 +12326,9 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ABSTRACT: case CPTK_IS_EMPTY: case CPTK_IS_POLYMORPHIC: - case CPTK_IS_ABSTRACT: case CPTK_HAS_VIRTUAL_DESTRUCTOR: if (!check_trait_type (type1, /* kind = */ 3)) return error_mark_node; @@ -12348,12 +12348,12 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - case CPTK_IS_TRIVIALLY_ASSIGNABLE: - case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_TRIVIALLY_ASSIGNABLE: + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: if (!check_trait_type (type1) @@ -12372,8 +12372,8 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: - case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_UNION: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12436,25 +12436,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { - case CPTK_UNDERLYING_TYPE: - return finish_underlying_type (type1); - case CPTK_REMOVE_CV: return cv_unqualified (type1); - case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return type1; + return cv_unqualified (type1); - case CPTK_REMOVE_CVREF: + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return cv_unqualified (type1); + return type1; case CPTK_TYPE_PACK_ELEMENT: return finish_type_pack_element (type1, type2, complain); + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..2223f08a628 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,9 +8,21 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif @@ -44,12 +56,21 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_convertible) +# error "__has_builtin (__is_convertible) failed" +#endif #if !__has_builtin (__is_empty) # error "__has_builtin (__is_empty) failed" #endif @@ -65,6 +86,15 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_convertible) +# error "__has_builtin (__is_nothrow_convertible) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif @@ -98,51 +128,21 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif -#if !__has_builtin (__underlying_type) -# error "__has_builtin (__underlying_type) failed" -#endif -#if !__has_builtin (__is_assignable) -# error "__has_builtin (__is_assignable) failed" -#endif -#if !__has_builtin (__is_constructible) -# error "__has_builtin (__is_constructible) failed" -#endif -#if !__has_builtin (__is_nothrow_assignable) -# error "__has_builtin (__is_nothrow_assignable) failed" -#endif -#if !__has_builtin (__is_nothrow_constructible) -# error "__has_builtin (__is_nothrow_constructible) failed" -#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif -#if !__has_builtin (__builtin_is_constant_evaluated) -# error "__has_builtin (__builtin_is_constant_evaluated) failed" -#endif -#if !__has_builtin (__builtin_source_location) -# error "__has_builtin (__builtin_source_location) failed" -#endif -#if !__has_builtin (__builtin_is_corresponding_member) -# error "__has_builtin (__builtin_is_corresponding_member) failed" -#endif -#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) -# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" -#endif -#if !__has_builtin (__is_convertible) -# error "__has_builtin (__is_convertible) failed" -#endif -#if !__has_builtin (__is_nothrow_convertible) -# error "__has_builtin (__is_nothrow_convertible) failed" -#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif -#if !__has_builtin (__remove_cvref) -# error "__has_builtin (__remove_cvref) failed" +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" #endif From patchwork Tue Oct 17 11:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4071700vqb; Tue, 17 Oct 2023 04:43:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFELSDYNVSI61UKTTeNTNpnuCpxhLGValjxTKTaXctbRQgfrlFU3lhsSGv62DXf9fSbQDBI X-Received: by 2002:a67:e14c:0:b0:457:d3d1:494b with SMTP id o12-20020a67e14c000000b00457d3d1494bmr1995870vsl.23.1697543031800; Tue, 17 Oct 2023 04:43:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543031; cv=pass; d=google.com; s=arc-20160816; b=ublB49prKtZ8AKD3eMBIyDH1stlCAcK81+4lQnpaYMaCZHzD30kQtkvC4cMpZuY0lp gL4MWG49SZ+tHnAFvgY1ptHcB97UajVo7ioaa2xEJ2RGXNgqQ+KVXM//rsAAggv5uU/q 5Q4doFbNjqR5caRtd4SoHHKakaAjkKwGyssYZjlmrPcwR3ytUWSKIx2c0itDG4HY0AOj b5tNdEwSgklBkz1RpmAL4A2fj2XnOAd0Irj1pcs3LdapqGlanbC7j1QE9lYvAdP5Pq0V 9e/hml48v8JET1rQL92LBR+q6UAQVnzZLDuqvWp/Vq7Je9k82U6R/2LtJUt5T6rC8llo ZJHQ== 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=XzQ6JaLHSfbRkzy9sMHe6fCo10/gBbC7RRRFQ9rcaoo=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=vTKZsFUgGCgta+tce5Xh59rKDCqIpYP8B8Z/wE6eALw1uNI8Jnv6O9r4EuulxZb6Dp ACrmdhvdT6y3HKSu85UMkjlsB7KBhkz5+tTDSi4kYf4hk3B7SzoXH3v/5JDHncGIGrjF L05tTgf7Sw8LkOi2Gxw5o9DQdAp+fyvAY1ygCWwHFcFE0NJ3baKRLHoKHa7P1AYoHdNw 4M2hCRb/ql/MeBbq80bZsL6/b5DJo5/bSSURWmfYK7z6daNoP3RY6gxwgWNgv+e2WCuc o0NEpPfqNRAkpEP6rwmr2n0jKG7170jqhrFWCw2ZvTF+2cxucBF4zPHs+/tSQwN/ScEG gvjw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="WfE6Y9a/"; 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 b19-20020ac85bd3000000b0040e4daf543dsi950498qtb.624.2023.10.17.04.43.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:43:51 -0700 (PDT) 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="WfE6Y9a/"; 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 77D803861849 for ; Tue, 17 Oct 2023 11:42:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77D803861849 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542954; bh=XzQ6JaLHSfbRkzy9sMHe6fCo10/gBbC7RRRFQ9rcaoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WfE6Y9a/dMxAPpI7rRFDIF10hKcvI+LK53P/cSp806i1bOVGCyhLmoUAV4RAqIAIO 79VnmG+mvlvCsZLGG2LNuHF55pmYBUOgkoMrGbPFBCzHcpIg9m8w3U0V6yUtC2kpjm 3RO4HjFSLgoBlfb2OtXOBpYHjJt+HlnwXN49Ba7k= 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 D9D113830B47; Tue, 17 Oct 2023 11:40:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9D113830B47 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 D9D113830B47 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=1697542852; cv=none; b=afe9ulQ/LFHWes55pbAGsG94J1P+RnXahFRRrXUTSO03f4RqSGsszp0yR0DfPf3/pjxipzXsFaPMB6v1adiTtlVSPhN49Syru6o4Hi3Z8TOo9kAHVMtdIlIim3gv4xQ8EvwQpV5WpwPcV/RI0UcU8c5akdKd+zBJXM7/wWVyTHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542852; c=relaxed/simple; bh=a9doAL8xaU26Jq7Wrb8cklSUyV+ncv7L4Jw4Kidz8BU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OwN8A4420AYPoCjUTuOMHsWk7n49h1q3FnbW1RQYAo3qpeh6NVI+/HHMyt2I006qxqYs3ybPtbQ6dazamBseUuiGTLhLPuO2aN3xZYQOIejlyy0KgS67M0T2xRArgzAI1uRr0dCUa1JDwvNAMm/kZQ67kcisHZ3tdhXkmgQZQkE= 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 39HBPXjF022035; Tue, 17 Oct 2023 11:40:49 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbau3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:40:49 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBeVq8000325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:40:31 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG5020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:40:31 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Patrick Palka Subject: [PATCH v22 02/31] c-family, c++: Look up built-in traits via identifier node Date: Tue, 17 Oct 2023 04:36:23 -0700 Message-ID: <20231017113822.677344-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: eWr5QCD3d_kG6HrlyXTsJ8LakhKvUmUH X-Proofpoint-ORIG-GUID: eWr5QCD3d_kG6HrlyXTsJ8LakhKvUmUH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779868979596920251 X-GMAIL-MSGID: 1780002881603483155 Since RID_MAX soon reaches 255 and all built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses the identifier node to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait kind. * cp-tree.h (enum cp_trait_kind): Set its underlying type to addr_space_t. (struct cp_trait): New struct to hold trait information. (cp_traits): New array to hold a mapping to all traits. (num_cp_traits): New variable to hold the size of cp_traits. (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (init_cp_traits): New function to set cik_trait and IDENTIFIER_CP_INDEX for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_traits): Define its values, declared in cp-tree.h. (num_cp_traits): Define its value, declared in cp-tree.h. (cp_lexer_lookup_trait): New function to look up a built-in trait by IDENTIFIER_CP_INDEX. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 --- gcc/c-family/c-common.h | 5 -- gcc/cp/cp-objcp-common.cc | 8 +-- gcc/cp/cp-tree.h | 33 ++++++++--- gcc/cp/lex.cc | 21 +++++++ gcc/cp/parser.cc | 120 +++++++++++++++++++++++++------------- 6 files changed, 129 insertions(+), 65 deletions(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..21fd333ef57 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,13 +508,6 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, - /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..051a442e0f4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..b1adacfec07 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -421,6 +421,10 @@ names_builtin_p (const char *name) } } + /* Check for built-in traits. */ + if (IDENTIFIER_TRAIT_P (id)) + return true; + /* Also detect common reserved C++ words that aren't strictly built-in functions. */ switch (C_RID_CODE (id)) @@ -434,10 +438,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index efcd2de54e5..81a5c06a574 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1226,7 +1226,7 @@ enum cp_identifier_kind { cik_simple_op = 4, /* Non-assignment operator name. */ cik_assign_op = 5, /* An assignment operator name. */ cik_conv_op = 6, /* Conversion operator name. */ - cik_reserved_for_udlit = 7, /* Not yet in use */ + cik_trait = 7, /* Built-in trait name. */ cik_max }; @@ -1271,9 +1271,9 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is for any operator name (including - conversions). Value 4, 5, 6 or 7. */ + conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE)) + (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ @@ -1286,12 +1286,18 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion - operator. Value 7. */ + operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ & (!IDENTIFIER_KIND_BIT_0 (NODE))) +/* True if this identifier is the name of a built-in trait. */ +#define IDENTIFIER_TRAIT_P(NODE) \ + (IDENTIFIER_KIND_BIT_0 (NODE) \ + && IDENTIFIER_KIND_BIT_1 (NODE) \ + && IDENTIFIER_KIND_BIT_2 (NODE)) + /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ (IDENTIFIER_OVL_OP_P (NODE) \ @@ -1375,16 +1381,27 @@ struct GTY (()) tree_argument_pack_select { int index; }; -/* The different kinds of traits that we encounter. */ - -enum cp_trait_kind -{ +/* The different kinds of traits that we encounter. The size is limited to + addr_space_t since a trait is looked up by IDENTIFIER_CP_INDEX. */ +enum cp_trait_kind : addr_space_t { #define DEFTRAIT(TCC, CODE, NAME, ARITY) \ CPTK_##CODE, #include "cp-trait.def" #undef DEFTRAIT }; +/* The trait type. */ +struct cp_trait { + const char *name; + cp_trait_kind kind; + short arity; + bool type; +}; + +/* The trait table. */ +extern const struct cp_trait cp_traits[]; +extern const addr_space_t num_cp_traits; + /* The types that we are processing. */ #define TRAIT_EXPR_TYPE1(NODE) \ (((struct tree_trait_expr *)TRAIT_EXPR_CHECK (NODE))->type1) diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..872ca970545 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" static int interface_strcmp (const char *); +static void init_cp_traits (void); static void init_cp_pragma (void); static tree parse_strconst_pragma (const char *, int); @@ -283,6 +284,25 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + + for (unsigned int i = 0; i < num_cp_traits; ++i) + { + id = get_identifier (cp_traits[i].name); + IDENTIFIER_CP_INDEX (id) = cp_traits[i].kind; + set_identifier_kind (id, cik_trait); + } + + /* An alias for __is_same. */ + id = get_identifier ("__is_same_as"); + IDENTIFIER_CP_INDEX (id) = CPTK_IS_SAME; + set_identifier_kind (id, cik_trait); +} + static void init_cp_pragma (void) { @@ -324,6 +344,7 @@ cxx_init (void) input_location = BUILTINS_LOCATION; init_reswords (); + init_cp_traits (); init_tree (); init_cp_semantics (); init_operators (); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 59b9852895e..ece238c2072 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,6 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -279,6 +285,21 @@ static FILE *cp_lexer_debug_stream; sizeof, typeof, or alignof. */ int cp_unevaluated_operand; +/* The trait table, declared in cp-tree.h. */ +const cp_trait cp_traits[] = +{ +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + { NAME, CPTK_##CODE, ARITY, (TCC == tcc_type) }, +#include "cp-trait.def" +#undef DEFTRAIT +}; +const addr_space_t num_cp_traits = ARRAY_SIZE (cp_traits); + +/* The trait table cannot have more than 255 (addr_space_t) entries since + the index is retrieved through IDENTIFIER_CP_INDEX. */ +static_assert(num_cp_traits <= 255, + "cp_traits array cannot have more than 255 entries"); + /* Dump up to NUM tokens in BUFFER to FILE starting with token START_TOKEN. If START_TOKEN is NULL, the dump starts with the first token in BUFFER. If NUM is 0, dump all the tokens. If @@ -1167,12 +1188,6 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_CONSTEVAL: return true; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - return true; - default: if (keyword >= RID_FIRST_INT_N && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS @@ -1182,6 +1197,44 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } +/* Look ups the corresponding built-in trait if a given token is + a built-in trait. Otherwise, returns nullptr. */ + +static const cp_trait * +cp_lexer_lookup_trait (const cp_token *token) +{ + if (token->type == CPP_NAME && IDENTIFIER_TRAIT_P (token->u.value)) + return &cp_traits[IDENTIFIER_CP_INDEX (token->u.value)]; + + return nullptr; +} + +/* Similarly, but only if the token is an expression-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_expr (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && !trait->type) + return trait; + + return nullptr; +} + +/* Similarly, but only if the token is a type-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_type (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && trait->type) + return trait; + + return nullptr; +} + /* Return true if the next token is a keyword for a decl-specifier. */ static bool @@ -1190,6 +1243,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); + if (cp_lexer_lookup_trait_type (token)) + return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -2854,7 +2909,7 @@ static void cp_parser_late_parsing_default_args static tree cp_parser_sizeof_operand (cp_parser *, enum rid); static cp_expr cp_parser_trait - (cp_parser *, enum rid); + (cp_parser *, const cp_trait *); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6029,12 +6084,6 @@ cp_parser_primary_expression (cp_parser *parser, case RID_OFFSETOF: return cp_parser_builtin_offsetof (parser); -#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_EXPR - return cp_parser_trait (parser, token->keyword); - // C++ concepts case RID_REQUIRES: return cp_parser_requires_expression (parser); @@ -6073,6 +6122,9 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: + if (const cp_trait* trait = cp_lexer_lookup_trait_expr (token)) + return cp_parser_trait (parser, trait); + /* FALLTHRU */ case CPP_SCOPE: case CPP_TEMPLATE_ID: case CPP_NESTED_NAME_SPECIFIER: @@ -11041,28 +11093,13 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, const cp_trait* trait) { - cp_trait_kind kind; + const cp_trait_kind kind = trait->kind; tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; - - switch (keyword) - { -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: \ - kind = CPTK_##CODE; \ - binary = (ARITY == 2); \ - variadic = (ARITY == -1); \ - type = (TCC == tcc_type); \ - break; -#include "cp-trait.def" -#undef DEFTRAIT - default: - gcc_unreachable (); - } + const bool binary = (trait->arity == 2); + const bool variadic = (trait->arity == -1); + const bool type = trait->type; /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -20089,20 +20126,21 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - type = cp_parser_trait (parser, token->keyword); + default: + break; + } + + /* If token is a type-yielding built-in traits, parse it. */ + const cp_trait* trait = cp_lexer_lookup_trait_type (token); + if (trait) + { + type = cp_parser_trait (parser, trait); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, /*type_definition_p=*/false); return type; - - default: - break; } /* If token is an already-parsed decltype not followed by ::, From patchwork Tue Oct 17 11:36:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075393vqb; Tue, 17 Oct 2023 04:52:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEciLjAU+SwYkNHVEJs8iANDam5f4ktABrZtlt8N1LlUxFdauK4rbRiMdSiwSqC2GrsGEt8 X-Received: by 2002:a0d:db0e:0:b0:5a7:db27:7794 with SMTP id d14-20020a0ddb0e000000b005a7db277794mr2084965ywe.25.1697543525083; Tue, 17 Oct 2023 04:52:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543525; cv=pass; d=google.com; s=arc-20160816; b=UZLGkv6kYqOep9M+1s5y3XG9/5Rzd6KXfXGy/GsMri8acAZYS/Sd5nUN5FV8cbJDtT h3ReK8tMSh2jcUZ8vkyn1iDJ70au+RxNF8ZYxsKsqzdbsLvViyxw0V3fuB8sXRc5dlxc RcFHkjc/guhlb81T6ObG8DnVPQdaqvWePvS2SYn2Xh+RPrHaR/6p6DHLJ8woFO/DKwmd bIqSIvK3sPimDzOUfGpYy4AF7C2YO3ogPKBjAd8klGMecSQiJvJ5V3H1GzhIqaiLtlE/ PrCimf+riALdLH1lsA7VDhawHUHog6eYquQlV9jK6liw0QT0OK75xxatskYfJaWKdCls eJEg== 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=12dNqlgpFeavMSJPZSk02QTDoCt42Gr025LrayzUMxc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=gki/KT380SH/ARVaSyxCyCCmMnH0GvgyJTvkFRyUXGTuc90CTPW2T9FwGIOEZu2Oml aB31prZPa9IDt0oFhvBI7329LSshmml5QWPuok7p49Vz/pOEXEsVNBaOKcVvWhUxKuvz +sjjm9LuWarDMpB0wNdIQ10khwoN0FeQL+NX3D/Ja9eaieAsB47KI/1K6ZuEbys0HS4H cm4VtLCE4lXpD55t7tvI1EgT2ereQPp9pDLmcVypIN63EW5oVefzdJr1E6DFdbFFk0F7 lWcsWW1KD56+yFy2tvYNIrJOOMT3TaiZ5ahAMs1o3PJauZZq6ZWymiOFdtN6NkePZDcp 1CNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=X77j4eLq; 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 d26-20020a0cb2da000000b0066d14dca029si829408qvf.555.2023.10.17.04.52.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:52:05 -0700 (PDT) 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=X77j4eLq; 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 23FCA385E017 for ; Tue, 17 Oct 2023 11:50:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23FCA385E017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543427; bh=12dNqlgpFeavMSJPZSk02QTDoCt42Gr025LrayzUMxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X77j4eLqL2A7vP9dAhUsx30ZXN7ixiXwcOtgAyYxR3KoIHfMRmTru1TmZTRRzh+IJ /VTTrCiQYjfYICVH4Jvl+L6TTKX8LD5MzHRu3nHrxSWC0RL3nwCvlCCmwleq2xeko/ SMF8PdmsyGdD6XL3Yse9hDAUxE9wScOta9KbYhzE= 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 82C8C388202E; Tue, 17 Oct 2023 11:41:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82C8C388202E 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 82C8C388202E 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=1697542905; cv=none; b=NOkUL//+F48WjkzGbWdr7AUCvXHEhNwikQxyMmw7lGyB4crl7umelS5Dm4RLT6lgZ1BII8vyB/QqNRIox0m9y5ko588gIwTEg2lA4++z6YVPH8h/EbtVCBr1mOGNXsF9C+kzQOJtCqWFMLAv6XNR4L5zB4JPuV966TBYJ2vP+NI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542905; c=relaxed/simple; bh=RfJ8hl0s/l6P20aQsfKPF76bH6h8zlFHEJKAl6sYyao=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PlxzAMfWBEqSEfVALrhSjH0ysQaaskMDlFGtdkBK/fTbQkplILPmcXgBNLqbg7IsFvviKXk4TOVxGWy8SBcU9WrJkbTp4o9aZUTrOyMHhfUii7rU3peVzo8DfCAExr5WvhA5lkvH6oXlnNU9EHOmF8WMxEBHU9S2eZAF+hnafI8= 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 39HAbfQR005410; Tue, 17 Oct 2023 11:41:43 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbau7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:41:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBfBB4010591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:41:11 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG6020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:41:11 -0700 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 v22 03/31] c++: Accept the use of built-in trait identifiers Date: Tue, 17 Oct 2023 04:36:24 -0700 Message-ID: <20231017113822.677344-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: BeYQb1CEuTlTTM2fAXEXoWeI5RkE_eNd X-Proofpoint-ORIG-GUID: BeYQb1CEuTlTTM2fAXEXoWeI5RkE_eNd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779681961607250764 X-GMAIL-MSGID: 1780003399250069932 This patch accepts the use of built-in trait identifiers when they are actually not used as traits. Specifically, we check if the subsequent token is '(' for ordinary built-in traits or is '<' only for the special __type_pack_element built-in trait. If those identifiers are used differently, the parser treats them as normal identifiers. This allows us to accept code like: struct __is_pointer {};. gcc/cp/ChangeLog: * parser.cc (cp_lexer_lookup_trait): Rename to ... (cp_lexer_peek_trait): ... this. Handle a subsequent token for the corresponding built-in trait. (cp_lexer_lookup_trait_expr): Rename to ... (cp_lexer_peek_trait_expr): ... this. (cp_lexer_lookup_trait_type): Rename to ... (cp_lexer_peek_trait_type): ... this. (cp_lexer_next_token_is_decl_specifier_keyword): Call cp_lexer_peek_trait_type. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. Signed-off-by: Ken Matsui --- gcc/cp/parser.cc | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index ece238c2072..e4c45190313 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,12 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *lexer, const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1197,15 +1197,27 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } -/* Look ups the corresponding built-in trait if a given token is +/* Peeks the corresponding built-in trait if a given token is a built-in trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) { - if (token->type == CPP_NAME && IDENTIFIER_TRAIT_P (token->u.value)) - return &cp_traits[IDENTIFIER_CP_INDEX (token->u.value)]; + if (token1->type == CPP_NAME && IDENTIFIER_TRAIT_P (token1->u.value)) + { + const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (token1->u.value)]; + const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT); + + /* Check if the subsequent token is a `<' token to + __type_pack_element or is a `(' token to everything else. */ + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); + if (is_pack_element && token2->type != CPP_LESS) + return nullptr; + if (!is_pack_element && token2->type != CPP_OPEN_PAREN) + return nullptr; + return &trait; + } return nullptr; } @@ -1213,9 +1225,9 @@ cp_lexer_lookup_trait (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_expr (const cp_token *token) +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && !trait->type) return trait; @@ -1226,9 +1238,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_type (const cp_token *token) +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && trait->type) return trait; @@ -1243,7 +1255,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); - if (cp_lexer_lookup_trait_type (token)) + if (cp_lexer_peek_trait_type (lexer, token)) return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6122,7 +6134,8 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: - if (const cp_trait* trait = cp_lexer_lookup_trait_expr (token)) + if (const cp_trait* trait + = cp_lexer_peek_trait_expr (parser->lexer, token)) return cp_parser_trait (parser, trait); /* FALLTHRU */ case CPP_SCOPE: @@ -20131,7 +20144,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, } /* If token is a type-yielding built-in traits, parse it. */ - const cp_trait* trait = cp_lexer_lookup_trait_type (token); + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Tue Oct 17 11:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077789vqb; Tue, 17 Oct 2023 04:57:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFy9g9E7basBFfofDzNDdYr+4UHQVwcf7axHrzCLkYukBREnaS8nCIbVs/f+0dXh+kgnvRp X-Received: by 2002:ac8:5990:0:b0:419:4d8a:336 with SMTP id e16-20020ac85990000000b004194d8a0336mr2274303qte.60.1697543874921; Tue, 17 Oct 2023 04:57:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543874; cv=pass; d=google.com; s=arc-20160816; b=WSlfhmAbvjVOqmjGWopKkzK46RFd+PdOsNE1Z0uTbbA5V46zG7DA/3yDs5nS37SUGL Vayrb2D3urmiBYOa7ZeZ5EfQWA8W0bdFiC/y1z8PMwBxY9cSu5nxDXMXMY7jtUxixsy6 0C/5uXQ2+ekxwe01FS5E9yRQfiLW0Ti42qeVGdyGWXwOZUpnvy51ryK7BpWz02rtVGLc IPrHFOP9ApgwZRui6PPQWQxyAVwvgS2IITkXPd9wSVPVAzBb5Ia4UET3CBrlDOZqOgWK cmmqrRjR2Np/tCiQqO40Ue/oRF9X0bKGQIQAJm5z30nz5JhgKLvy4BrtckHr9zyZOo6s NpiQ== 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=YFgz3JKa50S1VxfkIDu3wJrOJMs1VKbfdao+QHPwjHE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=w/29l0om2durMYOTb+3/rpTMhvSkIqv3kx6yITqCDWsbOh84b32W9+UCczaE5dk/j9 JlKHJrYOuWC40vC2zye5jA7APVYai5EdQ8n55+in8v8WSHPKfd8zBAfiaiNzMPfx3LTq 0woYPEGWmYvzFu0AtzGAq+kyT61cNJGu0B3+Hv484/4PDzrmxVxfsM3J1Wf3ccr9wGCl NMBFoh1eKXC2BL+E1yLypOkgZP85hgZme9z2f5x+ZPgmrU6IwQXOPCx2+Xiw62tvlq0Y fsMwvwU3go981MsM2oYRl3M7xBCHcUEU8hVyWWq7l5omlc3SmGvbMlBk6GOe6TbPvTKp kXYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eGi96ual; 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 h21-20020ac87d55000000b00419642d586esi988998qtb.450.2023.10.17.04.57.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:57:54 -0700 (PDT) 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=eGi96ual; 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 37B78383414D for ; Tue, 17 Oct 2023 11:56:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37B78383414D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543794; bh=YFgz3JKa50S1VxfkIDu3wJrOJMs1VKbfdao+QHPwjHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eGi96ualJZA+4rNaXOvPeXgDSRP7iqLY8fxJByvypOCOQ6sYT3wjs300ki69E6ILZ Q/dtDtx58bDUxoiUQ8M9R2AU2I52eh71nr/hgKKzj12ssnS0AsuO4Kyq8tB6g1fubr K79G93K876koRzVg5L+2rPGgw/qmPmwFN2vAKkkI= 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 DBD2A385B530; Tue, 17 Oct 2023 11:42:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBD2A385B530 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 DBD2A385B530 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=1697542956; cv=none; b=mCsTq3WMtAhsH/1Vw7DOJVpLyeYfp7Fd1n4TBpXT//T3lT7/IEEdgxil0rNaa7SI6OfIm89zp8Ety13PAZl3aHj+xQWLPQWVaajo/VLs9dvo1uLo0LzXybHjdKQUI2MEre36DLtdCw9Xhi6Vl/vGI/yVoncLV4/N1nZ2JpMcCiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542956; c=relaxed/simple; bh=Nhkst8uA8uBdTogdmoRZMARPpCFeWcQCWm0H9ZsIAxs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=O6tSUqtMXG1T62BogOfkWJ8zVu66BznyiJWcpvJBNj4AhT28qIRc/DbAaIfBNu0EqJdSZrvaMMXVRYxGOxLLAA9wzq4OmFXvOaaYJJ+eEJO7hV7OAnSkWmjNMcvkP6jBWdtNKgIlUzQPTUsDDtHBQL8DDKZ5BMnP5TZsmzeKe3k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBdWch026950; Tue, 17 Oct 2023 11:42:34 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw54p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:42:34 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBgOSL005455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:42:24 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG7020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:42:23 -0700 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 v22 04/31] c++: Implement __is_const built-in trait Date: Tue, 17 Oct 2023 04:36:25 -0700 Message-ID: <20231017113822.677344-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: P-YbALMuaT51T4zaNUYUy90M1KoeDGS4 X-Proofpoint-ORIG-GUID: P-YbALMuaT51T4zaNUYUy90M1KoeDGS4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=937 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1780003766054837050 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 | 19 +++++++++++++++++++ 5 files changed, 30 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 41fe2812ac4..41d9eef7227 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3724,6 +3724,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 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) 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 144cb440fa3..7fbcfd7ccad 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,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); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,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..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// 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 Tue Oct 17 11:36:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072784vqb; Tue, 17 Oct 2023 04:46:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCrDUzTwP0TxXOGmw/CrIBWqc73Yd9LXfz+ThjLcCmLyriS4H7dEzDA1fPLyMq9qEbvEfL X-Received: by 2002:a05:6214:248f:b0:66d:236f:2b89 with SMTP id gi15-20020a056214248f00b0066d236f2b89mr2365195qvb.47.1697543172992; Tue, 17 Oct 2023 04:46:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543172; cv=pass; d=google.com; s=arc-20160816; b=Fn0xYK7vP5WsLfbMxkCRJFvf0LZBVVdFVTdOohdCa999sEg5w13zQV4URzK+J9p5fZ JQVzSvD5ROQwSIdxYWfohYMoEC58CnEj/QJXK/mJuLWIHQEAYshRu0TEujI/ZgtPLR10 xOalX6TPjSrM38j68pfbf78TeCAj2qaRyXwNvmz2K6r55QADRx2mPMNly4IHKAfdTmrk Rfg328Ce/RQW5qWR7vooOaJHnvnZp7UgaC4PMQP+iny/eWBCoHSeyhwCpFOmXo7mYAI5 B3u68VF6yk58EDYfrdHvBXYK1z3wrdOJNUL09nClDVmnl+aaMyq/KcXtsxuYNSxXZSkM OXUQ== 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=qyC6olmDOD3xclF1RvY+2S0/j2J8XJ5zV7CYrN+e5lQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=NFuDnUohILM9MkVPw/S3z9y0p0bi2liYTNAidwcvGmPk1AhIYiAKMFfrU9uxy/86th 18l4pHDmk8Bp4093JJacLwW7ORkbzKfYwf4abfzOkiqOvARXrVSxW/oBjjP5MwP0nqKE kRXKIEIRr5I+c+umZzHFxyLtN9rDDxuYoK6Tw8sgHFG4y9BnAsQTp2pQ90E3422Qreak cc6xtAwCdzGXffILP67SWCApWsk0+OuIkyOJbY16mYrOkirHbiTm3pg0O75j4W01HMfW ra4Jy3U5/myhedBi8w6KlKU3wTFCoY0dK36Glnr2slZD04JoCTvNOv2BUFsXi5VLZhOE 80JA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lCKqLYp5; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v19-20020ae9e313000000b0076db6aaa20esi884856qkf.508.2023.10.17.04.46.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:46:12 -0700 (PDT) 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=lCKqLYp5; 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 2DE423875DD2 for ; Tue, 17 Oct 2023 11:44:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DE423875DD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543095; bh=qyC6olmDOD3xclF1RvY+2S0/j2J8XJ5zV7CYrN+e5lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lCKqLYp5/JT+MYivz0F7LVNlg+Y7hwcvylOy9U+bu01oI6MJ3l6l3u59cy7hBsf5k j6g1JKIxpHieLaGku0cpjgAOnWzCqoH5Gf6Rfpy39Ak7vS+SEySKMFZgwAxz9oQtgb YBG4GfhIfqarj1YibJr4dIZX6cARq619ZSPqc0+s= 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 4034438AA272; Tue, 17 Oct 2023 11:43:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4034438AA272 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 4034438AA272 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=1697543019; cv=none; b=Nr6kezMGh+qZ14RqyjqjY2w41MhOWqX369ycw2Sqr3FVhzl18ncucb0BZdE01AX6SH5P9rhZAmOIb2nEKFSKq/nKnQBnscGb2bFHoZ2qnrij/86AEK4EQTxKL6c+TKGMEn7TFgAmX0p4vFQ4YMcc8hF46+74hE4l+CUfxV0hSVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543019; c=relaxed/simple; bh=/1qcFEm4P/QLiMl/jAKWkbnYQhruObr98IEbIB0r71U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WOR0eZXWiMAaJOGm9yBZZCXwEtX5ibgQ12QqQ1ONuIzjl6cD7hoMpSyhIH+uilsw78kkUbui7/Vq0lK/XStn4AtqqKKlH0tFDivY9eIep/OP+T2xklBKrS2DoGr/TOZJhESN3qoIRYPJYSTRHv7jQ8VxC5PMqrsFsA6kIZn6pp8= 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 39HBXgLX022138; Tue, 17 Oct 2023 11:43:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rmsq3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhZ9m011176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:35 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG8020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:34 -0700 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 v22 05/31] libstdc++: Optimize std::is_const compilation performance Date: Tue, 17 Oct 2023 04:36:26 -0700 Message-ID: <20231017113822.677344-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 15NhWZQjQX_jY_QcE6hMSuQvuMFoaKkn X-Proofpoint-GUID: 15NhWZQjQX_jY_QcE6hMSuQvuMFoaKkn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=765 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002951185557558 X-GMAIL-MSGID: 1780003029989189554 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..686e38e47c3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,6 +784,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 { }; @@ -791,6 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3218,10 +3225,17 @@ template inline constexpr bool is_compound_v = is_compound<_Tp>::value; template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +#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 + template inline constexpr bool is_volatile_v = false; template From patchwork Tue Oct 17 11:36:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074763vqb; Tue, 17 Oct 2023 04:50:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtcKcYIWWCtBX28wCO/5qf7Mwqg8swI98DOvUg52MKCeMZGr1eKNHwrZI6aoYvMJ38TciT X-Received: by 2002:ad4:5d61:0:b0:66d:13c2:1c31 with SMTP id fn1-20020ad45d61000000b0066d13c21c31mr2197237qvb.24.1697543432975; Tue, 17 Oct 2023 04:50:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543432; cv=pass; d=google.com; s=arc-20160816; b=M0FYWI5/KRMNrijxagKQt/77n4Tve4l0GRy9jDeo2dBX06FTJWGPS/tvt0Dy6AJiDu lhyZPUQYv6LPf/KWYHGGWFr3NXSJdP0K4wxo7rphWVkfuV4xP/n0hQkmFtkzX2atbwu9 uuqBgdM9b5pQ/y//uqNewZbfh7jOB6o/rs4yeFcq+XDQyE3OtpCzzRA05S914mAsUETS x+aMCsuZsgFAKxyxMxo8Nr/zik9TyQp8VOoPJzgV0yHAXSkhzVpe9srIDuikS28UAaLT r/90vNk7NqDn7jH/2B3XbOdTpdsHE78/1c43gMj6tatWgjCkR10ypLFNOgY/HH1B/dzx r+XQ== 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=GHfL9y42s9AOw4KCQO/a6ZjHqW2NAxHIAkgovCmo5GI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LfQuppsNegOuZg8XZ5+5/oYkrYa1KPwyT+6ucELYdQJl7UPXAkih8lxRNAqP3DwM9P UzprW3UvkrclvgOzOHrmhuqxFERPlAMwmpTSIXQQMil+pPk4BlX+Cjf1h7klejiJZ8vh vyrsCS+2UYcizkmBcFLcgU4xgkDMd67/nom2zzke1gASqD/8egrhZ34NG5sm27UM2xV4 EWfZ+xsez7T7qR7jqiFy4+J4UGcObr7QiHr8tfO1dMxnZnUu2qt+oE8D2OU6UWpMi/N+ gf23uVXatp5lB/rrkKzQMiMpke6CNHv6j+BPss7CTxGVuneEsfNHgilFWXMIoQJEQIwz ES0Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=F51KeTdJ; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id do8-20020a056214096800b0065cffe26762si819473qvb.319.2023.10.17.04.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:50:32 -0700 (PDT) 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=F51KeTdJ; 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 AFA433831E36 for ; Tue, 17 Oct 2023 11:48:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFA433831E36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543339; bh=GHfL9y42s9AOw4KCQO/a6ZjHqW2NAxHIAkgovCmo5GI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=F51KeTdJszuBgkP9hw3qEGbdHaJ1at7qb+vq61GDLSgCz5Pn8F22zVF8ZXNtWKLnf KIyDPW7DbGZrO6Ney6Xd9hb+/rR6DoaQM5Oxxe+eWs1xmkyw3x9/B5gVjMQ9O+1npf z6ZFxvHBmCxbxFEejzyXg7stRfDx+w4qk//xjU7U= 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 AB04E3861937; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB04E3861937 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 AB04E3861937 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=1697543031; cv=none; b=aDIkK/tADL/FhBs/RO8WfjKTNadqSALUX2KBhzoW6ob+O9gs9R+lkZo2cdrfW4/HVAIwKp6bLg+6Do+EUEqgt6Rmh97zlDzPGkzB8xu3oPberJ0Sm7oY9PSe8AUbFddlahgqJJMZJlBM/xT7FOlrdd5g0LVkXDeKdlDIWaLU2/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543031; c=relaxed/simple; bh=1rHsyPoqaQXKsQOFdJbK+nBdkfKdFE5DDiprWTj+Wuk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=C7v7qHKJJNizL18Euc9gBBw7I0S0ZVclZa6CGqE9JTiGCFepopexPlCjJv1crknO7Rgxlh8+jGq0mh75e6mBIjiPys4jlJQm0BcGSsOTUmODxWYHCmmm/56QqlxbTHKjESpTkVgh1hl95PY1zSn/5i84BtWrcgulxh/cqc4xRPg= 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 39HBdsHm010306; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tseh6tsb7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhg2P030086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:42 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchG9020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:42 -0700 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 v22 06/31] c++: Implement __is_volatile built-in trait Date: Tue, 17 Oct 2023 04:36:27 -0700 Message-ID: <20231017113822.677344-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: J4zTQ7knWyrXvJFc_5o5pu81Guy5LLhN X-Proofpoint-GUID: J4zTQ7knWyrXvJFc_5o5pu81Guy5LLhN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 mlxlogscore=788 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1776996916785922643 X-GMAIL-MSGID: 1780003302973976181 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 | 19 +++++++++++++++++++ 5 files changed, 30 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 41d9eef7227..54782a167dd 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3797,6 +3797,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 9e4e6d798a0..d786f47e60c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,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 7fbcfd7ccad..7726fa99711 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,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); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: 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 e6e481b13c5..fb03dd20e84 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_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..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// 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 Tue Oct 17 11:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154122 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073611vqb; Tue, 17 Oct 2023 04:47:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUxL/bUKjuXew3oBgPVIvFgDsLpW4f+w6dTpD5kqSFdymVlpelBrT10V0g9BuSxnKgoMta X-Received: by 2002:ac8:5a55:0:b0:417:fe9c:6d88 with SMTP id o21-20020ac85a55000000b00417fe9c6d88mr2382140qta.37.1697543273820; Tue, 17 Oct 2023 04:47:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543273; cv=pass; d=google.com; s=arc-20160816; b=JXrOHnBVAkRZTayNkrgO9tPpeXIP2vjhqGPIbf14qEND0rmaG3qCXt5cTEUwqO4VkD wEdiap8m6lQwnS5/WDn6Bizqx55cv1J5Hw2gvpjdRaNpGFIN8Thj74RjGMhfaoncHrDE wsb+ImKRpFnFaRd6r1+l9ead9lz5VZSJTMAUHxdyAsbX3zxR3bJ7NYkTv4XgDoMPaDGE Gh6o/sVB+RI5+s2khj/zRFpxgqh4shGq/T05YyGNl5t9IpOXBfK+yjYCEl6tJ5L2z+Cu +zYdhr5ghpfcoXiNKrMK7QdrnVb6gNFiBdXAUwLYhmOPRqW8IUmdfEytTT6VgrbYBt3C sD+g== 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=QBj39jUSu1bVKtAdYFimfBXba1UDQ3sncrIoT+Jf20s=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=loTcXgJOqQEl7SdlBFCl/IRnPoemu9+3T342o2fDaqqoD4VmjJmhNCAab/zu04whAz wGhYfOHcvtFfVBGAKnO6meEzPagp75cX6k51sm/MN9YvK9oOJJq+r7l3XA4j8TXQDsAR W/EEMEiRH9byoVEccB3toEfxLB96U9n8snsKEy6JWdMifGZ9axi5uC42Q2d5RPAbNptf y9JwnI5OMmZGbIBeJORQw2s1NxUYphmwCVjKSawtvj3FahIGK80saosEXT9TnrkPamGx VjnVu42GyLBTYr6N6fKqQSckRnq1CkjqFhQp5v3U0KTeMsEmJhT5TYfxD9FeBU79zWc2 2QUw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MH5w0soQ; 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 12-20020ac84e8c000000b00417cd1d2a6bsi988788qtp.136.2023.10.17.04.47.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:47:53 -0700 (PDT) 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=MH5w0soQ; 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 A59653898392 for ; Tue, 17 Oct 2023 11:46:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A59653898392 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543191; bh=QBj39jUSu1bVKtAdYFimfBXba1UDQ3sncrIoT+Jf20s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MH5w0soQe+M6lOxmx6qAVs4LIkEmwfWMoFbKQHniDk2mLllfw39U7IbQyEm+dDf6X qvy88+FGx7ZV1WajlFByuc/yOtOO2E1bT+3FCc9GIl8R+HCkAtae8UUCDU9n2SPv9S hdVv6Hj6q2tQ3ILvutJWvlAWxSaCd8ki50Q8Pi/c= 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 77421388203B; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77421388203B 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 77421388203B 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=1697543028; cv=none; b=DzsSSWWLNW9aL/lR7BBFl79KzqP9aGzFO8by6IUeoGMOIwZxTNdnLwV9cEk7m4Ox6WokgRuEjzePhYc7oYWOeMkeP8w6cHurJavLMwfoZWZOLTCi/+fz/L/1KbALGA8fiTWmn2MtUo0HDgroOoeZAUIVYsy/56aB4a6oRG+juW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543028; c=relaxed/simple; bh=OOSc7LXvSX0VabJEFNwZWDP0RMhq6XkmejWzDYjnE+o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EmmOGvtzvPl7hIvbc/ok2dTIUMKeVDsxMjZg3wJPV+LHy+R9U/dY/S+82GzJkIky7ONRm6dTYR+gUKo6KRpU5bw3Rm83WY9sMbACs26cysqJgEb9sgVhvNV7+YYclsibOAODkIgfb2seRslRqccvfSuEdCqD4PypEWXQsu0NEWs= 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 39HBcYCO014503; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsgyr1pd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhgWu029924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:43 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGA020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:42 -0700 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 v22 07/31] libstdc++: Optimize std::is_volatile compilation performance Date: Tue, 17 Oct 2023 04:36:28 -0700 Message-ID: <20231017113822.677344-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: tbK3zzC0YQYehA0WNyr4PtsMWP6ZJ0sD X-Proofpoint-GUID: tbK3zzC0YQYehA0WNyr4PtsMWP6ZJ0sD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 adultscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1034 mlxlogscore=691 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780002988961806506 X-GMAIL-MSGID: 1780003135750953970 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 686e38e47c3..c01f65df22b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -800,6 +800,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 { }; @@ -807,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3236,10 +3243,15 @@ template inline constexpr bool is_const_v = true; #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 Tue Oct 17 11:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075275vqb; Tue, 17 Oct 2023 04:51:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYmTT7IrM0OwoCP3WM5UCnc2yQub2Vz/mkwC6u3AdIq2BVcXNtLKUZhFPMY2ch0hxfFosC X-Received: by 2002:a05:620a:1194:b0:76f:1817:942b with SMTP id b20-20020a05620a119400b0076f1817942bmr1856772qkk.28.1697543508971; Tue, 17 Oct 2023 04:51:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543508; cv=pass; d=google.com; s=arc-20160816; b=yDXvyrZ1rZwKML8A2MdM0WEOCTGbj2id4nNkTc8gD8UO3Hps3Oe8wXJkdA+k6mk7BK OZQgfL8qbByzeCakA/VyTtzONHt8tiQQZA8furmEVTO7A+HjZHqFZzbRzu/biaqNaRjL 6MSlU1uzUbiV+hxkZTAgHemD4I0n88d89gJ9T89NBrMklO1vrhQIuorDupaVzfdD07sd gTaVxRDLPjmNhKwYMtvFeNZ8zP/bpBuMNUIgGRFncEOqbsmlIC9kxvwRHtxxwLlSV0t0 1qzPYpZP/yG5QB7LJfR5R+PBXl/B8JPokWyq75tYsS0YpUWrmhEU3gC1h71a7JkYDTr7 dkxg== 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=7ixTjS3X9HBoxNnpE1L4uHNyKTZaXvNaPjj8X4w0bAQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LkwDNL81Xi1rzkr5xaphwHcOiIPkd21adApopkfu48jjIV/t50nGWnFPz9N0BkPXBW rnsgdE3GvCVsVTXOJc6x9yfsuU74AF6+2Kv3d8RRJpsVYUSywmON5arUoAqVP2JvAgcL UN1qqnXzixdWAgOgf4RO1KPM7vj10o2lTfj9yG03CgS2uot/0O1csUcNjX0JHmg8JySk RQ5AfuUSbcXywnFE5Z7vfKc4v37BNK5olQGeMiM35zyOtqhu4ri99u9BK9o5s94nTpOc KxcpE0HL17OIg3FYSXGCvobouSUKMq2n8fnSjJJhVN1RGri3Gw/bwRp2lFNwv5ezEHpM 6gKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PLUvToEC; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m15-20020a05620a290f00b00765a635ade2si923662qkp.309.2023.10.17.04.51.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:51:48 -0700 (PDT) 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=PLUvToEC; 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 238353836E87 for ; Tue, 17 Oct 2023 11:50:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 238353836E87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543409; bh=7ixTjS3X9HBoxNnpE1L4uHNyKTZaXvNaPjj8X4w0bAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PLUvToECAT11mb7ndpvapoZnpCI0akg4wW8bFhKx563MUgYvmgiMRduODMp2z2VgU 6ZDyrlbpCYxMayPwQbsTGKC5ooa73doV0q8ZAZuF0YRSuBUQ2NLYyIHIaajudStCTi M7dLltvkyskeohIyJIDFJs+Kc+dzp+xS+ecVf5sw= 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 A94E4385773C; Tue, 17 Oct 2023 11:43:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A94E4385773C 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 A94E4385773C 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=1697543036; cv=none; b=ojqLq+g0bFHHBAkRbCQ7l+OjCx9jVTQymZH2Klbs07QY7BT1YyxV4hfaZwHtsigR6zHeCjIrm4nE3zG/rKBLqNVM9DlDCJTS8B7BR+CeuhmtMowXZOzZ4XxpH0HEYYH1iOjz+Yvk5ivgk1QLfecmzAEYU5q+kVEupvlq5UChrv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543036; c=relaxed/simple; bh=8TftqluSpQljNHIfpPcj3uNIi87MZCtc8a0jE8Eje+k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JnTnJ851wtlR1rwzuFSZHLgAEjb9/m6C4bc96fhDW8ya1ZbuI3wP/+Uq+8IfJKg55o3Ht8y+6YzQLB+Hd1MiyMWbNyj3AZ1+Y/A1uWM4YvpyPvNYuMWKYlcZ10cagFcGAqODeMMaFtnsNOh3TxEO51UxecXvLEJYDdiXEfQuIlo= 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 39HBQT5d020786; Tue, 17 Oct 2023 11:43:51 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsftqt1uw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhglG032352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:42 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGB020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:42 -0700 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 v22 08/31] c++: Implement __is_array built-in trait Date: Tue, 17 Oct 2023 04:36:29 -0700 Message-ID: <20231017113822.677344-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: M6ePZjgCBS1mHk9gn93CY_VUHTqml6fU X-Proofpoint-ORIG-GUID: M6ePZjgCBS1mHk9gn93CY_VUHTqml6fU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=837 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1776997331947317165 X-GMAIL-MSGID: 1780003382451162558 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_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_array. * g++.dg/ext/is_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_array.C | 28 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 54782a167dd..b9f89fe178c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3715,6 +3715,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARRAY: + inform (loc, " %qT is not an array", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7726fa99711..8d5874d6ab0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Tue Oct 17 11:36:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077497vqb; Tue, 17 Oct 2023 04:57:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzmF/BvZwWuo5xNexqNFVS3t9bjMS9bFnI+LrCzkt2tnZfws8qqC/wpBJfaso4RLWnzCsd X-Received: by 2002:a05:620a:4692:b0:76d:a0a4:fe9b with SMTP id bq18-20020a05620a469200b0076da0a4fe9bmr2050652qkb.55.1697543827736; Tue, 17 Oct 2023 04:57:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543827; cv=pass; d=google.com; s=arc-20160816; b=fyimtYctSVvrob6sRa2qQ2oJ2fE2wIzDsmB2B0BGltjKlwTsY404T7Fb3Yk04aDvqG P+GyTkzKOXFzUYdzc0XCtjqWrkyDYArti1rH1gJJ4ozDtsvbw7ZAgNQiv/iAYAt1Jwd0 kHE9+dE6ijqHjMVqmavIrCevDI7NDYGG/EXuyAjpM3w5li4GWmNiEA9UMN8Y19cCpG4E G2wHKU2BjT4uoUjsix0m8is7imC+rbrk+2gSzcz+xeX0G+N78BBtmD/OiqbgREFDghpQ XCiMXnv/MsqiDafUfcVNHPPqa0xttZXkKAlM+A5xMwa+W9Lv9PmODcU1BuvNjY4b5zU/ 5GYA== 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=RZTNDHIWtB0xt/LyEoTYMcdMTJkRnyWcUjKmKws8okg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jBfFyed8DkMwd+Wky24jG8JCVsy59aRDnFwfEfIghe6EJM8Mz70h0zV2SwmfNnS4Xs Y+SX6iG9mc+TAwmIld8+q0LRxc4u84iASxs4RKDky45HXs1m4DGeWSnX+yNhtnBKheZ5 rTe+PMPzF9nOiH74+AW7FVzHZOMQ35ZAjW+zGwVYt9n3HQ/iBfEKdEwGJkT0YANzEpGX 1NYjh2zG68OyWBgb+648YXGckOctsxb3se/8uLI4MDOjI0PKkOazPe9/md/wZzRgR8Dg EYqY0e0vEnt2hveAOPqa/KI6TLRx0kACwQqTlazjcHpxjJii/+k2xAY8WTlGMoYB3LIU I3nQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p82i5dKc; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s25-20020a05620a081900b00773d6c99af2si925236qks.449.2023.10.17.04.57.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:57:07 -0700 (PDT) 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=p82i5dKc; 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 8A5E03894C1E for ; Tue, 17 Oct 2023 11:55:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A5E03894C1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543718; bh=RZTNDHIWtB0xt/LyEoTYMcdMTJkRnyWcUjKmKws8okg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=p82i5dKctJbsZrJkcsr49kykIflb7MYlkoaKN7rcycP+Cdbct1y6N5lDPirHvx4MB /6GD6QFilPWUVbkq1FRWdmCn1dpOyZ+KYrlWkbURW/B3Qddb1vI473dhg3Z4SrRaQH RrvQDPAC6vMbbkjTPicyGkKbgnTsL3Z4YfnzKn5o= 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 AFA253945C23; Tue, 17 Oct 2023 11:43:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFA253945C23 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 AFA253945C23 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=1697543036; cv=none; b=j053RW4a8IbMeEqsO63tBi2GNXxaQPu2Y2Rm4tFNuuRGdSw0PuJci9/Xx7Dl6RgUP4+7tMTO2ZBCbiq2AZz3f1EqnvkCCW4ulOA45ObwEjcHuBguZYnkb6T/YnWQ9tRk3vyHiE3a+kkCt8I6Kvy5mJFcwjwvf/feQNqMVrG8FCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543036; c=relaxed/simple; bh=LWlpKAqSPh2SZMP3ObLq+s/FTCguucm8HDdrx5fwRp8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LG0NgBh3AjRKBoQHwlGWkvURqlEWAICxYrAAu0u49QuSF4UjzdHiPSzk+3usLOCXd8QWLevMng4Z1kZ9WWKNgSicG8GocUJhjiwR+W05++3eAaulMJe10ZRlQUE/HgVWQRscwbPtHwIBCT9arUiQXBsjqWOuVkGJmE4RhCQo37o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBfDWs031359; Tue, 17 Oct 2023 11:43:51 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf8x2ff5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhhKi032353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:43 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGC020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:42 -0700 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 v22 09/31] libstdc++: Optimize std::is_array compilation performance Date: Tue, 17 Oct 2023 04:36:30 -0700 Message-ID: <20231017113822.677344-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: lRJPLwxA2OQGC8AG2ACcAY9nRZoDq67B X-Proofpoint-ORIG-GUID: lRJPLwxA2OQGC8AG2ACcAY9nRZoDq67B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=526 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1034 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780002741723435689 X-GMAIL-MSGID: 1780003716442357736 This patch optimizes the compilation performance of std::is_array by dispatching to the new __is_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_array): Use __is_array built-in trait. (is_array_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 c01f65df22b..4e8165e5af5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -523,6 +523,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_array +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) + template + struct is_array + : public __bool_constant<__is_array(_Tp)> + { }; +#else template struct is_array : public false_type { }; @@ -534,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_array<_Tp[]> : public true_type { }; +#endif template struct __is_pointer_helper @@ -3183,12 +3190,17 @@ template template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) +template + inline constexpr bool is_array_v = __is_array(_Tp); +#else template inline constexpr bool is_array_v = false; template inline constexpr bool is_array_v<_Tp[]> = true; template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#endif template inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; From patchwork Tue Oct 17 11:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075882vqb; Tue, 17 Oct 2023 04:53:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpJ9T7aiIGSUR0120tvTxN9jjIdWiFAPdg7bWogB63ecGy/CYUjvvxZIWILLpAUyjeU91q X-Received: by 2002:a05:6902:50d:b0:d9a:c31a:c0d0 with SMTP id x13-20020a056902050d00b00d9ac31ac0d0mr1782800ybs.8.1697543599186; Tue, 17 Oct 2023 04:53:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543599; cv=pass; d=google.com; s=arc-20160816; b=nh9XTY7Ef2t/r9WZH9nnIu2Lvr5kyK9wt5PYrPmVf5L4IInmE9+wRjU4WdWZU9pfit WVdqSgVIA6g0Wpo0xBPTF870kN/to6SqoDBSnsPn84wfsg183rb/dK9A6fDp0EgrszLv 3bZva1yp6Ga4ASHnzMOtqs/PoirgN+PszZhYdk3+ibUMnCBi6tT3yIOmYmpLwnINDN+K h2YKte2hIQNXu6IwCEJNI3MFAtPRbPZ+ey30QTU1dS3CKVcVsvVsdOEQzk4n4BZnqKv4 dNp0umPCyvzSgLojpf0h/qz82X5wY7wqdIcbzugoCBI47TTB3Ou8NV0/t9xeXBpWnqqd YC6g== 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=4fUvy3gQlMpAwr3jsAjiFhB2miwazGVk99LPxCPeIwE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=A9SjSDYVq732hDEXRQIRrzvMtxQdsdRn1pF+kz4TIN96xcKQJ5Hm6Zex/9lEwrpuuq dWKSjIbUDQhjhk7Y0Mf5+B1GNXbRWfflLV+sSX51v1/eK8KSpR2ZTjz+sJAEYF43eu6G 7poGVU05vQUZmdWnZHt6cQgtlDUrIS4jF9mdufZH1YSTVTwt+qTXThz7s1YRR6p1y35Z Z7mddpUsQ9l7jx8wcfi8Oa/KZzbGv4A1gjmTwRVfQH6ZdRbDhTM9o4mz23N+Mt8GrP4K 0Vv96JCekRTXHOTO8S30hjSntTQrWYiJ/fvklpq9m0Jn3Q5LJjcIX703/eKCv9idMsZn GLMA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="jIqB//U4"; 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 d6-20020a05620a240600b007757596c30dsi983109qkn.135.2023.10.17.04.53.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:53:19 -0700 (PDT) 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="jIqB//U4"; 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 5382938319FD for ; Tue, 17 Oct 2023 11:51:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5382938319FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543497; bh=4fUvy3gQlMpAwr3jsAjiFhB2miwazGVk99LPxCPeIwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jIqB//U4Yp6iq9WT4cl7NFAYbEUjqHNk98VNBPp9r8fjpG53pwm5pSdoXiKOTMjCB YB/qE0RhldiD4e1C4oLw2KnihjWkmFwZYXi8kZ52AXUsxQl21XHL0BULzMl0WX3VMk IgWlGK1lKE1pQ4wgPqnhv0SlUt+9my3MK9GZkDWU= 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 6FB453940CEB; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FB453940CEB 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 6FB453940CEB 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=1697543029; cv=none; b=IZzic/eOmE/TmIHW+XSifucgSwqkdYca3uP9BKo0h5EYA/B4J6srjuKhDvCnnF4nQxCVe4WRDlzhJqjjSHvrneeGpzw6nwsYnvMxqMbugZwS0+Ekz+OZVw7Bgnw4TycnPLdjiTFq6zz2Cre+S3hed92M4wddva7E9zDE2SDHdGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543029; c=relaxed/simple; bh=NhasjZWVUqUpZZmXqS8d6jkCFZVEX8IRPI+dI1G5T3g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GItb+8poxUx/0atsRGKhPADmHxLzNyFtLJ+vL+lZsUsdIuWqgWj0emCHDvvjHxGJ8lSpDCFNC4mevbjBj1ZG0Ndu6aJhWERNgHYXqQIcBJMEZc4jXzmrc/gC2MeKqpit/n8FNaO9dhQGRxZFKO7zdOR8VTCpA9PzL57b62b10tI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBbrmU026590; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf8x2fem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhhC0029925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:43 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGD020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:43 -0700 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 v22 10/31] c++: Implement __is_unbounded_array built-in trait Date: Tue, 17 Oct 2023 04:36:31 -0700 Message-ID: <20231017113822.677344-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: XAosJClAUA9g9WdcS_LjaHnkKxVcIhZo X-Proofpoint-ORIG-GUID: XAosJClAUA9g9WdcS_LjaHnkKxVcIhZo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=604 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1034 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1776997094718165190 X-GMAIL-MSGID: 1780003477045895481 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 b9f89fe178c..292b941e6a0 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3797,6 +3797,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 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,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 8d5874d6ab0..bd73323e6db 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,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; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + 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 645cabe088e..90997210c12 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_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..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#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) + +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 Tue Oct 17 11:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4081884vqb; Tue, 17 Oct 2023 05:03:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXgsX2mzEUQ9sRbTOzfn/iwTH451JGd0ayUf/hViRUhtu2TtZCyxmbEHBfGvy/eSso000i X-Received: by 2002:a05:620a:2552:b0:76a:e55c:252c with SMTP id s18-20020a05620a255200b0076ae55c252cmr1676554qko.32.1697544210381; Tue, 17 Oct 2023 05:03:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697544210; cv=pass; d=google.com; s=arc-20160816; b=DRKqBMxrHqBO1HfTERYxofj9D1D80zqubwFLmBnMOKpUmFgEdOeYgslC3wawDNWkDj PxSz6SDw3ilU0qfm4R4w3JfNJMZqBSuLPlIJ+rjji3EPBN7Ifx7CxbLy9YhIZ49ASeAE nHWhwwBer2MHPQ8+bDDNXpTNx5w5E/PqS8U5Nl3X0UJMqPzaYJTPJHyJtylwN/XAoG3c p76gcASK8UY0BjsjtYwHX7/N+0UEzzVfoarWYOkrwNndxVNHBviYHB7oevtzSHjVgnII 1TtzvNHR8cbXoDjw4gKtS2HrAuKaU0WDWnvhxZMyypC4B6soA83tegAKZt+JWncrjCio pQtQ== 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=RLQZZRfxaCHMdqX3Q4VuRHCYUQ7HTy37ML2Zz4GJKzE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PiI8HZjLqCluZxv9AW8MTFkwSOM149yAogfmZVm2cu2XCK9mJ052hyRjX7QrTQuQnU wE4gmH9PqMKSvqt8eaMDqinQfJdvN4m9QFSlBD7CpKEDHrZV4H71q9CXsamT2wZXBNWE 85pWzwEKxImkO6oPdRs/qEgDkapNBJrklCW/AN0ncZoaOqG9r8qp9zGNvP6xDYIICi6p GGyvmvC/J6qNwoQ87DWQ/cf3wb3KX1uO2V3AQ6jaY/yrX0PYDiTR6Y6j/F61GYar29JZ hAZ875HLZgQS0bcyICHZNBLT/z7otiV04Er/Vgj/OZ4GGWHVPnbRBlCTPNHomAibqJZ2 Gnkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pjTjg0mW; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qs19-20020a05620a395300b0077767d37fefsi976643qkn.771.2023.10.17.05.03.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:03:30 -0700 (PDT) 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=pjTjg0mW; 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 AB97B385E020 for ; Tue, 17 Oct 2023 12:02:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB97B385E020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697544161; bh=RLQZZRfxaCHMdqX3Q4VuRHCYUQ7HTy37ML2Zz4GJKzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pjTjg0mWGbRdmUHqY9JAPgB7Sh/pjz5D+M2g72lcX2o3NjcEBAK3sO/4f7+KE2RD8 gkipU7mxS7hTGpFkkswLaNyxAG84f267tEwzgRxU8TDF+Seu8PrkaMGsBVoGNn00gb DJ46BZN7rcI9hD4J/2fBlrlY6Q5TnYpmxsyKecpg= 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 631513831E3B; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 631513831E3B 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 631513831E3B 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=1697543045; cv=none; b=tXzr9A4xpDRa1yVJFFaPTP0xjzCn1hVCuo0DiuVIrHxmwbFFV+HOn+h/aaiOLpmQjpoT5VVi/bqSR0+KDq3RzzsnUwBqM5dGVJGpZN2QdlD+QS2UQB/MFfNTRj6ixXcl8GC2KEpzKWTYMmm6156DGxXa7fCIN8iaELSS9NKpiAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543045; c=relaxed/simple; bh=K00IDF5zEbYHxaGvNxA8OxHa/yILcGh6RlZf6vWDaAo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Qaa2dqB6eoeVzge1gHvoZxdtxsZzCFcC5UqU4G/ySHm+Xu5YoxkzcEpZ5lbd/PKM+UHKYvRw539TF1Gth5eikD7yKF+eiOn8Y8xiaaxVHYrHe6eXHqF8I577aOPh5q6KpFfUcaht6uelQZcB8mZc4lKODtbCbwjQ46JC8XiZ0Hw= 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 39HBPDCN012457; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsekdjrvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhh9F011187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:43 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGE020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:43 -0700 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 v22 11/31] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Tue, 17 Oct 2023 04:36:32 -0700 Message-ID: <20231017113822.677344-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: U2oH1oltIqubNFbktP_1WXKbhqsBo-Or X-Proofpoint-GUID: U2oH1oltIqubNFbktP_1WXKbhqsBo-Or X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=556 phishscore=0 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 clxscore=1034 suspectscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780002967013735782 X-GMAIL-MSGID: 1780004117664155499 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 4e8165e5af5..cb3d9e238fa 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3541,11 +3541,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 Tue Oct 17 11:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074338vqb; Tue, 17 Oct 2023 04:49:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExFn8e4CxzV2N6W8WSAb8OlWePaww0acrG/g1VwZd/IduafDuit5OMtK3G71VO+BEnvtEP X-Received: by 2002:a05:620a:8592:b0:76f:93e:4b30 with SMTP id pf18-20020a05620a859200b0076f093e4b30mr1567610qkn.67.1697543372395; Tue, 17 Oct 2023 04:49:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543372; cv=pass; d=google.com; s=arc-20160816; b=rX/ElQe417PiT7poVANHxD4pkZqXwj2ck8pDY8D0h2Je0HAL9dQKM5Vq5Y/n+PaN6T KGwxRh6WOa8YuVGVwY22hdZwAEJXM7p5dr1sOoLb6GVFHjGlHuQiP4uViWES/Cl1raIJ 6l9L+o4QFKZicHr4NyIN2Rk26c/pWtTL4JIIWv+1vcoQEqds6ht2KxXndb8NxyVvnWEM 7sVzHm1VUK/0iyw89UsS1Ejxlah54Td5mpFDYgiaezXTag55kifSkqTFVqi5DWXnb74T uMaWisvTHUiTbFJ6uyptkrM+HF6Wa8hq9bD3PQeLFGr4mK2GDDiX5dKB81QQYnPwdx1F AjgA== 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=FsMuUrDQIKOQmencLbexsoY8bJoop2ZORDdDp0rKtxg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Qm2O0TZ1L2oeyc6VsS0bm8zACAuCrjoAH9/ovAC6KSJ4NIurzjgocuyXQdSq3cOa2l KSCcc0lZY5bxbdfriuWDBDr4HVpNrkTsHcXKYGV4FvkJ1UmU/fAvGiieos9nJ2a6QGP1 LtZTBjoxENlQvthd19CUTwV15onnF+zNxG7QqCIZ5XHhHece0c00B+IUL8Jth54yPHZg x3FJTMdoYAYtujgf5JqbRkspnxO5uf5JhiJJVX0yvw+WuAnEJN+Mvq2jb7513LSk06J3 tWuKqNlE04VNB8CA4TtyK1gkQAq4BFYD+dTmFY1aWGN+3qe3kzSz0I6VczAI6ml4dyo1 vVgg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fxk3wBTT; 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 d4-20020a05620a240400b0076cb26a4d93si905752qkn.233.2023.10.17.04.49.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:49:32 -0700 (PDT) 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=fxk3wBTT; 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 480E33940CDB for ; Tue, 17 Oct 2023 11:48:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 480E33940CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543282; bh=FsMuUrDQIKOQmencLbexsoY8bJoop2ZORDdDp0rKtxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fxk3wBTTKiMEBehayoT23WuwCIaaDK2RNKOkbn8I8sgBM1Yy3G194/jR7QwWU6qJl syBi9v9jSp95ISuNtDK9JvXZfUoCaIfTAw27T8dI1ZiLNIUm/EFLgWV8GX7KX0alKW LSFT5wPq4vS+lZIhPBGRopSkmWDHv7EwqAIbdAgk= 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 A091A3942000; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A091A3942000 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 A091A3942000 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=1697543029; cv=none; b=t36R+XtHCIj/hXUvhNGo0YRvTzYIfYSomMLiEWtp161sXrYrilUVHYCR6InYAo0UVoyNZ5C2AuzXEVgLmq3E7Yg4vPdl1dLLTrpeZ/mta+qiJKBSQ4JZXpbAiG+o8qP+NzsiHbZRloASXlGax+Vba7CDeSJ23MGtA6RqBUqg2Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543029; c=relaxed/simple; bh=nZ/pEsqPL8Mwkgwx3MhbngeLpQUO9kpyZb6eSrDGXGc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rGhxfUy43wiF4OIHLu1NDEcIj8K+xY1uXCF4IiOnxsRCZROIJZWVaFG3G14JsBCLluYflw+Z5R+QR4jNp5M3fEk22+kHiT3kNqS5BuXH8rm3FK/++xBVyXijtzQ1V49OFYsP7V69hNFMv2BDAh8mIdK4r0Qrg/xRUt8zRzhqnL0= 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 39HBYRVR027459; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsekdjruu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhhup030087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:43 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGF020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:43 -0700 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 v22 12/31] c++: Implement __is_bounded_array built-in trait Date: Tue, 17 Oct 2023 04:36:33 -0700 Message-ID: <20231017113822.677344-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OH0dILyJ6mgyDXAHkeyRf2I330-157zr X-Proofpoint-GUID: OH0dILyJ6mgyDXAHkeyRf2I330-157zr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=565 phishscore=0 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 clxscore=1034 suspectscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1776996279060207258 X-GMAIL-MSGID: 1780003239141655652 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_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_bounded_array. * g++.dg/ext/is_bounded_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_bounded_array.C | 38 +++++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 292b941e6a0..71a40558881 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3724,6 +3724,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) 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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index bd73323e6db..aab35c9e5ba 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#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) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Tue Oct 17 11:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077573vqb; Tue, 17 Oct 2023 04:57:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4CeOCfsdFf77A5haKge0zbG77uGBLdvUsiwBUvJ5G7mcxP6Zt8yO99WqEgVkhKlMNOsXM X-Received: by 2002:a05:6808:2796:b0:3a1:e7fb:76fc with SMTP id es22-20020a056808279600b003a1e7fb76fcmr2165356oib.17.1697543840177; Tue, 17 Oct 2023 04:57:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543840; cv=pass; d=google.com; s=arc-20160816; b=gwywCfMDKeZnfG7XQOERYUZpMpzOFuCi64m0ta+eN8H5tLqN2N0EmmT2HzMhPU7V2T NsdFVcPtttjakQNbBo2lazTf8Ho9o3OsSSfh1/dhpmraM34ztyek1uULfMiACh6NA9pN 8A1iHe12sk5Qd9cQAG0lMP5uap1WUwdwzZBljGIfet6lwd2MrDstLv9aQKs5XMVgf4vf p7+G++q4Orw0oMSB9flfgQrJ/xyfzn3rMXFp2tbTwequ4VBNtiUflAaYlYTRdNxg0m8E nJwqQV5xV8vZcdrgQMl/ZZMj64Y28SgOhVJfmVj9wbzYKTvj9I7QVDlX/Ec77dqZ0gAa goHg== 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=PzsL6dsGswgTk344Px8h/e8d2SHNDgTIaBh2FsS3aXA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xrb5r7jeWNt0msmrLPIxjfMQJgxoErAUfkKXkWekSAvMQdPrFzsybCXguBGwTtpmNK LMkpgVENq63uAZH75csoGb6XaRZJPatzjCSQ+ajb7nCuDlTiLrCwVy1f0eoMBcKyf6Ba 45HZua7t6Km/AbNCrbyGs3F/lJIOuTnIFUHWfgLQ8kt2HBxL2wC4plD6Pzr6SNvA7Rna yihddbVzbF0Ath6WpLqgy1uyHRQ2UV/9PfJ4h4r8yEgtFSnZOYno9xmYZqq8C7ZgH9TP y0FnstuoW3XUceWVUdsmVHz+X4dO9ea4fX4EMAjMEIfx1SClQy0UeZDZ0mbB7YoPfbyq st+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q5JQizw1; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a11-20020a0ccdcb000000b0065b05c86102si843932qvn.272.2023.10.17.04.57.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:57:20 -0700 (PDT) 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=Q5JQizw1; 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 1AC323AA88B0 for ; Tue, 17 Oct 2023 11:55:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AC323AA88B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543732; bh=PzsL6dsGswgTk344Px8h/e8d2SHNDgTIaBh2FsS3aXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Q5JQizw15SZsGnGymCZErUNjw+hcC1HbPBMSMB3ZQFpK8EmgDJEgmBhGFulKy8BUC GssRvDpy4jx1NgnXCARQtWOPy/h3TyDFSCYzVgL8fJo5ofa+naA3ObcRGpSN6kI4it ilYm7MjhFdOOEfrueLzQKx1TOMo1Ck0WvuTrgxFY= 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 A7B243889E3F; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7B243889E3F 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 A7B243889E3F 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=1697543048; cv=none; b=ZVO7IkyJWcbK5CJoBKNdA9oku+o/kGOpT5mHrjVe0HONdp4bqq/ep8+dWOraTp+29JwgL6uHVER1drGuGLNNhF4yd4S8hFycxYe1CzWxDV2F5CD4SS0F8cuO0PlDw5bdEaT452sFYNIScfWf2Q4s9MxSLzoyKDELxTfeA5LFCK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543048; c=relaxed/simple; bh=Gwln+6kReoTjeSwMaRkvh0PM3wCmQoJc6szbsyWoD70=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IH16Te3dOoUTo4vJsG25pFDvvcuZEJ7X3B4e0iu3CZEt90kOzLJJsx39aOiUzizKC/PANVhSKRiRw9vfUI2agSr8Tlf2GRT4AwIOXf2ri9nQifUqoO91js6/sQGtlGVQEaCJ2ZKNN7Gu4HpDm1/jvaOBWt62IfCXwdQJR+Z/KQw= 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 39HBbLXq026625; Tue, 17 Oct 2023 11:44: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 3tsa9e5qex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhi9d005654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGG020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:43 -0700 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 v22 13/31] libstdc++: Optimize std::is_bounded_array compilation performance Date: Tue, 17 Oct 2023 04:36:34 -0700 Message-ID: <20231017113822.677344-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2zboE6UMvHo53mGaGbXQG5YvdaJaxzxZ X-Proofpoint-GUID: 2zboE6UMvHo53mGaGbXQG5YvdaJaxzxZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=549 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780003208222706603 X-GMAIL-MSGID: 1780003729352401822 This patch optimizes the compilation performance of std::is_bounded_array by dispatching to the new __is_bounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_bounded_array_v): Use __is_bounded_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 cb3d9e238fa..d306073a797 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3532,11 +3532,16 @@ template /// True for a type that is an array of known bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array) + template + inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp); +# else template inline constexpr bool is_bounded_array_v = false; template inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true; +# endif /// True for a type that is an array of unknown bound. /// @ingroup variable_templates From patchwork Tue Oct 17 11:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076212vqb; Tue, 17 Oct 2023 04:54:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMEVksFzTiNc5+uMXiVrgReiEb+kPi24Z0YS4aIeG26HQ7Q5d80AaHzfXwoeFWGaBEz/Ez X-Received: by 2002:ac8:5714:0:b0:41c:b54e:ab13 with SMTP id 20-20020ac85714000000b0041cb54eab13mr528917qtw.26.1697543647893; Tue, 17 Oct 2023 04:54:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543647; cv=pass; d=google.com; s=arc-20160816; b=ag3Gc/MvcGsqVhhe9jXUGe6OU4KNs350NyidsBTBI6Qq+w/opXll4TbUMU3XFPGrge nSDOGuAEW41Lc4PJgiMp+GpIdet3msRqRmdRDhvX38mU8J/Hakimp/aQGy0YQuIllcka 3chmfXXibDcDeIj4yqxcxdAPpgvgWwX4PRv1hRsdfHFOV5GfbIb0jmZ+5d9SQD78m6gU 4Q4S8O+8KUkHNjZ13Dxqo2CAaoON8ntFZBKvK5+soeXew+gwQcUe4+CkE0G6m1ZGsIw9 YTEL0yRUTmIWENU6HNclTdGwir0JHT6QJGs1ORykLncW6H1WLiaYsmpUn+RX/AKnh5LP c1tA== 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=DRg/DNgFrI0TZpzvE9Ejgu2stthUWDVZ9VzyaTaKmUg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=JLnn8iGQ/l8Sq49wa5D3rfyw7DfFz6fkhwUU26cIxhN/Q8/V6gCQnaJoBEmsq+9DyR nxokQgwbBXs299GvvlDP62UlJtrUyYoeiiPjQE1H9Mwt4o2ca8ytQnupb01XL6e+Q1FR jy9zrObRvWiAJVpALN/0+MnZbqocfLQ0i0MxCW0FC/1CaomgxUQqYSkztXotADJLrGDO LWV4ui+FIK5KGvLw1OCNWWUZ43YOkE7BPJIUrakvXu8PDylw27W5bcoN9GqdrJZkY6Ol h7C+97YrG/B5Ct1DHV9ZAIM1ETeI1PxLUPuaBs9egTqDg9zB9kBWw1Y/eIxyxU0Jr2Aa ykyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=piKSGz83; 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 v17-20020ac85791000000b00419529edcf2si949698qta.391.2023.10.17.04.54.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:54:07 -0700 (PDT) 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=piKSGz83; 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 EFE933954404 for ; Tue, 17 Oct 2023 11:52:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFE933954404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543542; bh=DRg/DNgFrI0TZpzvE9Ejgu2stthUWDVZ9VzyaTaKmUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=piKSGz838HJQYdQHkSBg5AYFUNwk5Hi1qTUQm2iSg7F44vdXT8cTJR7c7Fs7hLiK/ qb4wJXYaTZ8OlSkvrOPaAw1l4duFfwFi7URRp9vjzlGwVbeoAo0LFpbvzKi3DL3jTN hzqPMMpdvrW5nlSpgQ2S+e8ETJ8UfZQpCFfMv70U= 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 8032F388212D; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8032F388212D 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 8032F388212D 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=1697543048; cv=none; b=IQE16BKte9rGpoJy4rYFJrjnAvrzHkTF8x3aLZ7PFOwmst3Sm/r1px+XCumP2iMM6Mj/018QAVyvxw3GTb0Mdz0O1ynDqZk0peAmdsdykn42puhEqXSUOLQ0/jvw/F/8aKeGHPhYNWhYkkvcTjzweg9qsRPmI4NKG89f/6m5Q8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543048; c=relaxed/simple; bh=fkQruCseJD3dB1E16vhUv/gGSDDVp/cL6/48GiYilPI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=V6lJ3+fTmht427PzPK2ZtT+uu5nw7UUslsCXX4WES4A2iDfPlZ8NBM/Kyn45f68OrFk1hKOnElYEfozu85Pt3wOEW6BnFjp5SqN6GkVXRAM/rmqC3xeNDQq5R16TyD9/k422f2p2B/M6f3ZH0Bph6m4p5bY6jizmpdRuA5hzWww= 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 39HB5Rpw012504; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tseh6tsby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhixH011188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGH020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:44 -0700 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 v22 14/31] c++: Implement __is_scoped_enum built-in trait Date: Tue, 17 Oct 2023 04:36:35 -0700 Message-ID: <20231017113822.677344-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: pC1-pZdsYp2-rbSsTkUkZGzMNV8MOTSX X-Proofpoint-GUID: pC1-pZdsYp2-rbSsTkUkZGzMNV8MOTSX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 mlxlogscore=707 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1776997580847515671 X-GMAIL-MSGID: 1780003528221633997 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.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_scoped_enum.C | 67 +++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_scoped_enum.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 71a40558881..2b46e3afa97 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3782,6 +3782,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCOPED_ENUM: + inform (loc, " %qT is not a scoped enum", t1); + break; case CPTK_IS_STD_LAYOUT: inform (loc, " %qT is not an standard layout type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6d6dff7a4c3..e0e3fe1d23f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index aab35c9e5ba..9f0e468f489 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#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) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Tue Oct 17 11:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077981vqb; Tue, 17 Oct 2023 04:58:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfT2YZcdt4WVI5mcgrnd9Aua0NdjzPszuGVCdPU1ZwfdAegnv1ojUcrmkQQR1sktdfbEgR X-Received: by 2002:ad4:5ecf:0:b0:66d:2435:b3f8 with SMTP id jm15-20020ad45ecf000000b0066d2435b3f8mr2290346qvb.4.1697543897098; Tue, 17 Oct 2023 04:58:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543897; cv=pass; d=google.com; s=arc-20160816; b=rJT/VyrE92k9jubOM1XOP5GhXrgEZtmyA0C6q8NUPwrLtJrvMGu0vWxFTO0FfOlK+X TWDjcwCAV9yEiJQ323XFctO7SVLQk91lUtCCJdBrfG6LRgB7jk/XGyyI5h7UCRtWA06Z Ujs8S5oLQE1aMpR4+soQdPUXlQIHMwFnXsjdboEKk85dFJnUsJfRogFBRyKhNkkBriBS WaPNWG5b9n15koCSmyOjonf1QTXpV5Jd1dKnhC9HurCBQZs2xj2O1z6hQuafUbClgkHW 3yvO5kIJR9KGSFNxs16nRBrSaub3C0WoksmqbOIlqaEJhQvyntip99K1qMJIj+b5yYJA B/fQ== 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=6w8/pu2bvouwsnUid4AK0QIURuqMXsP8R0XkmMz9DaQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=hVFLIGrta5yCIuMHutWhqdJ5VJBqDIY/RshVfsnJNiYMc2Qn2huohKeD16xeJ+QIJ3 reB41s4GvTpdG/jg9NcQQeGhuA6591ZaU1ZR9yqyjm6ZVRmgNXiEIIdOikJqHyXKlgyX 9IbMKaTYfjVU+BZxvFwMcb3AuaWk1wQCZABhhYX3RIUtTnHzIQHd7Ds9BKqJkzHvtuNg kPJccFfCzstqEiFpDOHf8v6o6aJwIDqpAmN5GP7msjQpUNKieeXC9GLME7r1Jw45XvzQ ++CMonq/UwxeFOZ0HQfP28gXaKmoru3a8P4o6zqOY8z+nHCQuK8tcEWruIUzER+2pfVl MxAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=B0P3VW8c; 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 t4-20020a05622a180400b0041953bee755si976593qtc.441.2023.10.17.04.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:58:17 -0700 (PDT) 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=B0P3VW8c; 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 1AF11385C422 for ; Tue, 17 Oct 2023 11:57:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AF11385C422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543856; bh=6w8/pu2bvouwsnUid4AK0QIURuqMXsP8R0XkmMz9DaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=B0P3VW8ceIaaNhXXKqeGp+zPFgYXMv2c/WDe6PjsheBGKCRC0eNq6I6tBkzu28vCt 0XMso+7wBopmsAKVWkXQfRE1ykKTQR8MqLUeB+ds+4A4c9tktNfW2mdRRRtHRo2wdN gVFTNOc99PVp20qf+HBUb0IF3+C1B1OTeiPy8zCg= 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 7C7FF3940CF1; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C7FF3940CF1 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 7C7FF3940CF1 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=1697543028; cv=none; b=xcMI8HY0ntOank/QSWScdVoeHbZVuFAyUDPPej3u5sJBV4vi+ztl7cV5KeLZ9Tk6afaLC8fGSHnOpRswbMOB34AsBBlNmGD2Knp7pUrw2efu0iDmDowCoVHs/y5goWHcGqVAQIAzOOhyWDpvRnnd7ndhlPYIDSye/KHO/dwuUGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543028; c=relaxed/simple; bh=0fJjGclj4XvwKH8AmhnNT3eHruG+WCMpFlf3cIH+UjI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TYs9QglIT6T3PzYx/25hu6dAyBJGenz98tKYQfcb2Sa6H+QbrUos57uvIuhuM8g9iYTZ14+7eF6rBhZZworPUh88/oldgkKSd4FctWr/9hD3vUSWoYy1xyPufc2WgoIwNb96bZwjX8uaNOMoYFxv4daikoEPwvxaP51/P1CFofI= 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 39HBdXsZ011422; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsftqt1ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhiBu029928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGI020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:44 -0700 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 v22 15/31] libstdc++: Optimize std::is_scoped_enum compilation performance Date: Tue, 17 Oct 2023 04:36:36 -0700 Message-ID: <20231017113822.677344-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: xEEeE9KfGoaVANNxlgwZKeHNY18QsII9 X-Proofpoint-ORIG-GUID: xEEeE9KfGoaVANNxlgwZKeHNY18QsII9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=697 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780003114363271989 X-GMAIL-MSGID: 1780003788972917490 This patch optimizes the compilation performance of std::is_scoped_enum by dispatching to the new __is_scoped_enum built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_scoped_enum): Use __is_scoped_enum built-in trait. (is_scoped_enum_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 d306073a797..7fd29d8d9f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3633,6 +3633,12 @@ template /// True if the type is a scoped enumeration type. /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + struct is_scoped_enum + : bool_constant<__is_scoped_enum(_Tp)> + { }; +# else template struct is_scoped_enum : false_type @@ -3644,11 +3650,17 @@ template struct is_scoped_enum<_Tp> : bool_constant { }; +# endif /// @ingroup variable_templates /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp); +# else template inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value; +# endif #endif #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp From patchwork Tue Oct 17 11:36:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076750vqb; Tue, 17 Oct 2023 04:55:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzAuQgiDlEDYuj3PcXzFce9wbFbEzq8BT52QZZWNfIkiQnyvHXfO2VBo/Pw3AsK6TomA+B X-Received: by 2002:ac8:5986:0:b0:417:a01e:e39 with SMTP id e6-20020ac85986000000b00417a01e0e39mr2171623qte.63.1697543732165; Tue, 17 Oct 2023 04:55:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543732; cv=pass; d=google.com; s=arc-20160816; b=aocnaNrEakOWV0bdRkKHAawbdz5dk19oMhENv8SHXRMBa2kwJ773MdbWIXwFPOT5Py 3aKJ+UNA26kRH65AN4ZoWjajHYnkzxUNk0VtgSpwDYRyyremznglq1VWM1Yb4kbXUNL/ ewEc/pMhfcu2RVphzIpIL4cSwCAjNVPh2pvSYxf4a+SSrqlIZLu+/nU4Uy0JFAnp6pdG aqPC78cUD3vx6qrJuYRVBV12IgGbTOQB60oVtpu2PXB25khcS8pDc6oXR7SLwVKfKRse IxEWrQj/edbOWkw3QxIxmF6vKH+lMVt59QinxN/bgbI2mh02dJqbdHTSKDG7Ae2y6tIb WegQ== 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=s0GI8LVbPVkNcH40twl4oGn8nFP7xw344PFmeuRO4tQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zxuAD32i4lN7RcOnUAwJ0Foqwj3YQUUwlfS3v0GZmm11tXEvddJrAB9RyRxkmG7Wuh qYM26MhOCeFx0B0AX5Nm5wyh9mD6WgrRCt8gxXWCdikdZrHK0W1Y28gsu2h4CApdMUSO HR6DMxjDwNBankjz481lzws44hFrFL6MGDLnKx0TwpuSSVCKqiZDwhqP4kwuXCcVrww0 1tKyULWZ6aRZR7u2YiE8+AgBf/2o+hOd0FozgYU/MGRcvqmpyCzECn7rAdmZ3qq+aOzC MSe6ZrXH4EI3NCTs2q8LHkEIokbV/dl4TsGZHwgWPQbKq0U10Ck+SZISPpYmNfy2oOax pnbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SjhObRkr; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i9-20020ac85e49000000b00417fd10f754si987132qtx.412.2023.10.17.04.55.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:55:32 -0700 (PDT) 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=SjhObRkr; 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 C22503AA900F for ; Tue, 17 Oct 2023 11:53:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C22503AA900F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543615; bh=s0GI8LVbPVkNcH40twl4oGn8nFP7xw344PFmeuRO4tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SjhObRkr4GH7jTL+FTXJQM3dFf7atwyM6g/IIvWAPwHp3iiInu3ZQiTmvtOdeYlrm PJkclFDK1JCek8D3qliZod/OtGOUlDCmKqYN6286+cnsXijOGR+s4jnWvxjxJR14To 0xYaeab98Bnh91c5AAqHUalWbVRbZbiTrkfbVw1M= 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 7D5E7386EC25; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D5E7386EC25 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 7D5E7386EC25 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=1697543047; cv=none; b=rfrVLxNt5U0cLycikuHKWZjXx2Y1xV3g9PCRIfdnlgqjjp8MBvcy9GjQ/cGhR8S0KuklWjXAjaj8jsRIG/2Ot2foVonv1MH2x39aYKbZRvpaqnK5j6+2zvCvesG+H3/Qkw4QuUITrukEPZjYi/sqyAAyWMk1f6a8luXbXTrSTCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543047; c=relaxed/simple; bh=tTsXR07ddbRuc8GHnZgjHVGOldxUmME9x4Iwp7/K0aM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Lvgtf/LhZUg5mnWAn14k7Q09/P91S+ovh5IZs2aF0HyRK2hrLwu2RWU+gdU6hytVPfR4T63zRKRdn/smYVZSNHXvfWR4TOnXzJLLbHljM643j0CZFyJN5nHrLSzwJ+hRTBWYYf7tTuCduZJa6IkMU9irLQS8uLnlt1mMKiHnbuU= 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 39HBRXI4001961; Tue, 17 Oct 2023 11:44:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruw60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhikk005655 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGJ020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:44 -0700 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 v22 16/31] c++: Implement __is_member_pointer built-in trait Date: Tue, 17 Oct 2023 04:36:37 -0700 Message-ID: <20231017113822.677344-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jby7t3jyX-vSDjrhMXeYNVG71SlyCGJU X-Proofpoint-GUID: jby7t3jyX-vSDjrhMXeYNVG71SlyCGJU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=856 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1780003616451423614 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_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_member_pointer. * g++.dg/ext/is_member_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_member_pointer.C | 30 ++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 2b46e3afa97..a969a069db4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3757,6 +3757,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_POINTER: + inform (loc, " %qT is not a member pointer", t1); + break; case CPTK_IS_NOTHROW_ASSIGNABLE: inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9f0e468f489..5ca05dde75d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#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) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Tue Oct 17 11:36:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4078371vqb; Tue, 17 Oct 2023 04:59:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiK8Olvd475dM785t5Zsr6qPoIvURWo4eoNoieuXnNmg1JTX7RV9iCYfslxROMvLOn6L6Q X-Received: by 2002:a67:e14d:0:b0:457:bf4d:2ee1 with SMTP id o13-20020a67e14d000000b00457bf4d2ee1mr1994713vsl.13.1697543949806; Tue, 17 Oct 2023 04:59:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543949; cv=pass; d=google.com; s=arc-20160816; b=Wqd8CN15pSrFNy1smli0OWmB/n+nwylO0Heo9VcIApo4rkigwvBpJ7YPigQN2xmMLJ /mtx6bmSY1REMxO1HAPlSKv/uRK8vFkGuEX81YQsz1Ct+53UZhIzUTV3NPB0rTrXrmiw gYfwQ63fwxu3CQVbbBfXJuS2efuxHbCpO0MU+Fi20wR/lHq5QEFzbLOKpOup9Qm4efPs HLKCzf2yeD2FDJwRXTZbPka68UL5olyxpb0Vrc79kjNtu9YduXvYxi7y7PlQmUhm45zx gEXBfEwBPuS/GWgY388fHIkmArCLNW6abYWNbWozwk4B86+U4akSS7BhG6yTM0C+1X4J Dr1g== 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=5BCqGLNSCmRaXPYuqqLubmxriN2Rx4QdNVL9gnlY2CU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=KFmZwSNhmHwVd13ySRd0L6k0DR5T49nzCaS4IMNLsgloed/CUmouOefbRXe2Z4M3mL oJr879I3R5GzWnvNF3DUEiWpeYE8VeNyS16w/HRPk1pDOQdQKGGwTkkg0s8d3sRZQ8lS 1isfwbky7bTdZgzMHcnAhv0YLbipRUVzmxyuoUO/HY7ak0gMKa13G7hXOhnYSJ8nXZZF Rbv2nv8/7iMRgVD7Jd+78AuuCqVHSTFC2f5h0B0xyzTjStHdEDjWPHo46gifoo7HJmgD RQleInrBwSS3xryK4FS5PILFh9+CIPl/F1P9ewEGma2tSVUKd5y3+SD4O+b1oltPZ/lN a/yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YR87OF83; 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 dw12-20020a0562140a0c00b0066d02306e73si868827qvb.169.2023.10.17.04.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:59:09 -0700 (PDT) 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=YR87OF83; 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 85517385843A for ; Tue, 17 Oct 2023 11:59:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85517385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543949; bh=5BCqGLNSCmRaXPYuqqLubmxriN2Rx4QdNVL9gnlY2CU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YR87OF830iWmzElX+XfCjD0XhdeId5tJhxdwn4KFmQgeLvIxIta0k2G1P+94on9r9 +gv4KumyaRK3esN3ZIxurMfj+FsJQHz9V4eo1DdJz6c+FQftyqUhPri3m8SLhRvTk4 IDRtKFo6KWD7Pa8nsnncO8rm+RISJe45vakdf2lc= 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 ADFA238930F6; Tue, 17 Oct 2023 11:43:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADFA238930F6 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 ADFA238930F6 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=1697543035; cv=none; b=MOj6tvHxs1d/eMTNvjFdb/gK70aUh5fXKFlNxxf5I6kZml9J8ResU6SS5SBbPIzVeoqDLGSsUSWIcwypNPSoQRzsvuF6QzTBxoib3H3PkshwTztGEz3mtcM53SHCKozPiXXtTE0eQ3OsTONYWIhZLs9tZC38Ct6POacNGJJ0jKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543035; c=relaxed/simple; bh=f8Yn4ts+8fO+dAvSx3E1hRc02AnbIXSjgLj2daX9YKc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=eb4ONOla2ANCI1GXWXeNxxUhfwERApEOq/2Zu3+ETdRHVCGmYSMYneEeYPnIWcYDpPuFJhXIOajuhp9ayg0FbFZCtuT7S7uG1p44KTAeogUB8BVto2f2wig59v4kQKZ0zH/P85vcM9wA4WY8RrJXitKTjh3glH7JcMIVjGUNWi4= 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 39HBdnZF009672; Tue, 17 Oct 2023 11:43:51 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tseh6tsbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhiT3032356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGK020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:44 -0700 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 v22 17/31] libstdc++: Optimize std::is_member_pointer compilation performance Date: Tue, 17 Oct 2023 04:36:38 -0700 Message-ID: <20231017113822.677344-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ng5LdJ8-LV_n1rnkgxu6465k7uOQ2S5I X-Proofpoint-GUID: ng5LdJ8-LV_n1rnkgxu6465k7uOQ2S5I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 mlxlogscore=508 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780003567680885453 X-GMAIL-MSGID: 1780003844287097920 This patch optimizes the compilation performance of std::is_member_pointer by dispatching to the new __is_member_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_pointer): Use __is_member_pointer built-in trait. (is_member_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7fd29d8d9f2..d7f89cf7c06 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -716,6 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_compound : public __not_>::type { }; + /// is_member_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) + template + struct is_member_pointer + : public __bool_constant<__is_member_pointer(_Tp)> + { }; +#else /// @cond undocumented template struct __is_member_pointer_helper @@ -726,11 +733,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; /// @endcond - /// is_member_pointer template struct is_member_pointer : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif template struct is_same; @@ -3242,8 +3249,14 @@ template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template inline constexpr bool is_compound_v = is_compound<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) +template + inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp); +#else template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) template From patchwork Tue Oct 17 11:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077478vqb; Tue, 17 Oct 2023 04:57:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxE5xMZcJWEyqI7d81fsOA5IPSfQjYOpN+UnOz+yKgsGKZ4KisEB6hzsXIcwux43f5fbxY X-Received: by 2002:a05:620a:4481:b0:772:6384:f8e8 with SMTP id x1-20020a05620a448100b007726384f8e8mr2304343qkp.3.1697543825949; Tue, 17 Oct 2023 04:57:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543825; cv=pass; d=google.com; s=arc-20160816; b=0+kkA5VfGaUOwrBbP71OprpFCWk2glQI5xWo6oUndOmdDp2eyPLmuTD+0FovJyXYys EaDjC1URr3f5UFV2aBHdGGjRhEKVBdQ9ZIckUy5Dcb/yh3Ra4+TCk5PoDnY/IBsLNX+s DqMYgaEAaYmn4Kexa97+QgGs15H652dKvotinwP+XjIkreMXqxYirDKSIhHpVv4WSq37 fJFqN2ofMfxqhFlBp6DWxSlZHbn7R9Mxr4lfE6dkorHgLS2sYPPXh4TtQkJHpK01/990 UOWISw8Miev3sPUV9UsjkxQudUmL7wDqlMeJgndrI5Uo2v59WZbwlRe33bUtCh/0cYQY JHag== 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=bvd65+XKCvGzi4qTtRK6nRAEJc68Wgj0GRC0JgEHuPU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=iNaPsj/sNMtAboGeaSEKggnQ0yn9h7ukdhaLhNuTlG+HCpOip3jWQ502EbvVqq3tN7 aM5xUMgMvktq5hNro6NrhFr4JKBevmLdXiB7Mn3SyapCQXcU5QQwHmkKC6HlmaECBZLQ qCodNLQeMu6/s+MJwPnQn2FAye4BUSolRpuV1koOC18BL1PQhdtpCDhzxTKL+JWM1Olc vhNVOwbLfUy+SsZ+6ngix1XsMBwi9564VSMKi9RqEHO2dywEXmmqYYEYbLPQSqa+Vywi Se8y/60Nc0d5AhhGWtw3hK+Wpn7/hux5kujZqp1BZ6oy8JY6Uqf1sZEg0Mi2H9RfzZL2 kx3Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XDFX0D9a; 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 y7-20020a05620a09c700b007709278367fsi904133qky.497.2023.10.17.04.57.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:57:05 -0700 (PDT) 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=XDFX0D9a; 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 70D3B3838A2C for ; Tue, 17 Oct 2023 11:55:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70D3B3838A2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543716; bh=bvd65+XKCvGzi4qTtRK6nRAEJc68Wgj0GRC0JgEHuPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XDFX0D9aqA95Th/t6+z3dhZlPCAvH4wnsqntUwV9d2QjoCMjj6yR0C+JL3wMUPbtr JUdpVge8nzvU4v/ZEi/Gat6VRZoYJegeN5tXi42/UzgXxGIsoJ5avET/52Fw98BwuG zyjbBuVc7sg3gCZCOu4Oag+OPym8iLE9973/ccdI= 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 A555D38A8177; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A555D38A8177 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 A555D38A8177 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=1697543049; cv=none; b=UrRSaGT+VSy/pUResWymFMMNBPhhGfE0WxwV3sLxr2VVb6hHOzdzxC5huoX1UHjbUqUG6rBEFqT+eppbIwJb8YItLqoU2wRjngYpZ4zMNfitLWXb9/k1P1IJwrVaEU0KwVXWtkA8U9ZDDgxECrBjdpa806I5v19CedtFJjXkrKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543049; c=relaxed/simple; bh=Wu6uxEsGT7DwvMgeZmQ/CUhdHfQIMcBEaar3J3BUDrE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ClXfm8N0DDxFBxp6i5jhu5qXv5Uoex2TUJ5WT0EWoWnqTRriU56qVb/9z3SqHIoCOwOQB4bWIEDC56q7lXm+NHDSrpJd0BMNP8JvPHkaMo+Bnv1QcxR/SSR6MF5c6GAJ7iLoTMhF9AUd7XbNaHpXCaGShCBSuQ8OjnLK1LD/Pwk= 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 39HBVXnI022425; Tue, 17 Oct 2023 11:44: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 3tsekdjrvr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjfR005656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGL020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:44 -0700 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 v22 18/31] c++: Implement __is_member_function_pointer built-in trait Date: Tue, 17 Oct 2023 04:36:39 -0700 Message-ID: <20231017113822.677344-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dcVEbDXd4NbIVYPDbyOfXLMI4jU15ZAg X-Proofpoint-GUID: dcVEbDXd4NbIVYPDbyOfXLMI4jU15ZAg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=911 phishscore=0 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 clxscore=1034 suspectscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1776995491422845008 X-GMAIL-MSGID: 1780003714924405992 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_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_member_function_pointer. * g++.dg/ext/is_member_function_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 ++ .../g++.dg/ext/is_member_function_pointer.C | 31 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index a969a069db4..dde83533382 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3757,6 +3757,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_FUNCTION_POINTER: + inform (loc, " %qT is not a member function pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 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) 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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5ca05dde75d..59aaa256232 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: 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 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#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) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Tue Oct 17 11:36:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076330vqb; Tue, 17 Oct 2023 04:54:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDg7PI8pmipSQfQKvwuSrDk7OUh9QLPN+pSPgcRA6J7G9aET0X2tKRiW4VgrkBObkc1Ept X-Received: by 2002:ac8:7d45:0:b0:417:fe9c:6dc0 with SMTP id h5-20020ac87d45000000b00417fe9c6dc0mr2890156qtb.16.1697543665928; Tue, 17 Oct 2023 04:54:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543665; cv=pass; d=google.com; s=arc-20160816; b=QmWtc/7+vwa5k1fC+IFbMGwixg/fUisXiny87tFAAck0Xkb+6FyeoFjRqmDH6K9miD AaMsUOtLpxdyw4TeO7zgMOp0wjQs2G9k11UvCxxAIFaWCMIiWYuDo6nDECv1bLo6uprF S4BfSL18oO7wFRurzh0YFXEEL4phtgFnKVM7f2Y144Y5Fq6+ATSOyopUzX+mekY1K8qL 0V6G1HYpV4A7sZw4lp0D4NobK3Uc9yySGGeb+bKp2P3jI6ytSX6UY246+eH5oQcIGCbK +eiVR4u7nsWgTM4ntBrTFdREFUUzakmbl8UGbMlD98pbS7AuBGmttxnjFj0TJrbVAdrs tH8w== 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=N17T7aCitw2LumMHTmS+gL4bmQewOjA5Ej2IDLIDQ+w=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Bw4ldCjSFJf67M684jJDMBxl+zsbYSKqFrKHn+X/TdmphePRrg4WlCykyi/19GHEFS 7tFVAJDTYmlzzYMtzaIcwRrLK3iDE4qZxzEwo3kfkElOHXlnVsI1aXjFprgZPe3n3gYu uJaDClMbGIhDPdbU4RdMKRox8ykAwOUFH/HpZOuvbtHd5YpyHhY+7Si/WcjDLAuScYrN GmwFAhTUUfaMlVgwxguaURaMASxXu/zCehe24zvmGGj18ywrduyoISc3m2hMKlWx+3H8 N2aTIVlTGyumbQY5o6elxBUClmCWd+Cm30B+pLq7Rn84PBxtQ/HJoDWWjRsJZHvgK7zd SCoQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i6HNuLRD; 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 a8-20020a05622a064800b0041819819519si982697qtb.694.2023.10.17.04.54.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:54:25 -0700 (PDT) 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=i6HNuLRD; 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 0DBBD396DC2B for ; Tue, 17 Oct 2023 11:52:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DBBD396DC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543556; bh=N17T7aCitw2LumMHTmS+gL4bmQewOjA5Ej2IDLIDQ+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=i6HNuLRDB/hTgHAn6sm0NU9JfyI7jzdfGjD05jAIFdKsCWrAtSiJ1ji24XYUack99 A3FECOnEqIqIEt8c/hbUqeohlnsREcSJz+Tsd+jphAeCd89/5PcctKFnddJUUA9S8x zUjQtUr1F5oykBhgejX0beNgLIFvfYGfMK/Nlxxw= 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 678BA3882100; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 678BA3882100 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 678BA3882100 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=1697543046; cv=none; b=ehRMe7Vlg8O9S2nRDxftMmLikno+VvyMr6EEO2c1gkoQ4W7MSSKcEKikL/FDU1Rf5b5ZCE//4S8Fbzlakwzlg/Reb3soL37oZgEWmmETZmxK1JkDBV5ee9d0ZPJ31IuXLUc2CntRzR4KbnL7tDAglTQ03OYrAekqjibjFekoNBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543046; c=relaxed/simple; bh=BeAwYIzK7d5/iToyc1oLwLq2kGHJhlp/l7AS5fX4HMw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JEDyq89g2ychJcWQNvce8j3AJQeq4COSqw5SCV4bR1rULbV27CfCsmBuJgusjf2E2e91orxju/8WpSwFKJBQjzzLLbmoqsX8eG0DHQaSzaemTJwUxi5UlejZaGtrtWvnSdFVZ45fAr0eUhwnCUYOApwq3pHGj/dCGf7KK9RBtLM= 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 39HBbekR007330; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsftqt1vc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjXk011191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGM020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 19/31] libstdc++: Optimize std::is_member_function_pointer compilation performance Date: Tue, 17 Oct 2023 04:36:40 -0700 Message-ID: <20231017113822.677344-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2Ki6iLkbfIwcSE7SBToe6JtAqoqGtE_7 X-Proofpoint-ORIG-GUID: 2Ki6iLkbfIwcSE7SBToe6JtAqoqGtE_7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=594 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780003547168618314 X-GMAIL-MSGID: 1780003547168618314 This patch optimizes the compilation performance of std::is_member_function_pointer by dispatching to the new __is_member_function_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_function_pointer): Use __is_member_function_pointer built-in trait. (is_member_function_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index d7f89cf7c06..e1b10240dc2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -588,6 +588,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) + /// is_member_function_pointer + template + struct is_member_function_pointer + : public __bool_constant<__is_member_function_pointer(_Tp)> + { }; +#else template struct __is_member_function_pointer_helper : public false_type { }; @@ -601,6 +608,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_function_pointer : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// is_enum template @@ -3222,9 +3230,17 @@ template template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) +template + inline constexpr bool is_member_function_pointer_v = + __is_member_function_pointer(_Tp); +#else template inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; +#endif + template inline constexpr bool is_enum_v = __is_enum(_Tp); template From patchwork Tue Oct 17 11:36:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4078050vqb; Tue, 17 Oct 2023 04:58:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkHzA7sGCF1Ooj+hu7mFJNJqZJk8ur+CnIXPjwhTnTvTo2Lk9rRNaBhfYLe9kiKG1Vk0cE X-Received: by 2002:a67:e1c4:0:b0:457:cc0d:6298 with SMTP id p4-20020a67e1c4000000b00457cc0d6298mr1755098vsl.27.1697543906470; Tue, 17 Oct 2023 04:58:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543906; cv=pass; d=google.com; s=arc-20160816; b=sZqCmqLFw4ifxDslyN+Y/Ni/D3NW6fACVrMcs0NiVP9ZZSlS1QcSGscU/HVvA5gQ3C h1a5fCY8fOFbs5R81oZUtdo3IYX5/2n5je2VMPQ9KhZMiOIQ0DixQYo3ibNsotUgtzWY jbYEhaMB7fIxVUeuPieSGwy/rj7mHi4qPEoH/P4E9qAaUy1SuwIQJsWWnS5tiHr/sXzA NuEomIVx2INk9gggp3QeLbAd04uixOjNdVVLTWJ35zVrNPAwoLiHLXu8KtGShRjHiI85 XwLpzgke5ncnk7F22mWL2LnY/E9htM68L3RLbVVnec3bPuEYEK5468ZVSTTmUU0ymKzf LXNQ== 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=gGBdcQ+YEc4rY8cO7yuYgGoal2BBq3pAmBVeJ2+PDSI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=N/tG5Mizuxb8VPioLElLy2QpM2mq8gQjP/MJTITLVnWiU6Jf4x5qm1YzMTu6wfe17L B6w+q7x1UVr5B7gDdPP2JGzKgK3tycRlCGwTbzSDsk3SgXIN8ll8e9VdaL2aX+iWNLqb 2Cshj2y6zzOTKBEL98jAxIrUnTiTn7dSLmHUavTthfJrWH8ywX5gbbLXC90sI0J3noJH MqPIy98UDkzUXoK6t1xkCL+CWu1SbBkhao/b3FlcE5/gzhmjD6lgcQFmcDX8ncLzUkH4 YM95ISOBAlkmbHp7sI38BlVUTzDMa4qCaRV8mdUChzhDNSUMIYyYlWXlExfnYG9JU3B9 2Rnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WCkQuXoZ; 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 s6-20020a05622a018600b004181bc4d5cfsi973160qtw.642.2023.10.17.04.58.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:58:26 -0700 (PDT) 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=WCkQuXoZ; 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 1061838618DE for ; Tue, 17 Oct 2023 11:57:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1061838618DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543879; bh=gGBdcQ+YEc4rY8cO7yuYgGoal2BBq3pAmBVeJ2+PDSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WCkQuXoZFNvOXnXsNpI7x0QLcSHaIcYjdsY+PbV4uom96gmaqUZrVB7dvsTp0Oiqq 6Q7cGQg/6h9MW/c9biZ03ealfR+xfqpgRLhp0LMFq/pjWaza/Y5MVLhZo/oO37CJa/ JL49EqnoP85/nov0WUk8mjMteF6+DFZ6+20CpNiw= 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 5C64D385C6E6; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C64D385C6E6 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 5C64D385C6E6 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=1697543045; cv=none; b=wYeu+CO45ihbXus3Or+L4E1T2z8JTsMUbP8EOXTznF1EXvPmgUC1TpaHmbvlKyak44chrigAlrK3Y6upcPufBzFqa8umz4xma85m2x+ZShwd+0gAqWG9gkYEf4b3J6YHQ7N6qjQXk/UPEmlsS1h3Kwxh1UK0bgJD52/IZ/dF3OA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543045; c=relaxed/simple; bh=UVqQ3VYH2YZi75SlDBCPNmo7P0UtuVGM7vsj+lXPHGU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=pt2O4OKlT9CNzoUdyGviTtqvgR4CxG22u7vdyzDxqQ5X5w1IXZm4NHexFq9USFw4gHxp+oXDxlTyCKPLsyWttvQLUl81+pHXFPmsrU8Ei9/o/BAejJDuiSIovZyhipjTLYHEJ3AhzKPq3evivl+k9ktqCvxHQXNRK76aed6xYTg= 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 39HBbuCG008299; Tue, 17 Oct 2023 11:44:03 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb6cmy3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhj8V011192 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGN020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 20/31] c++: Implement __is_member_object_pointer built-in trait Date: Tue, 17 Oct 2023 04:36:41 -0700 Message-ID: <20231017113822.677344-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: uIHn0uNVlDXZpf6nNG7ienVrvLKjHdt8 X-Proofpoint-GUID: uIHn0uNVlDXZpf6nNG7ienVrvLKjHdt8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 spamscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1780003799280839326 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_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_member_object_pointer. * g++.dg/ext/is_member_object_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 ++ .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_object_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index dde83533382..9db3a60943e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3760,6 +3760,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_MEMBER_FUNCTION_POINTER: inform (loc, " %qT is not a member function pointer", t1); break; + case CPTK_IS_MEMBER_OBJECT_POINTER: + inform (loc, " %qT is not a member object pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 897b96630f2..11fd70b3964 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 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) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) 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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 59aaa256232..c7e6396370d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: 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 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#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) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Tue Oct 17 11:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075369vqb; Tue, 17 Oct 2023 04:52:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELpBJu4gelaSw8AkkqQXBM+4s+f8/bo6OykbDqm8VhTMkVlqtxS6sXSkUvsf4ZzA6Vkp/K X-Received: by 2002:a0c:dd92:0:b0:66d:fa4:68ae with SMTP id v18-20020a0cdd92000000b0066d0fa468aemr2179288qvk.15.1697543522381; Tue, 17 Oct 2023 04:52:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543522; cv=pass; d=google.com; s=arc-20160816; b=jU2dwGhGOvKExwXsqaTbyQt4Pw+4VJQU2hmErhk645+/iabj5BivbCWly1KoToeUWm 6MQc7ZNWpC7Eum7ekvo2/8hFWSpqVPGlzexHCvWcG4kRFahrW/BajvHBeynYz8Di5z7Y l9Jz2BDzx1FIxPTIF3LbEMy9UdSkLY87lvSL/RMfviRUBLJtXjWjLylzvZMvdNHqOs1z 6eUvuGtNTleBHQmpsUK2AU0Wi3dgxWQ5NCt2AzQZZbjDEMjvb56K5hW+Hx1cTD4dw39q WmntWEvWsaCbMaWzqCwHK14qmF98dtpuV3Sat0PIhV7X44aRuwDPm045y7t3wKlihMwr TZ9g== 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=QyCvgHiTzY1jFYQtDMBYvJCe9IRXOXlXmEJ8y1zP6vk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=rx1wPwjIJWhvnzDYhPLZhlLtUXR2ZeTTsfh9cvcO10+o3/67wl2BUfP9ooziz7HW3/ Mdz0F24ADI3YvfA6KnCfpiwFigq1ZWmkWy31YBAAsnTya1TER9TSBKgZQHUssFqu+XgA WJszAPY8k//m/pGAk/9WQjpK5qsPAySgdaDfXPfgAEexg8uw0FwpAg+UFXEBGT5lznDd lCnP/Xlv9qW25KAGxJBXUtbsRrPQA1oGDXSzgtwvpE5yn5WN1rCwG4R3RzmY7faolo20 2j6TKgIgkwp5aiapR0WytNDJ8smkrXxWfvqkRRO+mJ5voZCa3QbJqQ90ANmW58mO8fWU Mfsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nhRh2Nho; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f10-20020ad4558a000000b0065af751dbb1si828193qvx.448.2023.10.17.04.52.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:52:02 -0700 (PDT) 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=nhRh2Nho; 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 6A967395BC3C for ; Tue, 17 Oct 2023 11:50:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A967395BC3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543424; bh=QyCvgHiTzY1jFYQtDMBYvJCe9IRXOXlXmEJ8y1zP6vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nhRh2NhoWqv39/R2BB9ZkelESpzb/7DorIyqKhIX0G/53MyKb644R34PoxHD5VjEb OWiKWmcet2uT6Jl3jTUaHEmTpqbXcR6XidoD8vL4zkbd7v/iCYOfBjakpVufFonj9j T6sO/eyPM70E4NBGTiFGFZ6s3yfOj7vxxq5RxCtY= 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 86D7A3875DC1; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86D7A3875DC1 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 86D7A3875DC1 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=1697543047; cv=none; b=b1gzWbIgnApenYzSYrgJv69fiA46un4ohNWEnUZBreMVaEdl0CB/nQyUU7wg5hH1AAxQoV5YBDeax41XhvVgCXb44cqKc9DSNB7bypigx4Zg3ZmUW5J1Otsv0jQdBGNnTi0xH8gS/ZWrdahrPNPwYKjIEt4Jl7Eg3smbvvI/BsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543047; c=relaxed/simple; bh=xgV0HhbeIOEZQRGv6DisRL5pSBe9b6hh3c7MgByCqhs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YHPZhN/WJIphFbTaa8lgMi7eJuyV/QqUK4L5jMp6uKC2WrigbKlod5tbkEsRKAxUCg3LFOG0W8GVqNP/KW1uTdo+x1CZpi62eS/9jc3uSxyi69aTSRXRybizcVKya9j11XWcWPVx6zw3tY46216nDES6NMXJzb68xTw4IYzgDW8= 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 39HBdPMA031264; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsa9e5qew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhj7V011193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGO020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 21/31] libstdc++: Optimize std::is_member_object_pointer compilation performance Date: Tue, 17 Oct 2023 04:36:42 -0700 Message-ID: <20231017113822.677344-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mqYy5fGA3XumZj_0jrVweziUPKam7gvy X-Proofpoint-GUID: mqYy5fGA3XumZj_0jrVweziUPKam7gvy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=645 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780002886817829020 X-GMAIL-MSGID: 1780003396968866274 This patch optimizes the compilation performance of std::is_member_object_pointer by dispatching to the new __is_member_object_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_object_pointer): Use __is_member_object_pointer built-in trait. (is_member_object_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e1b10240dc2..792213ebfe8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -574,6 +574,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_rvalue_reference<_Tp&&> : public true_type { }; + /// is_member_object_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) + template + struct is_member_object_pointer + : public __bool_constant<__is_member_object_pointer(_Tp)> + { }; +#else template struct __is_member_object_pointer_helper : public false_type { }; @@ -582,11 +589,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_member_object_pointer_helper<_Tp _Cp::*> : public __not_>::type { }; - /// is_member_object_pointer + template struct is_member_object_pointer : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) /// is_member_function_pointer @@ -3227,9 +3235,16 @@ template inline constexpr bool is_rvalue_reference_v = false; template inline constexpr bool is_rvalue_reference_v<_Tp&&> = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) +template + inline constexpr bool is_member_object_pointer_v = + __is_member_object_pointer(_Tp); +#else template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) template From patchwork Tue Oct 17 11:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4078870vqb; Tue, 17 Oct 2023 05:00:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERj5wPObh+P5p4sUZNfcWqzdWETAaUd3UDIBGhLOj7DhF6JjsdrlXJKuYp+RzS/qHyTs/M X-Received: by 2002:a05:620a:3946:b0:775:8040:edf6 with SMTP id qs6-20020a05620a394600b007758040edf6mr2281888qkn.48.1697544008977; Tue, 17 Oct 2023 05:00:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697544008; cv=pass; d=google.com; s=arc-20160816; b=Wj8Qch2Crvimk+2lQM2qAeTi5jOiw2bg43fwJnu2lJ6pduFWzC0W8XjlWQb3YiLHuC 5U0v5X0TR1a8bmFSSa3vElTSKkH573FvL46XYPzc4ULAO9HEosO0vz1yqVajdr1xnXi7 bu/qIsjzzJM7l6V4lhfE/LJWZsek+vFaHzBFwqO4DeMfYYI97dGsQK8UspiNlX3S9hAy UoD4niWYdTMMjVtNit3qeofgK1i+oGVEtq8zLoRGdNjq+2MWNwKNjypKESL7qBnw0GR7 6jr4TDIm/+9BzjJwuTnteugvBkohRyNOImlxIoP2uZp0t61EvnIjsp3Ua8iiTcuw7Q6c Y+FQ== 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=e62m0jOUnR7I7vTRzZ7uRVcwuOT6H45wBZ0/PmMVg/k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=dbrkh+VJCdZE0gVywqqc9MLKPxyQPSCWC/ZWqNqILW3xR3gPB2WeAaQ9mj6og3pyOg pFCt5B1hVTExIl8/v1lWsP2VU/QO8CpKKhme2Ow7y1bOTHGaZ5+RT7Izdxo6oqQGBZQd fWh5YzWKa7yo3MO81E36SQaNrp/lf3IODzMqVAlhu98swDgfIro9fg1OZg5Fd8wXWBAt N0sNNJVLZ24+FOkrGDKd2zQBU7EelzKUUamHfWONchaL+LS9X9WleQ9Qzc1jSD8aHvPP TNtgLyeNuOzaPKh+msinmxE7anruBF7hJB6CpncLUvmelAVnkGXFpRKS8NFqbd6XjLhy zXyQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dO7ZQVbo; 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 f10-20020ac859ca000000b004197e89b6e1si967709qtf.474.2023.10.17.05.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:00:08 -0700 (PDT) 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=dO7ZQVbo; 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 291A7385701C for ; Tue, 17 Oct 2023 12:00:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 291A7385701C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697544008; bh=e62m0jOUnR7I7vTRzZ7uRVcwuOT6H45wBZ0/PmMVg/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dO7ZQVbo+peBniDQF7kNHZlpsKu6y/NdSJh3GhWtYHpANTsU6ULy2gkDTo93UpW0E dWGbzPVczGYHyOYAoktYIKpZx1SD8beqSBKib0rKBUJF1a37Ltapp3IJkH1DZPMUWR c9hZQm79cOIs96ItDWvMj1dNIhuD4nNNfN0ZpTTE= 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 DE9FF3947418; Tue, 17 Oct 2023 11:44:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE9FF3947418 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 DE9FF3947418 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=1697543045; cv=none; b=rqlc80afuMuDGNvyrvbgxrqx3XC8Du/ciiye97lOKia4cBBHw+KGi26s19R+DLDAyrU/7qdLxdR8DP8U2GQvjscfZ1kcddihfCFFsoA3sv3t/vs648Gra+FUES9ITngqfkv2W8oYRd5WsgNF7wa+RnSiIQM4TcBe44MDo4ubJ7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543045; c=relaxed/simple; bh=44mnHb56z+5WE1rdQYxHO5/55BkAITix9zVSDG7Bbdg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lF4BcjG3PyQ7mL1m85AKbIf5WMPEnyrbxDyQxR2qPyZe1TpvloMkczDKvet9uw2ZhEPew12Hk8ZJNmrFJZld1Ol/cHX8uO/8ObJt6A4nU1WCEiboWFHN8RDzDAAuFcCNSgfcZG8DVQ6c+lEd9ZCpiDd5k+ltTCQvclcMfCACT30= 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 39HBRY1f001998; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruw5x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhj9D022394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGP020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 22/31] c++: Implement __is_reference built-in trait Date: Tue, 17 Oct 2023 04:36:43 -0700 Message-ID: <20231017113822.677344-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: XHSmf4BdW3h6mff9xcvYWexz_KtGJb4V X-Proofpoint-GUID: XHSmf4BdW3h6mff9xcvYWexz_KtGJb4V X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=743 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1780003906645586118 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.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_reference.C | 34 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 9db3a60943e..e05d4fa4d20 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3788,6 +3788,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 11fd70b3964..e867d9c4c47 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index c7e6396370d..cd17cd176cb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#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) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Tue Oct 17 11:36:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075798vqb; Tue, 17 Oct 2023 04:53:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkeCzR/4BiEIU6VX1bsQu3fM7nJmrdTrytFAtCX5AlYah1F8RjHl7wG00GTjHLc9Tz1TmX X-Received: by 2002:a05:620a:37af:b0:774:139a:e442 with SMTP id pi47-20020a05620a37af00b00774139ae442mr1855778qkn.76.1697543584435; Tue, 17 Oct 2023 04:53:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543584; cv=pass; d=google.com; s=arc-20160816; b=BwGDYm2dUvBRyk8TjAw/r5BYTZ0J0EPsBBZHavgt4WQBi8nLo858XTooNX1WHrmSpP jBnSVy5QBVjaAvY1lni3ewEEMlHJe1jd0dkKdyAL3A1boG2ib94QXEqrKUhGBCmgziRG LXeAa9++WsXRlKGvAWwBWDdrtoLkr0fSsKYfNH5cdbjU3z/NlF15hMCK0jXlT98NqHN8 +vjkAiccatwfrymdObdpxCnz2XxNzYGp8Q9vmMEEXj2ePOH2GdC9dgze+/SnRckyuo4/ W5odbfi/0ld7wqyUMiQIL8J+9rH28etjsh3hVS4EYDTt37A1HgDo5+otl9UHGDN9LJqc C8cw== 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=rD9Ixo1azXYHHHB/BRXQ4O0ZhyFrXng+m93wtWrxPGk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ljd6qA6bi0VA5OdJqsL1fM2wAGpKeHIy1ABbcqAwWR9/+M1ygLZ+P3kY8oTm/gNhcC 981tRfuKkJfJA6OEMgSTHuxaUr45eTQjwLF6CRa2kBj+qT6W6DhKDc4yQlTk8R4nPszN nNy/WEmdid4iKzu09SnC/3GCXlymzT8HQJmaSOYAUro5Bf5aFXtSr7VCbkfzykIyCroA LNdXGJu6NIsCk1grMMkkjtHN77yDRn8a0RW+KIpuMmsGOCa8XwGsOVBPVE0oI2AE5vqd 8UGYECxom121jUpFs3FFpk/acMGVTAMW/ppmrklbBU7OlY2LCZibCA8C7e3ui5YdhEoB bowQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=scgwGZBM; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o9-20020a05620a2a0900b00773e066060csi961194qkp.296.2023.10.17.04.53.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:53:04 -0700 (PDT) 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=scgwGZBM; 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 144C238A9096 for ; Tue, 17 Oct 2023 11:51:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 144C238A9096 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543483; bh=rD9Ixo1azXYHHHB/BRXQ4O0ZhyFrXng+m93wtWrxPGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=scgwGZBMJpurWPep1pHa4/rLGhDyr2hyOquE02hA3rarxMXK27lT+DWSiGLq8WsXD HIAQmym3oiBwp9ut5ny9uDsxZQaFSgu3v/37DuB8j7t39sUy3r2DfFuXxTx4rrub3m phLB8GU0Iey1dYdrwVgf5IbM8AIb2iCSXbS13sUA= 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 891513888C42; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 891513888C42 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 891513888C42 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=1697543047; cv=none; b=fyN1HrMgbxyg2conW6LeqJHwVQp5sXrk5fWFjPEIxPuxC9esNAzfALdhRLijDDXVPd8ixXDYaza+zWNAg1QEQfHM+o8Kha181H/JFJ6g1oKdcViPC0b2DoM6VtENwFmnCvogufAJcEy+R6B5bYy01GcKR5aTYtK03uZeP6+URSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543047; c=relaxed/simple; bh=XDazgY1fylMM2iWndx0Ss7j6lazHiqJTozl1aJbBepM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wLhjtpz6kHC9Qn40BR2CGJ7QtSB9vRmX8cSnngCUB35AcNFtw62zUd8jdCkvb7OBlZtCv9e3LN1T5GLtLSMoAN4Vg46t7B1G6Kxd7E6SDAUEoZBetp85VOCAgm1kq41ocEbJh16X0luKnyAmkjKPxDZbI+MUtjUkieJV6cg+c+w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBV4qM013067; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf8x2ffk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjln029932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGQ020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 23/31] libstdc++: Optimize std::is_reference compilation performance Date: Tue, 17 Oct 2023 04:36:44 -0700 Message-ID: <20231017113822.677344-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wEQQ6t9lUFA838Wp5caseHW4nyKN5pzj X-Proofpoint-ORIG-GUID: wEQQ6t9lUFA838Wp5caseHW4nyKN5pzj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=590 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1034 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780003423168701575 X-GMAIL-MSGID: 1780003461887240598 This patch optimizes the compilation performance of std::is_reference by dispatching to the new __is_reference built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_reference): Use __is_reference built-in trait. (is_reference_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 792213ebfe8..36ad9814047 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,6 +682,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -696,6 +702,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template @@ -3264,12 +3271,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Tue Oct 17 11:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076569vqb; Tue, 17 Oct 2023 04:55:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuGOygujPNeDSfnwqnur71nCXTQTsu+WkgrRxWkRi8YmRpbVpDIlK3Y7+0YS6BGLcFuSPf X-Received: by 2002:a05:620a:2b91:b0:773:a83f:4170 with SMTP id dz17-20020a05620a2b9100b00773a83f4170mr2119005qkb.63.1697543703747; Tue, 17 Oct 2023 04:55:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543703; cv=pass; d=google.com; s=arc-20160816; b=YWe1vPuTLLBIa19TRAEJm1Xa6IRNnJ97JWiG1kKMeqlDkceBgI7Y4a3jus4Ns2Z/JP 1psKRLy2vyX/C3GYpagJkoFRxVYSFFDASvKxLDgZ69Ql1KS+cd3rhrkYL67o4saX32mz ZmnacbDyzvXImHiO16lT7eZGWxV7q2xi09j1bn/4yfJd/qIkO2486ab7Peb+kAVQ58aO EIXWeMyC/g74oD+MrPhEavXIC0qX6rrlx0Y4xwLPi+Y9pORXrkqE2rhK2qGjKt4T/uq8 4qIqXVGjdFs8cZ80Bazll+yPV9S0Vr3KQUQ//mUnxqPFnDomA5KlvQMxikqjGGx0ONPH 98BQ== 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=QA/mFJW2yu6aBP542WV9rcrx+4HcUjO8qWSjUVnLld8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=JGeFbkiNTno38EefNRxuiYxeUA9o3wP35DiC0HCBbtByXC0CzO/B0IUd6uYT2kXr+R ttHChz0R+u1NCdZOm9LFvp0fuyJVAEEy/g9vPFaQoMB64yAlmSGPbDEBacyYSzHP2TA/ iGMA6FwuwjKwHYkvDnL02I7WP+ummF42w0RvGLXxSI5BjCExA8Vyy2eyilkmr5qYD7nK Rg0paZQkEHioBFTxd1dDl5n+nwwk1EIC5jhFuSN2Z0MGJnZgTk9PofWgRB9I29pWvEbB /SOS6DsEFZyT789/y6Ayq3K72XHF+jEug645ZLO2Dibl0baY8lFVvgNbT7JC004GH2m9 V39Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XmEscgDR; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u21-20020a05620a0c5500b0077772d4821esi975087qki.291.2023.10.17.04.55.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:55:03 -0700 (PDT) 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=XmEscgDR; 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 5DBBA3830B71 for ; Tue, 17 Oct 2023 11:53:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DBBA3830B71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543591; bh=QA/mFJW2yu6aBP542WV9rcrx+4HcUjO8qWSjUVnLld8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XmEscgDRu5oK3KFBnSSoqDDF+TPcghYo8BsbUX9VyRaRetF7EJzPFCToncxOdlIiy semyePfhB2BPexpZaLjH/+sSRi1AtW4gZftyBE00phiaj+ic+JjOHJfa/JSFJpL3JY XOkV+FOUU45vCjRSb1hHuSjArB8eRaMXBJuMhFw8= 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 82BE4385CC95; Tue, 17 Oct 2023 11:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82BE4385CC95 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 82BE4385CC95 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=1697543029; cv=none; b=jhye9j09Jd9TViA83LowpNmE/9O9fqD23+0icH1uGd9/cTY9SxpBolujcMPK9P34PocKBNzLi2sof4uCRhTHY4zLVU5fByJUotBODmjVom+yQryBoK45mOwHYmzwgVQz8nbUUBoxx6SD71Yac0ZvXFrz7bDMshwAlUiZ8J1KqvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543029; c=relaxed/simple; bh=mJ/BPkZ4Q1g1t1lvGmGKWZc/pKhsmt8XDUgZwN2ajRk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CuBmCez+eYiCoE9DlTKKAQKSzW8DjisMzi4+jzNSaVeSyzfCnrh65/fH+Ox0Bua/Iix8tcqLM++amXQvKQV5PP9AtjQbbR5ao253HLVJ9+f4gPJBXwATJFMAp0HRQvQhAdOi2zN+UnzQ26F106beZEOrjGg2epR0RqE8FkHYMYc= 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 39HBbLXo026625; Tue, 17 Oct 2023 11:43:46 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsa9e5qe6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjjq030090 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGR020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 24/31] c++: Implement __is_function built-in trait Date: Tue, 17 Oct 2023 04:36:45 -0700 Message-ID: <20231017113822.677344-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: naO-P87lHnFc2HAqkNGNbI5heGNEii2f X-Proofpoint-GUID: naO-P87lHnFc2HAqkNGNbI5heGNEii2f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=980 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780003586802560888 X-GMAIL-MSGID: 1780003586802560888 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.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_function.C | 58 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index e05d4fa4d20..c394657d6b9 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + 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 e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) 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_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/semantics.cc b/gcc/cp/semantics.cc index cd17cd176cb..8118d3104c7 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) 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_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#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) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Tue Oct 17 11:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077870vqb; Tue, 17 Oct 2023 04:58:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzALbMvRZH1WPMzNaa+YDVv0LyuhijmYrDHbIS3rLOhDE9mm+9+uqxcgI1EWNAx5AhcALS X-Received: by 2002:a0c:b38c:0:b0:64a:a5f8:6314 with SMTP id t12-20020a0cb38c000000b0064aa5f86314mr1916084qve.0.1697543882871; Tue, 17 Oct 2023 04:58:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543882; cv=pass; d=google.com; s=arc-20160816; b=XHJlESPyxLwfGGi8VOpwqH8xFMEOSoofgv+TNPTWxub8hwEfwYdSJHfPC6xL8f4pc/ eZGtafvRUUR4BInvBDDXYPerJB9fBWEPT2RgyFSxiBvXdfq7flXDCdMdd9UTRfC9EBCx FoobpZUPdm9E4PxqBP1aAV4CXHiit4cvOQN0QOsbHbeaVW1XyJiN4sLUnv4fdyciK5Rq sZGrv7m0TuMaNO3/OUvQhq+5UD/QnRwfOOZhcLvyNbn7fzADXawuL5YKGDOLCwUBHVxY aDnkPtiPKsRWFG7qw1f+vURcTqe0JkpNZFeZd6Gp5qpT34cmBw8f5QHgASMheoXfdQSD OfIg== 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=MoFGZrXYWQnuxLLXozlmHXoHbLqNuKGteZmjnUBj1G4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yNZK0tkPIhZSDHg2EgnlQNdfLb+SJFEhw7Omx05nH5hQ6ED+6xWjSCZ9EyzLalV44E bI0W42MeZxrXcM5WYUUpNAl6PhW+oMdo0qKjNFlGHzzGCif/pgO0xknI3uMOhsPbA+kj t4XkYqgVsUklurQhWeB/+eFwdzB571gzesAgu9wJYLS0jSSVKns3q45EIPvApk0dajbg duTzL4M5o/w4wn3amclDudJ6C17MokT5F9FKRYUHNzVxTEIkoYfT4l+TnyF1TAfEwiDB NWAywbBnGRP5nv83OkewtjHIHKcw0Je21tVQfDbPxUmlFvrk+9fRQR+jqHo/saRmcnjU 8ykg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ajYPPxpa; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w2-20020ac87e82000000b00419930eb097si995897qtj.215.2023.10.17.04.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:58:02 -0700 (PDT) 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=ajYPPxpa; 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 787F5385AC09 for ; Tue, 17 Oct 2023 11:56:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 787F5385AC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543819; bh=MoFGZrXYWQnuxLLXozlmHXoHbLqNuKGteZmjnUBj1G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ajYPPxpakIv3PPw4QxhnwhLZaPmIejUTIw4H3vmvLNNSWrhKZuO7G97Bc3mbcQqlp HYPkQRv3g9rNmLhJsHvjLfIz+t6ZRoTS508xM14aJ4fjU6nYkJmLyhF2hjsj8AH6MP QnnvrEDrgzeO6zAOiOuVK1nKnsgB3J1t4gwqWXY4= 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 3F21F385559E; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F21F385559E 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 3F21F385559E 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=1697543045; cv=none; b=MDGxSyNmLoTETkBQsSYScxm8KTzTAz199/mH/Bqa9hXtDR836+bG7wqT9+tWnL6NOmQ+9xamc7CdXvS6pxQa/CaiYyd1AaoCJaFfGUgCYNqGglk/BietV0RbLJ6KsgyHpR8N4eGTmP5vJujNVCf6Hkt5omV9K7m8wKeGqepsrSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543045; c=relaxed/simple; bh=Gm1sCosWhoGfMkhnlmEt/iwf6ndEw3EeBrJJMskswyo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A7LAFRG4wGahRWhG6q2J+BTCNMdEMSFWhSPEeY6FKIdBvHzHAFJ2i9Flskc3BHUroGsnToXQjrRSeBqjduyqOiKJD2tyPd9cAJXS8E+s/jR/LA8ZihNqqFK4hRFSsOpUjQerXqhbSZI2wyO3fDFVo2FYAAN6891D+o+QKJPTa1g= 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 39HBPXjL022035; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbaue4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjKJ011194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGS020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 25/31] libstdc++: Optimize std::is_function compilation performance Date: Tue, 17 Oct 2023 04:36:46 -0700 Message-ID: <20231017113822.677344-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: kmZ46LGA77fowfeHxTvvqP25g5xlhclF X-Proofpoint-ORIG-GUID: kmZ46LGA77fowfeHxTvvqP25g5xlhclF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=507 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002618169089074 X-GMAIL-MSGID: 1780003774834398583 This patch optimizes the compilation performance of std::is_function by dispatching to the new __is_function built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..bd57488824b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3269,8 +3276,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template From patchwork Tue Oct 17 11:36:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077207vqb; Tue, 17 Oct 2023 04:56:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeFro4ZwTI6QnWDp98O3lofDwxUpMiWO7/+rYfrkBjqrYL/qi7vjixMf+JS0UiIZjMzaNf X-Received: by 2002:a05:6214:ccd:b0:651:66c4:cf4e with SMTP id 13-20020a0562140ccd00b0065166c4cf4emr2620230qvx.23.1697543792614; Tue, 17 Oct 2023 04:56:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543792; cv=pass; d=google.com; s=arc-20160816; b=n2Bul8sOEvFt+hbVUA7B2qqGGzb2SmTdjpKq2Hd4ZZ2IPVmkGq00o/8b5odEYgWek/ JJu5QuDT19KRbwVmYr+SQZRAsOwnidaXMYNvQwIuvjI3JWcfCVDvfPc33dNc/Bx0xyZG d8LzqOHsCmt5Dp93Yg/KlfSXZVqse2nnXH1UPgh96/xM+S7X57+AvnhO41VD/mB1f5xd 1RIzezgZd3/jKPCeG/sj5Yo7Y3/3eVm27nWFL5aJohS0LiHJl4LKMR1pl31ySFy6pJgp FOyYvLZqrr2C4BrMrgM+nrOwmNRF8Lrhc7CK7dUsx6C+XOH+nC9vRStyDYcOVBOY2mS9 g1bw== 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=I7u3r5aPxOApyfVQgjLcLQECiaN1qIF1VQi6GNB/wx8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=my4XfkeOEuVehA65rqlAVNOyfkO/UiUv/8SnS5vq52TLBYeEZuGiHKQt+L5f/Br+pN ub1AZcmXy5KtZZmBVH8CNMK/DQXxG+thkQjICQCCMyG1kYC0RU+fHX3gmbu6x/nwILdR 7zu258/h0elLhunUPuTAwq6uuGYXIzUA9rPd7di31JyWr2j2tB402BYtVWvl7wYYedCu r/5ShK4+1g/wb3y5jQ/35W1s8B1HBTRbKekFlpJSRbAXoY9+0pPQRpvQA7vRWBCu1iZ0 3BUE/E1aND2CYgsjbZ/NLojlVcxaLxYBMabt2fUJs7nIgI3Xx6KlE9Baw2NhaPqe9uxb rnrA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uF1ojj3d; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c20-20020a056214071400b00646f2d31709si861279qvz.178.2023.10.17.04.56.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:56:32 -0700 (PDT) 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=uF1ojj3d; 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 2545B395561A for ; Tue, 17 Oct 2023 11:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2545B395561A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543674; bh=I7u3r5aPxOApyfVQgjLcLQECiaN1qIF1VQi6GNB/wx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uF1ojj3dfuGq0LbHGM2dge3yjnXa80Lx3jTXmgY78iWKy3J4RwiZ06XOdhRDUbrrM +enozfRnyfa+FwcfWkza2LH57HugHMoO2kkG9lNZp6Y+DHyGbzsm6TLfr1j86Rg6Ct v1LOUYwU0b/nW09lR1maM6lyWctCBMSVstybgUiE= 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 7219B3875DDC; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7219B3875DDC 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 7219B3875DDC 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=1697543047; cv=none; b=HZtPJxsoXvaWJ8mePaCnEdCcf2AZdRSB59jAiCFcggD+0PU2RWNv74G14kmizFwENZTXLz+Qp1Jod1bvZLmgZNR3abtzU3lUHslV1gXvQnMMUvC+ZQMMqCbTAjOrWNUqraDKQDo8F4jbY9tQVrsRggXgB20cmc34l/D6Wvu43Tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543047; c=relaxed/simple; bh=ESB1diD1iUYt/kFPVJWJ9UAIk7o3wFY2Qiy0kMZFkcU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TQE8KI2KlyPYIhz2QLbPoemhyFxoJH9qcgflSOTbWGKRJwQHvEBlD2q6MYNtHwa28AaI7X0tZXqVggyCb27ec7Y3pW7EDQpuXMrJutLXaVvapIKmLFl15Evt04VFVFs2dQ6hoaFGLIm3C64SXnODUHAiadVJ1Lhpw5MSIPWj6XA= 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 39HBdPM9031264; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsa9e5qev-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhjSK011195 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGT020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 26/31] c++: Implement __is_object built-in trait Date: Tue, 17 Oct 2023 04:36:47 -0700 Message-ID: <20231017113822.677344-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: e3oqyHhSmM-FOUzh664jYWPptkUlMefQ X-Proofpoint-GUID: e3oqyHhSmM-FOUzh664jYWPptkUlMefQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=917 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780003280955820114 X-GMAIL-MSGID: 1780003679439352029 This patch implements built-in trait for std::is_object. gcc/cp/ChangeLog: * cp-trait.def: Define __is_object. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_OBJECT. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_object. * g++.dg/ext/is_object.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 6 +++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_object.C | 29 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_object.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c394657d6b9..444dbaacd78 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3781,6 +3781,9 @@ 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_OBJECT: + inform (loc, " %qT is not an object type", t1); + break; case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: inform (loc, " %qT is not pointer-interconvertible base of %qT", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index fa79bc0c68c..191a86307fc 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,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_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_POLYMORPHIC, "__is_polymorphic", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8118d3104c7..e3f71ff5902 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,11 @@ 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_OBJECT: + return (type_code1 != FUNCTION_TYPE + && type_code1 != REFERENCE_TYPE + && type_code1 != VOID_TYPE); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12412,6 +12417,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_OBJECT: 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 4d3947572a4..163be1d710b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -116,6 +116,9 @@ #if !__has_builtin (__is_nothrow_convertible) # error "__has_builtin (__is_nothrow_convertible) failed" #endif +#if !__has_builtin (__is_object) +# error "__has_builtin (__is_object) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_object.C b/gcc/testsuite/g++.dg/ext/is_object.C new file mode 100644 index 00000000000..5c759a5ef69 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_object.C @@ -0,0 +1,29 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#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) + +SA_TEST_NON_VOLATILE(__is_object, int (int), false); +SA_TEST_NON_VOLATILE(__is_object, ClassType (ClassType), false); +SA_TEST_NON_VOLATILE(__is_object, + float (int, float, int[], int&), false); +SA_TEST_CATEGORY(__is_object, int&, false); +SA_TEST_CATEGORY(__is_object, ClassType&, false); +SA_TEST_NON_VOLATILE(__is_object, int(&)(int), false); +SA_TEST_CATEGORY(__is_object, void, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_object, ClassType, true); From patchwork Tue Oct 17 11:36:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074103vqb; Tue, 17 Oct 2023 04:48:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQ7QcsGvPkG4t9mRK44OMMT/2npMxriiuxC/Sbt5uykY4JUZtlPnDbdUQzZSwWMtL0Fx/H X-Received: by 2002:ac8:4e56:0:b0:412:bf83:e759 with SMTP id e22-20020ac84e56000000b00412bf83e759mr2282777qtw.42.1697543338455; Tue, 17 Oct 2023 04:48:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543338; cv=pass; d=google.com; s=arc-20160816; b=d7bfk2SQWPLgfCi9ENgOGKGVidqOXfkSNKUQd41Lbcs4XBVdgodWyGQ1XnZ5yCzFXZ fh0RNezN6qUqR8krhwV2+3BNeLk73zMi4uhetn/3vnmlkAcnzfYkWYXz84g49f4lpE6S RD4lIZelbFj0M8cXVGV+ZQITZZSw7qEtrUIrDgt2HFdSdeHmNIrZ1HVHOnWet36srLXL z+zEtVehSylQ+CeS0525sCrtuGZmJT5JowRIJRfTVzk0FbBm8wIXH2/eu+v4m5l6Y6ye lxAspjSdnJZqjcEsTOlWKVztfMcxYHF1RNR82Occb0g4rgNWA6YQC+w0u6sBAz4d3Pns Bvfw== 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=GwJIozGDWJxGiKlP2wlIRXfHovWX2PngOvElR6IxpnA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CDnIRjvLgqhNCiJrczWV6bcvofT1K3/VZLoQEt9tOJCuVW8uk7MPXrcEFhA+mbUWtZ kYsj+3zS6Vu7KzLhaafu8fuVT7eOkRBgMDi4CQqXe7G13Gw284HWOh/Forx+OwzLefna gTZhdm6CUeatpIjMCFhdVGSXwEqp3nH77pCyqtTAvSKsRcj2FUSPucA48C47rFqwJ8H3 UnaWRJuHJkSFfyT32nBIfqq5IJM+5YbmgTh5ixh/n000pyUkEKvBWKomFmugoltvoyNn 2LBeLsD5HbJYqyixK6ElTYccl6+Wg0tghvf8gRXfN9tIm24Paf7QxMOb1GdYWrqnYPTW njbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ofqCW5zt; 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 s8-20020a05622a1a8800b00403ef05b8a2si988360qtc.291.2023.10.17.04.48.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:48:58 -0700 (PDT) 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=ofqCW5zt; 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 2377738A90B9 for ; Tue, 17 Oct 2023 11:47:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2377738A90B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543253; bh=GwJIozGDWJxGiKlP2wlIRXfHovWX2PngOvElR6IxpnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ofqCW5ztn/TBmFQNCtwgTG762O7Fir0F/O4Oq84+zv6qPEuM0BE4tNRtIX1qRymGl DYLvvb75EaINObiNPKc+ZshDGNO4R252QoO4R5k9VaA61W/yMIq19hvKPrbzSYxvVo u/uo3cIsWXhZSJyR6+EGHg+LYK0bNzvmddWMlaCE= 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 A9F6E3875457; Tue, 17 Oct 2023 11:43:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9F6E3875457 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 A9F6E3875457 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=1697543036; cv=none; b=H+10U0kbPe/AUn6H0W/q4vIw2wYTSev7Jy4DFI5WfGswuwzgYOM6EmnzVjiRnEgd6qTkLEm3QOFRs89/qxGTeA4S3nfnf6bF8+Qjaiz5ZYkjSTp3mpf99sUXkhDe9vRnQ/0HX5TIN4yTZ5ortmSFJ2Ci3JlFyJdFCQpU0S+4Nm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543036; c=relaxed/simple; bh=ppZ1J2R3vTzF4ae7XE/TG2BmfxX7b8+cpy1Nkg343tU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=r7WellmOSWrgA1I+g7NQMVI05t2jAFdpNlTr41LJBNefcwLHduccvBTTgxTbId731yR7ZTuCs7j0I8UlFrNpfjZodUACp8NjIcYhgGbUOKA9HumBp7VGOORctoTsRp44+mPzMqPQy44D7H9je20b5r7Iq7/jCH28JzC5rj1VyIQ= 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 39HBTgRt031104; Tue, 17 Oct 2023 11:43:51 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsgyr1pdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:43:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhj70032357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGU020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 27/31] libstdc++: Optimize std::is_object compilation performance Date: Tue, 17 Oct 2023 04:36:48 -0700 Message-ID: <20231017113822.677344-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: sO-zaHlZABh-t3GkhVCWbSn7QAwj9Ofx X-Proofpoint-GUID: sO-zaHlZABh-t3GkhVCWbSn7QAwj9Ofx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 adultscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1034 mlxlogscore=715 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.0 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 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: 1780003092679074239 X-GMAIL-MSGID: 1780003203567367399 This patch optimizes the compilation performance of std::is_object by dispatching to the new __is_object built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use __is_object built-in trait. (is_object_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index bd57488824b..a12a35c209b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -725,11 +725,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object) + template + struct is_object + : public __bool_constant<__is_object(_Tp)> + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer; @@ -3305,8 +3312,15 @@ template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object) +template + inline constexpr bool is_object_v = __is_object(_Tp); +#else template inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template From patchwork Tue Oct 17 11:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4080879vqb; Tue, 17 Oct 2023 05:02:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGofrqR3hEUnO+W25MedixSoodBYTOeYoVs6ZgtvkniYhlgoNcrxk2bc0NJL9w/RftPGKh X-Received: by 2002:a05:620a:4155:b0:770:6854:fb7a with SMTP id k21-20020a05620a415500b007706854fb7amr2002724qko.17.1697544146791; Tue, 17 Oct 2023 05:02:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697544146; cv=pass; d=google.com; s=arc-20160816; b=rGvGdNEmDjwHPhSuZ5+lYicRR8fbiTHS5YsC9WeJqo6JJRCvaqEDpbKOKR5e1/pSqv wmhimR58kPvzYjOleSqT9iNiAzJz6Gv6wQrGu7IwVbM8O+1r6y+J7/ODHZ/pryYHX4gq Ao1LU1bcVeV5jUEorok4+gqKkCSQB83pbkOSai9pFN0ligdgk9XHnKfcwv4rA2e6qp9O myd6kYlqJ+FGNjA+nm7niIuU8HT4ZEG58G7H2VqsRSp+tjRxhAwU9ehIUU4U0saVXZLC 4I2ugvmFSfnd6W48OtKri9tNdER9rm++LXmm2LR3orTBy/ETVBIMrP6lJL6WPf/9fGjJ aalg== 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=5c03BG+ACUU26yDpXw013AaVrGf0ODAIozIbkRY2mw0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ri1jZjDtPy8QVRwVMEdNjyswu7WdHyt4eW+RahEgBErgAsxcLzquFHla6toaoTNv9P BZ/t6IZ4rboIU/n0G48lpKianKOeXWaRLt0PQcDGNgoGYAAxSUzS1F2iczlvtE7duT7Q AZ5xrnlErC/+1j6K4p/yAxbUCb5v40u4MdqeyqXcwTAK3iDarBzdHdJvMsT6OdvrNBhn rYtiQoTZ4n8lrZZ6HfTCtn10pFX/ID1g6Fxvjx26SF5/0Sx+kV0ebeX/iK3lXg/MdlDu VtTTbj429M5BnZ8ACMoNNc5SbURZ9w7GJW3dvngd4brkvOVu0XrV2NW//xI4Nhz1Z57Q HC4A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aCcxVDSS; 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 i16-20020a05620a249000b007756e8eae0asi974038qkn.444.2023.10.17.05.02.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:02:26 -0700 (PDT) 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=aCcxVDSS; 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 E372B38618EA for ; Tue, 17 Oct 2023 12:01:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E372B38618EA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697544103; bh=5c03BG+ACUU26yDpXw013AaVrGf0ODAIozIbkRY2mw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aCcxVDSS7h28Lqzlh8UJn3PpGTwqhB86EckLXOxs4CYHxko1Z2G1nwlB0cP/SFXex 8ZAyT/XgKiGHA6vGiMTuHgGv5msTfERl+MlYe2l3UIqRMM+dCEhtc8evT36G6aqSUi 5LJLhcbq//Gkvk5kH4me1qZJknW1XauA5L3YUnGU= 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 13537385734F; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13537385734F 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 13537385734F 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=1697543045; cv=none; b=CwiUD2Qn9DbtM4s8oiRvDa7+8FXUZpORWR3gnq2qaEks2PLGngYkpp8RMomplx9ijCwjLYWEBwYZ8dPs1KRZnD9tWasgR1inus0bfPijiMIb6B5e8EAqBI7zQ+kAfy8F0ZcMwvAp4k6ORuEmsIFYeNE63M4Qm0YxzdOV6ZILBS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543045; c=relaxed/simple; bh=C0qcTRTV/TeuNZg0DDmxzdyb6y2iW6hZf2AYLVPf/ps=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kS9Is8nVk02WwTpPi5YxdZfpFB3IH3jx7IJs3HUmqX9JMSqOPFASHlrDQKwNLxTAAQQZSVpkMKYBgTBF/bMlLl0RvTISG8tIjYlZPfvq4AIqI8hrizTVsBZ2JecDJOkTB3Hy8jiiPKLWWuQneNS9PuVyKZtLfMBHGsI8AQd8gxg= 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 39HBWQbR018034; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rmsrj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhkJM022395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGV020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:45 -0700 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 v22 28/31] c++: Implement __remove_pointer built-in trait Date: Tue, 17 Oct 2023 04:36:49 -0700 Message-ID: <20231017113822.677344-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: DLxGCVNmIjdN-fsTMVovWlAY295XajmC X-Proofpoint-GUID: DLxGCVNmIjdN-fsTMVovWlAY295XajmC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=620 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1780004051014840522 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.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_pointer.C | 51 +++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 191a86307fc..1f405f61861 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -98,6 +98,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_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e3f71ff5902..45584e9045f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12494,6 +12494,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_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 163be1d710b..719902d3f1a 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 (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Tue Oct 17 11:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075759vqb; Tue, 17 Oct 2023 04:52:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/qxfK+I+xCnnTL/jvcW940MfXqz5BmfgDCRxaoqm0hoNKJ2WhPktVfgCzROOrzJ8EJGpW X-Received: by 2002:a05:620a:258d:b0:775:9041:73dc with SMTP id x13-20020a05620a258d00b00775904173dcmr1863574qko.16.1697543578487; Tue, 17 Oct 2023 04:52:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543578; cv=pass; d=google.com; s=arc-20160816; b=xXJZtr8W7EjefatoHHT++0DXd+8uEA5+fXBJXtwfBjxl8aaNmMEbPc3ZYRtbOrnmBs sbads0uhDuqFAtUlF2Sz0NppDJ9b0M8Yv1LI2ZjBs45OIaWp4kYJ/lo2VIaYdSYja/Iu pUY7kHbnwnKHESAu4j3wNc2Em7PuUZmc2SMGr74obCJqx9PzEPaNM/bgrDQ9KjmaeGIn fzwhA8SQJM3Ax1uINDj2sW2vttMqWpWhm2UjxIAM2lZnWPy73C/8SUxLJtLOCZjDGX4n imfAabIuaqAGSvIjMF6DWnrvm0ptECGEYsPVGK8yEISf+oC0G3snEpHQ8bvadUeOT6lh KQyQ== 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=6hXFlPbvzC+1W4D7nwkYmF0u+9usn1LBxG/spQD4Org=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=0iuE30C9Sech5ctIcgHLk+ZVH3NJ2Xh+po2pq+AEaqFNQkIxwf5RJHZwR49cVtrzP/ A+vNo9aP1ANvo/v5Ysd0MO6RO66xUNpEwv4V25EC/MC0WbwnX/O4xcL+dJhJ9SajhxAH CGQPriQlrpSjeJeaaPB8QVYUsIdYKv40EsufgoF2s6FSiUrNdyNPTpxHdBngfTnv67Bv Erb7x3Ww26tv9ux1T+bGhAYGxUJm/lmKdpInsQ+CmEvgG3hQtFdYvmqjZOr82/G4XJc5 9Ax2a0PPaqkOeBqM+EtSOh6tcApgq7kheujXxxW4Ex2TX+2ccB1BDgcoJR76BaFzAwJg YvTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nUe9puS5; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b27-20020a05620a089b00b0075cb23ee1fesi907513qka.602.2023.10.17.04.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:52:58 -0700 (PDT) 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=nUe9puS5; 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 E81813856969 for ; Tue, 17 Oct 2023 11:51:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E81813856969 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543477; bh=6hXFlPbvzC+1W4D7nwkYmF0u+9usn1LBxG/spQD4Org=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nUe9puS5AjlgTudIxSp3eL19GdOu6DkFcxfDgMoXTChc3IkbVB3C74V6l43pNR0Qc 1H/9tPs1l4XD8zafUPeM/kxnZ4QTvpvWmWSSwWA3lTh6ONhhVXveK46kbE9dygelvH wVXlNYFY6v2h3wFAp5MA1JyuXisR8ZRbuVmPLxRk= 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 CC7B23831E26; Tue, 17 Oct 2023 11:44:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC7B23831E26 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 CC7B23831E26 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=1697543044; cv=none; b=Onog2AMlscZOGlGiX+cw6sF+DAzGBBHCb+FyBFgFEJy+LYaZdgvNQLiqsk5tfm6vGpETGv0P/RQb3fHUoIRh7UHQmIfuAVKUdMGuzfQgnhoL1CGZvadeMqKwJqpK6kWoHH6J9MhLz4uabcqzRxPpRQbRq0inQxU8TUUuNpBBacw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543044; c=relaxed/simple; bh=Oz6GB4/nklZZg/Ua12A1aUDpcPcwACJS/UiICCBC9a8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=v2Vsd0nKOqp+N9FO6kT/U+DSrI7YFyqXw8du4FdmA+TnZYPZ0iLlF+H4tcy+7BUTmzvgKGcwa17On9plhsOzQSb4oKK//Z/LX5FvxMX3cw/FRxh8DSbSGRRw6Chov2yu4bwnHS+ufsZ9xt+dINzeF+lkHZFWm7WcSN/mmjbd9eI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBgwbS000827; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40agt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhkLI022396 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGW020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:46 -0700 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 v22 29/31] libstdc++: Optimize std::remove_pointer compilation performance Date: Tue, 17 Oct 2023 04:36:50 -0700 Message-ID: <20231017113822.677344-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: uirYzG8cgyLXWWWPujvdwOveFTOclv2u X-Proofpoint-ORIG-GUID: uirYzG8cgyLXWWWPujvdwOveFTOclv2u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=593 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003274130707210 X-GMAIL-MSGID: 1780003455168270158 This patch optimizes the compilation performance of std::remove_pointer by dispatching to the new remove_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_pointer): Use __remove_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 a12a35c209b..50210297121 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2103,6 +2103,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Pointer modifications. + /// remove_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer) + template + struct remove_pointer + { using type = __remove_pointer(_Tp); }; +#else template struct __remove_pointer_helper { using type = _Tp; }; @@ -2111,11 +2117,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __remove_pointer_helper<_Tp, _Up*> { using type = _Up; }; - /// remove_pointer template struct remove_pointer : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>> { }; +#endif template struct __add_pointer_helper From patchwork Tue Oct 17 11:36:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076879vqb; Tue, 17 Oct 2023 04:55:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbxdEF9DFLslh5DdBBW1zNxOKFBu7Z62c/mPcQo84w3b58eGZ/xQ8iayzp/VNJLcPbEVs9 X-Received: by 2002:a05:620a:4706:b0:775:d4a5:9c18 with SMTP id bs6-20020a05620a470600b00775d4a59c18mr943176qkb.56.1697543753079; Tue, 17 Oct 2023 04:55:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543753; cv=pass; d=google.com; s=arc-20160816; b=Wtaw3q7ByZ7FXH3xMsk6PqEvqoqNeCpDInCiIEyHhHkZBV5dEUrezBEOn8qB2UPZso cfoxd3yVPFtOkXPEvBx28llLPxwvrSALTRMcxKzrB+htp3iPqzupDVr1rBoao5HmCnUS LCdvLek1qWQ2tFVi1Cif6YnhDw4XtI6gcwzkklsQSzLIR5Iu2bsOLGvHbCp3zAlWZVEK Gz8CxQ7g1+MzVzJ1L3MUCABzc5o2JHzGOulcwN7rMD6fjqQLgtsmQy79j8C0KrkQjPm/ QO6zeF8XIeIzcreyNuPLHCYH1WCkqIfL2fO3AR8obXJutQEY5xImnZmD71/a3SLum1RA 0P5Q== 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=Smh/Y+kB+0wpjHL2qeQS+IxoTryiXigFIt43HCPbyWo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=KFms4nEzohKaOIYEB/aCGEzv1IHLzWfvl+5qnhns0Vyo4ltuwOH5tc/J3DZ7J8kGZv HMw29jprhaAB+xtY4rVUsHPqBlsZul31ilJ6k67GMoAIDhDeT4+lZkrPv5SSkuHBb8eH 2lVWoE3LdQyVW5vRwIbO7EzejVQ0+EekAKCYruOYbuFveYoG/CKdas/BUShAINMu/yJG ntHBd7jvWFw2FyMe0Vsv9Dn+25D65uEYwiuTJBaK3TXvLe3N9rxm2Xw2wusYo5pvZFhA K2hKMHklubSXqA1rLjnY5A4gBb+XKsylphVgv3xeVh9phRzkLVvRkRngADQxleEEvxHi cAnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RzAdeY2V; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bm30-20020a05620a199e00b0077416fc65e5si921292qkb.346.2023.10.17.04.55.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:55:53 -0700 (PDT) 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=RzAdeY2V; 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 7A00F3AA9934 for ; Tue, 17 Oct 2023 11:53:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A00F3AA9934 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543635; bh=Smh/Y+kB+0wpjHL2qeQS+IxoTryiXigFIt43HCPbyWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RzAdeY2Vrnw+LK1MdVXajYtB65naBd/VOtTGpIaVgYuWz+SMasJPyic7GIjNLQBr/ hiw1e1pCxaFod/qaHWBc0L74/Gpu50rCn0+FcuTF85RDo0XpjW5tkD4vEw7myW3Nqf z306D4u6nDs0T/RPNzwB+QEFdn7bcHzE8yuiH7t4= 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 C5BD3385CC8F; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5BD3385CC8F 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 C5BD3385CC8F 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=1697543049; cv=none; b=Jp0xM4+c6TfDDRtbb0rcgUmBje0Rm4SQ+RntBPNJ5xs/JOfm4MK+4GBpLnvBZauuOnjU9bZO7IFvf5/DI5w7O2DmwGAiTp345jOWcbIzF39ejDer1DJwnxfkVYxsndBBEdo441Zl0gE78x/MMOH3ZQd+W63UyHiv/re83xDBVIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543049; c=relaxed/simple; bh=nUzdWNlhWch0UgIpHjoLMy3laHHmMznmZ+d5mPW7o04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=f5Cwg5QaoT+Oxv7OZ2r68Z75Kzw5eNxT/D+loh6WeOZpJJfo6ZiJBTH5qkRLNhpdnh64YR52Ln5IcsWRVGO2SQmq8RihD9aYjhb2YsNfQBpmQ7pnWyLEIkJy9V4OrwpAEYRmA28L5WFVkZ+6r3eJDoqiobboLV6yfGQbpFaO4ak= 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 39HBTl89026030; Tue, 17 Oct 2023 11:44:02 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsftqt1vb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhk5N011196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGX020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:46 -0700 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 v22 30/31] c++: Implement __is_pointer built-in trait Date: Tue, 17 Oct 2023 04:36:51 -0700 Message-ID: <20231017113822.677344-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: FpMPmQaRgIc3tyPrIge-7db2uYSJ7PYK X-Proofpoint-ORIG-GUID: FpMPmQaRgIc3tyPrIge-7db2uYSJ7PYK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=728 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1779677497968726301 X-GMAIL-MSGID: 1780003638215495480 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 444dbaacd78..9fce36e12d1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3791,6 +3791,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 1f405f61861..05514a51c21 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 45584e9045f..7cccbae5287 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12216,6 +12216,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); @@ -12418,6 +12421,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 719902d3f1a..b1430e9bd8b 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 Tue Oct 17 11:36:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4082557vqb; Tue, 17 Oct 2023 05:04:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRWvyuMlzXVCNKFWXNOOCP9qe/rIL9zsscQlycACpCYN6y+JIXMaSkD5jy4Pxfs39AFGuC X-Received: by 2002:a05:622a:a:b0:419:7e82:9190 with SMTP id x10-20020a05622a000a00b004197e829190mr2136698qtw.31.1697544261286; Tue, 17 Oct 2023 05:04:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697544261; cv=pass; d=google.com; s=arc-20160816; b=sPYlzh8vW5TiPitenjJ9kfK4lVlGpzWvn3KcBBU1Uk+1oTMGHJeEuMCxGGWBK3iY7m fdRpY+UKSao7ydyLGY631JTm71zE1bAz1ud15R12WpHIxzig3DuWNvLzESsgIXm7uP0/ J7N9/Kmni7FJKs379fhO5Bt9T399Kw93m9QjjL50o03xKnIVcyRQxbvR1dLaIS7VkPT2 x6kW0HyY9mDM9cMc3zL+DBi/5ZjBPDYvJc8/8ubsy7b4jKnm7FtbFsDiWbhBmCZj65ak 6NOQzRzCgwLRhQviVHlHoxxz8oczQQ61EX6EaJqbRrhChwy6Q0yY1ZtP555JyVdd7hPV HjPw== 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=9Dn0VEr7nsHP6cfPUJmE0z3cJehdHxR4FVAFVcStTPE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=n0lVPsewkOGFIMrvjj+T0jeOVelcxjMF7FHyE8JHi60DXh3e7PWOhKPkPCrYN2Ildu dPKovQUL5bU9CDhhmFq7HyA7+1TKPst8fGq43Oi6DeGT58R8dOUFET5mzuvLa+jiptIw a8taciPSOGHcT8IiUlu6j/9vv0fgbtmVJGq5gJHUCCi7nYD/wIUyCBQ9buiz+nIxpUhl r3QzJ1NtrsUvIvVfnEukzSR84pVvbMyi7QqOkH4WjskwJ2s5GBOeLryqrLcm/QMvr6+w HQYb2smKnDwDcl/Dgiv/YRiNWK6bkTIqzkm/o77K1r7rIdhEEPhuvl/CkPcZIPRb0Y3f dcuQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=H3oj62eC; 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 o20-20020a05622a045400b00410993e39e8si956451qtx.260.2023.10.17.05.04.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 05:04:21 -0700 (PDT) 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=H3oj62eC; 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 0A23E385840D for ; Tue, 17 Oct 2023 12:04:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A23E385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697544261; bh=9Dn0VEr7nsHP6cfPUJmE0z3cJehdHxR4FVAFVcStTPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=H3oj62eCnC3/qkalsAQ2YjZ/bjQH/7xYdck2DfpsZy6hn7GiFuG1fmVln9tqIQ/Fg e8xsoqLLU3DzKbdXgFxDHqmodSwwYlCcKVUpsczmRjzoxhoXpOqa/0c2pEiZ4Ysr4w 4rw06qHqqWFB9ZGPFLCwRsbycT0ysSO+3Una2+8k= 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 B5C3F38A9094; Tue, 17 Oct 2023 11:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5C3F38A9094 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 B5C3F38A9094 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=1697543049; cv=none; b=CIEiGKUSJ+sCTsrCcAAhuH+0oZ9MiZHSarxqo3IK7PakgQjRjgilp47Ls5qpvCyi0YFAWkh+Bn2D0fAVnr48L0emrq/KO/i1fe6y0NW8hrNOcHwPkEXAbIn7r0XcuJdfYLm5pP18p9j6kYM5WGtZlB38R4tGI6ELH6cJ8EXMDeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543049; c=relaxed/simple; bh=CwlGtBzZLdvGgMqqHMFspW66aANcOfbkJYM5resMAc4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AtNEbhnLLgRlK2FOqBGn7h7E/mtaOc5qR/5liWuBhmsJlvFgf8P3LwZt6PNP0E1S1RRW45OBM4T0J+r31UpoG/LvOPPWF4Jou8NV7cVodpS4Meolc4OU2FSDlf4nW2rH9Fo+ZiSWsLTK4fB0j6BmN+oajQMraKUv+IQmefzubUk= 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 39HBOicv016073; Tue, 17 Oct 2023 11:44: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 3tseh6tsc0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:44:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBhkIv005657 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:43:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBchGY020891 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:43:46 -0700 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 v22 31/31] libstdc++: Optimize std::is_pointer compilation performance Date: Tue, 17 Oct 2023 04:36:52 -0700 Message-ID: <20231017113822.677344-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113822.677344-1-kmatsui@gcc.gnu.org> References: <20231017113242.664523-1-kmatsui@gcc.gnu.org> <20231017113822.677344-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: T5jchnWZxSsyBxs9o43jH2_3sCC3cbuw X-Proofpoint-GUID: T5jchnWZxSsyBxs9o43jH2_3sCC3cbuw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 mlxlogscore=415 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170098 X-Spam-Status: No, score=-13.1 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 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: 1780002690195991879 X-GMAIL-MSGID: 1780004171564204867 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. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..246f2cc0b17 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<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_pointer { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 50210297121..acd117cfa73 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 @@ -3252,8 +3266,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