From patchwork Fri Oct 20 13:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 156116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1074404vqb; Fri, 20 Oct 2023 06:59:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyqMBiwgFaxAF2KjL9cL67zO4qU4PuQAIOAVOoyeUhIpGL3Hn7H8V6flKUBdKSPVXV3e+/ X-Received: by 2002:a05:6214:e6c:b0:66c:fc76:7936 with SMTP id jz12-20020a0562140e6c00b0066cfc767936mr1622286qvb.48.1697810383638; Fri, 20 Oct 2023 06:59:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810383; cv=pass; d=google.com; s=arc-20160816; b=KjpUgQDaJzzouG3gYhhCTPOjwqkolC0h7RnsFhI4hynIokBQ0S/DtNekiUyQ9rxTyQ G3ertfgJdnuLoAH2CuEiBSBvxQZxBRo7W7qDk5JUbgwMUK5dw4wU/n0dEprfxn71qeEi JuA8KH1GPkq8FQEMUIKQ/Xd2mVUDfLmJzw0rbb4iC+CTtohB4hZcFLnD2JAnVC0AsdiT xdwfaOwMDIIER5l4rxA/pFdBHdAkFX5E3mN+wRZ+ITGPsYIkBEY663ODAI+s2KZxEQw6 wE4JKHqeTLa5YlG+ZAPfSYpIkpnoSkfVUkt9wC8j9bqtzuI1QaJtgUvIxG+ClgRDjIyr PXJQ== 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=ljHaeZ8R1YYGshlrVI5LGHASwbUtsgihA8NiF/XFmx3PFqdYm8v6qV1kGR+Wl3y2bm 2WtbMnPa9AMzL3B8CYy6VHbhFw7C0NPt/ZQypjzyjnuU5Sd4HeMD7KEfnidugj/Bzz/m mn5farGXZ8WBm1upTQs328skG/086u2lio8e33UP42SmxLkDctB2+n0kPo5qy6kNacjE TCDrPfIfK+R7psekqsX6Iq7xw8crFtf7KWLmVXMNcqq6B0qotMdCHY6MOln1rjuERdy9 n6FDj17OWC2ikFx3uX6zByzLCbe+VwOHHwYzmTDe4vgyhtsY2GhfcE1vHrjHrwVjOQ4A JJww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZmbIzmJl; 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 mf16-20020a0562145d9000b0063d42d0a6acsi1493660qvb.517.2023.10.20.06.59.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:59:43 -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=ZmbIzmJl; 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 5C9983858024 for ; Fri, 20 Oct 2023 13:59:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C9983858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810383; 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=ZmbIzmJloknUN1YAQlxDZjInJ0HYcianKDxv2ccXNmH4U2cfNsCFlcydTrOiyjqQM GcgAITVElDADGWOrtHi9AJOAiWkYfEtlNXI842y6//EtjsDxdJtHPb7z/4d87s7rMr zH8EG953X7/D6F5ldIy+BPYZSscdENke4STBmM7E= 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 E75EF3857BB3; Fri, 20 Oct 2023 13:58:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E75EF3857BB3 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 E75EF3857BB3 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=1697810339; cv=none; b=f/Mg65eDVrgHDJamz2M5rVsLlcKs8Yi71arDoRS4FoxVE6dUp1eX8mXPtJSLr3hwqL/4C0nJS6gcUzInIV/m6TzJi8erBQuasQ98Y5sWb+4GDij4BcRIKG3Syi2As00cuqY1r5GnQzGvH6q8c/LR/W17Pv4B0CTElkhJrN/1CwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810339; c=relaxed/simple; bh=7TvwmHW6fih2o51F4woPX+Nt/mu8wQlnBx0TFFC+I1g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WoCa1XIbswkpFQs2bmegActlextDKH7wZX5xx+FeBwbFzWO5DBMPPtpSgtjFPqFg6fBbnrOdwzQUkHWqyIBPkxYzcnHCkmLWOOpeV2dCpGu3TQcfK1JbPsCBMPMcay8VWT9XaxNvR5WFB88905t6W1UP0gxMINrh6yFbguD3bfU= 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 39KDvtMO024033; Fri, 20 Oct 2023 13:58:56 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmd81-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 13:58:56 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KDwo32015131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 06:58:50 -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 39KDvqKF011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 06:58:50 -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 v23 01/33] c++: Sort built-in traits alphabetically Date: Fri, 20 Oct 2023 06:53:20 -0700 Message-ID: <20231020135748.1846670-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: whot2HGkG87ekBmnGEkwmobc3Itgpmsb X-Proofpoint-ORIG-GUID: whot2HGkG87ekBmnGEkwmobc3Itgpmsb 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200113 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003261967306099 X-GMAIL-MSGID: 1780283220556267510 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 Fri Oct 20 13:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 156118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1077224vqb; Fri, 20 Oct 2023 07:02:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+E+AISo8igw45muCkPjJ/By2vmE7L4BYQh5XBLHIXx3IesBJbkbAvm6GEaJHNLuYJ2yXl X-Received: by 2002:a05:620a:8906:b0:778:9be8:275c with SMTP id ql6-20020a05620a890600b007789be8275cmr1816482qkn.33.1697810562285; Fri, 20 Oct 2023 07:02:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810562; cv=pass; d=google.com; s=arc-20160816; b=vQOiAnHJXPG5wrg1XMTo3XkiM6+aCuMfg6TFK8Y3tbhr9h4KMastkDmiQXmdDMS5x3 rxVConoQXlBjQG0n0fhH3UCj01h2FVY4GVJAyxkevuqyruuBwFoPgaRqG+sH8MdllOF3 ylfn11Rkkt48uFDWN3QlFdt5jXDrdeV33UdLo8hpzGfgmU6aFtnh4U6zrsAuzhMKhuFe 08CBT7lAmfp+AcFSwCWYGiOUts2H6wgeRqlg89m2XqNn4NUSQUbmvRCBPKMHSVOISQzl rUsz4sYBr6gYo0zUKimBJRlmRcgzwT+05/LC6Xi9+x1PzFmDyPiMglCG5tsQ+9Sad6hd EmTg== 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=TZyL1hDqKrnZucrIEFKYZbC5UdZ42v4YjIpti1xdbMQ=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=AsrdN8u74ia9ZDaUPqZAbvPHRmAiVXXUJIbI8s+Fwhnhh1AWKqfa7nyn7BSEwGmDc3 JUj1W8cWhIWMxTeH9J4XBEzbE9QPPJ5+wUDkT33eIGxVkF4HhSevZ4skH9CIgF3kc/xo 0Ow5uJguPqiH7YKDs9oifRGAu1Pe/MjF05bTY5WnCxZXs1lKLkuvKa0bUdTJKUAaJYNK yyer+zkQ1/feVG6+x5hHVfcIdv0CGOJTEytNMks7mvRGDKV103A0ttTH0Z+9KNrO8lSo cN8qBypaKexuxiBM5OG/7wOmYlKOmNTKjOlpIi+vxL1tsWXrhMl0Xqow3pSVMzQxRhCm 4HlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L1zoUWli; 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 j10-20020a37ef0a000000b00773ae74632asi1283141qkk.604.2023.10.20.07.02.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:02:42 -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=L1zoUWli; 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 F35A63858288 for ; Fri, 20 Oct 2023 14:02:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F35A63858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810562; bh=TZyL1hDqKrnZucrIEFKYZbC5UdZ42v4YjIpti1xdbMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=L1zoUWlil6YOGuI/nK3zmWpl7HIklVl6wR9IQhQZX9dT3siic8WjNjYbcYjXWRo/B Ioe8w8nMuN4uyIQeld2Quw3ntHLPljpSKrFQo9y8o2FbfTP0JWr6xZ+RGTSxFMGwT6 qr63bxbqCbU84Scd197COM+9nME3F8A7mJJ7/M6k= 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 1FFDC3858D20; Fri, 20 Oct 2023 14:01:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FFDC3858D20 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 1FFDC3858D20 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=1697810516; cv=none; b=Am+nNlaqBF5/JmOxqW3kH9xrRU3KlgyhrdJc8pmqbRoNmKi6rWPWaBmqGDItHm5oxSw5RFVBMEVzsl5v3DKrpcBxBeArqL0IxVcT/2tOrGkXiKqaIFPMB7ij2FN3I12tvIiyw52R/9HjLFpN3mBsYzhmDCMu//cn+UEH73hY9VY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810516; c=relaxed/simple; bh=vgrCXlTUsgISdV2P9ntk+bK1fdA17y8s8tHlkSQLYNM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IKnIagIeiseBiqslnGY4SCzsKtU3hd/ccJJO7sL51uY8t8JI5CcyZp80/8BbX6pdrqa27FMzGmm6OUC8s0ahmLMk9v0PDdiF6kQ/bUAIOx1M7OmRDinIMyZGm1GeH8V1wGzzHLoGSURAWwvoYp+E/bm3numgYdxVqACFn3Bbey0= 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 39KDexUH000810; Fri, 20 Oct 2023 14:01:52 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc8gmnnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:01:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KDxIuD021620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 06:59:18 -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 39KDvqKG011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 06:59:18 -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 v23 02/33] c-family, c++: Look up built-in traits via identifier node Date: Fri, 20 Oct 2023 06:53:21 -0700 Message-ID: <20231020135748.1846670-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 0WRCjXKdJW1ywa-VSX3Qmb1LCw6fFJ4p X-Proofpoint-ORIG-GUID: 0WRCjXKdJW1ywa-VSX3Qmb1LCw6fFJ4p 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200114 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779868979596920251 X-GMAIL-MSGID: 1780283408089211101 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. (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 (cp_traits): Define its values, declared in cp-tree.h. (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_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 | 32 +++++++++--- gcc/cp/lex.cc | 34 ++++++++++++ gcc/cp/parser.cc | 105 +++++++++++++++++++++++--------------- 6 files changed, 126 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..e62e4df4db0 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,26 @@ 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 indexed by cp_trait_kind. */ +extern const struct cp_trait 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..a939e2e5f13 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); @@ -97,6 +98,19 @@ ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] = unsigned char ovl_op_mapping[MAX_TREE_CODES]; unsigned char ovl_op_alternate[OVL_OP_MAX]; +/* 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 +}; +/* The trait table cannot have more than 255 (addr_space_t) entries since + the index is retrieved through IDENTIFIER_CP_INDEX. */ +static_assert(ARRAY_SIZE (cp_traits) <= 255, + "cp_traits array cannot have more than 255 entries"); + /* Get the name of the kind of identifier T. */ const char * @@ -283,6 +297,25 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + + for (unsigned int i = 0; i < ARRAY_SIZE (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 +357,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..f87d4c0a855 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 *); @@ -1167,12 +1173,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 +1182,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 +1228,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 +2894,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 +6069,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 +6107,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 +11078,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 +20111,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 Fri Oct 20 13:53: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: 156121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1079399vqb; Fri, 20 Oct 2023 07:04:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuM61UBplBfrBwzc6rhVKkYvUXw/yPNrX3ZIq0BaIHkfyYx+jTyEZeKrRyyMUYHFEcurqG X-Received: by 2002:a05:620a:19a8:b0:76d:83ae:fdcd with SMTP id bm40-20020a05620a19a800b0076d83aefdcdmr2034379qkb.57.1697810698213; Fri, 20 Oct 2023 07:04:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810698; cv=pass; d=google.com; s=arc-20160816; b=hv1ITfbkyHC8Hp5i77HD1eh2GU7ZD+ZEsDbJ3iFeeNB3LAixxO0/goJRd/4JE+O7eh YP3w3ewIiD8TCP2p9gQO3DHYxhdVW4f0ZNbXkhMHvwKOYkzYwP6idSsuxJrng6ea5Efw khv3jfNYlnd/1AcnEhl9Ul6nSXYOWNf7ZRUtZVtk9HX+oEEFszhgNEVC8Ol4+2Xzq+u6 V7cMOMQ6MQVLCnxnMituKowe7Th3K62kBFZIraI0YUlLs8z3Fkktf1fJEaySsWapa7yC hy/9HgfhxYpwbfqDLSzo5c5AalIy+M/PosT2e9y+yXz9EtXmzEvw1lnnN8VbRzdJsaRW axaw== 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=tYl4mnzU6s2J+66eKdEdBgGbTedHYW1P8QdNdlQbXB4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=rhMWAMMrO1N7GgzURRvDQQLcfGc4KXM7pDuGSeO4Lt0JZkF6z6CxuRIJNgAk0UJ46K bn3Y9v6YIiKbCM5SqsM75MRBn+I8Ru4ftoNUW8kjSN413+8wMlWWXz3HQB4j1xRJlSDW 6ZLTEogFWjvfvq35ROVd9me+aKymJ6q640a7yZ69kXpZQFq1qBpxx+aJpbTFVz6EXJ+H qW3IWy7RfZEHyCF+VIS6Q1Q+JX70K9vyZn1Yj6wVhnyx5hgzOZtIqh0u7IgGKp29Lz8t zOPJ8NdM5ojOJScZuZc62rBVqZsR91G5S68yQS2H0gi4uXcbEOVeQsJKyorzXAuVXG4F tGiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oujiHe3T; 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 j15-20020a05620a146f00b0076cc4d494c2si1263316qkl.88.2023.10.20.07.04.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:04: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=oujiHe3T; 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 E2AB53858288 for ; Fri, 20 Oct 2023 14:04:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2AB53858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810697; bh=tYl4mnzU6s2J+66eKdEdBgGbTedHYW1P8QdNdlQbXB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oujiHe3TA5fkzZMm5tsZS5ph0QHo6fU9d1QzTGOr73NksY+AK0BGKsUowgprA+c3m vxvKm4BEXtOQTakAUzj8G4zut4qL2WkhSz1NyrPNxlbpm0sB5RVe/ZuUM7BCtObtIN D/iYyRr+WGmHMvN5CPCrfps5PGwEMV0mVlyfpSVc= 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 6E9083858D35; Fri, 20 Oct 2023 14:04:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E9083858D35 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 6E9083858D35 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=1697810654; cv=none; b=AhI48GOkM89N9bCTWSF7QxaNlBoT/1nB9MD1Bnua1bWQp8TUWjGKa7sDLnu907rMb4jbwReykCdeGwYlIS6V8d0d1BDx0v/Qn9LCCzPZU4+ChThOY1EdNS4n7jHZbalX4VWA8Gj0z11tHb3VhtL+4QDsr60RG6NmY8qrRZhRH3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810654; c=relaxed/simple; bh=h7Rrj0OqLwklY2BW/WCZmHTjCOAUg6xYB6hoVkFxFHY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vrHpb73y2hJHT0S4wn98V4c9IpQ0beZQ3tqakuyoZIBOSoevAUdEz5G1dgCPsoh0J5HhPplODXAxEwz1l1e8sbjQuHzc/UtDbzyf2FpjvBMHcr6c5Z6vCbibezD8ciLJxx0TSpE2o2bUw2MJXQOzkzvEKHLerXCTdWjog8G7iPQ= 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 39KDpWrR015452; Fri, 20 Oct 2023 14:04:12 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmf24-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:04:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE299D004285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:02:09 -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 39KDvqKH011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:02:09 -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 v23 03/33] c++: Accept the use of built-in trait identifiers Date: Fri, 20 Oct 2023 06:53:22 -0700 Message-ID: <20231020135748.1846670-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: XDOqDUSbbvyCaEVmX4iqJT1-DxZlh5J5 X-Proofpoint-ORIG-GUID: XDOqDUSbbvyCaEVmX4iqJT1-DxZlh5J5 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200115 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779681961607250764 X-GMAIL-MSGID: 1780283550538938100 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 f87d4c0a855..8b6c01e52c2 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 *); @@ -1182,15 +1182,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; } @@ -1198,9 +1210,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; @@ -1211,9 +1223,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; @@ -1228,7 +1240,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); } @@ -6107,7 +6119,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: @@ -20116,7 +20129,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 Fri Oct 20 13:53: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: 156122 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1082422vqb; Fri, 20 Oct 2023 07:08:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFL4/5Merge9YwAxYWrHjSx6v1e1nAfQ8urKVzItN7GUYdM/+10V2KBXuiLUhcCMEXmKNcC X-Received: by 2002:a05:620a:889:b0:777:7314:ee19 with SMTP id b9-20020a05620a088900b007777314ee19mr1819452qka.21.1697810903873; Fri, 20 Oct 2023 07:08:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810903; cv=pass; d=google.com; s=arc-20160816; b=D0jHjELgkD0flQ2h1Skkx1lo+83s5CMMGz1t2UCuTo4gRk9IHbBZ90zxGdTlz+pdbq TbHiusE89zw2nNYRZVJ/txs/neACPDyl+dzLkZPoTDymcz2XxgJqkN50PDG+I2ykvMRZ WvTeKp9KE3CCSL0hIaIfw0xwq2llLw8SwskX/LakauIF+lvlYlp3glIQM7nOdCZwp0ex vJFPfZNNbZifczcwX7AAqvkInOeEb/aOKCVac4xCYsFpn6oKNFbUwHblf0yjjj6oKsVB jTn66BvOA2dNH2FMZs3ayCfoddXF8Cs43z+tRn+MnhzYml/A3YjTsFtPZCF3Y7+AJUsn W6JQ== 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=oQonYHObtE1tDhSIjmrs9yVN14/72wU5+IjzTAsGswE7rUH8epY4kH+YGwvs+4g1Rk qC3D/eIvWiXV4IMeqb/KDGBZ89VET5NW/77eNQ24Nom5oAWq4vKYaGEUbMVasV6bn+P1 6/V4VR3P13qnW1KSD32o8bgza5FTpiF1L1J565pzI14wty/UcOkZabKOhlHy6+3xArMX Zf3vhNkac6LBbWa81y29ziP0XXWe0O3YfFnj3wlzWCHp9Ihd4vHvjR/yklo8u4WxRHoz TBPP8ZXZ2x4pz2tTzQEptQnUYPvzFI3HTDB/1i00JnX1/oa+NYbH4jsvywDSTKHZH0pR G99Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n10RqV4Q; 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 m14-20020a05620a290e00b007625731b2acsi1363777qkp.636.2023.10.20.07.08.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:08:23 -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=n10RqV4Q; 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 8ABDB3858017 for ; Fri, 20 Oct 2023 14:08:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8ABDB3858017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810903; 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=n10RqV4QVubd64HI/6fCfTL8gk2MhiYkKw1nIYGD7h8cpKYIg/BHbdEH8KuTZ7Xby 9tNtnVKbF9bwgKO9kEsrPPGbnqupr06FGFKYVh2A18dkZr7JmWX0SmdAJzvltq9mfi qu6BbBsF20p53bXCH5RGRyeu/oLPbcDmaWRzguhE= 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 AFAAF3858D20; Fri, 20 Oct 2023 14:07:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFAAF3858D20 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 AFAAF3858D20 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=1697810862; cv=none; b=tDpn3fwe8WLfEhSKiigfIaPWqUd6N3hNtQjxtz9DtEYJEWlLituTOndZcFItmnhQJ4RKwQayFWyUlN79e24ElRETFNz4Y4YKxYkegR35MVXIgxCxmxih4a1gk3bUlOCmI5fVqaPVKGuRJH0oSpV2fkNVWqQlwZxjVJL1eeMdl+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810862; c=relaxed/simple; bh=Nhkst8uA8uBdTogdmoRZMARPpCFeWcQCWm0H9ZsIAxs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=S0GIcw/EhBcxzH9sPzUbHRBKSopqYWaD7XGBYLor/TX8waDwKjN/ukSOMBWYgcmxrNOvA7n+xyqkmSo+ikUhC9IiyjBWxrc+eQjncl8WLHOcORdkQA6DR0IV7/Hdb95bfnUWtUosaCAvKNza+SLaW28RPEg1v3BkXwWr9Afdgx4= 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 39KDr9Uu009723; Fri, 20 Oct 2023 14:07:39 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc2c4s9t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:07:39 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE4PAK004718 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:04:25 -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 39KDvqKI011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:04:24 -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 v23 04/33] c++: Implement __is_const built-in trait Date: Fri, 20 Oct 2023 06:53:23 -0700 Message-ID: <20231020135748.1846670-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Jy-KhDgUTikWVYoTIqwq1WbGyZ-X-31c X-Proofpoint-ORIG-GUID: Jy-KhDgUTikWVYoTIqwq1WbGyZ-X-31c 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=940 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780283766128674397 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 Fri Oct 20 13:53: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: 156131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1086866vqb; Fri, 20 Oct 2023 07:14:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6CH3XEjeYQwGgW7FrWWrffo0lS5hlX4+VShU47/0by6OOcvURvD/RrUOGk6lWey+BUmzf X-Received: by 2002:ac8:5bd1:0:b0:415:21e2:5e38 with SMTP id b17-20020ac85bd1000000b0041521e25e38mr2188214qtb.39.1697811241906; Fri, 20 Oct 2023 07:14:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811241; cv=pass; d=google.com; s=arc-20160816; b=XDnFa9KrXJfbDjvim/j9AlNGNdr8fYJRvlfj+S0KVtlOnDH3P0E4D5FQndEr5mxgS4 K2ULdZjW6u9Pk/pctEWdTfDOgHQW9ZX3gsiLP0NPzCy8yLy9eWUXrnaro43uC/QAtSCw Xv+k42/jLPmsNRJ/AxU9B94KH4mR0LwvtUW7k1sYQ7/g3t8QfUvH51KV0RXfdQQW+4c9 Ga2gviG59XvKPJHukZ/GN/S20xUyZial9CMUbtNztS6QWwNxpv+Kf4vUsgPECKFd9F/U bpn1MqCeMimVA9ibDgjyJbv/2LtxAKbSdAY7lGnu8RQfwY9MhlmDJe/D8CN8TLigv1am Y6eQ== 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=jNoQ4KNaE1T3RL2Bh+8GM+6o5FTmG7gP3spBCaNT8cpvKFRXCHoAsrfjlz52uK2Uyo EpuZPKhVRg6CRJPvy6TKmwdRKKN3o+2OAAT1ObKKUt8WJFKl4mC7p9rvbFj0iTE8UjAQ enpxGgQzZLvbpwXApVVb9bljPAV4pEPGM1fytSp70pxgHNoKqKXQcTNfWYw4LN7MsrKy 2zza+VXoIVhEXdLUnwQhNTbUgU2a9ZdmRsTKuJeKB9bU/X1vU1SvD+pJXaTKGR6xuzEF 7zgSCur2GAVCVf/5i9Q+sT/RcspkSWux7VMvuVYkJf+QQDr1CeN5Vs5hweT/KdAjmhUc RGDw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sn3Ll3p4; 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 x14-20020a05622a000e00b004122bb38ef3si1358109qtw.701.2023.10.20.07.14.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:14:01 -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=Sn3Ll3p4; 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 694A138618C7 for ; Fri, 20 Oct 2023 14:13:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 694A138618C7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811229; 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=Sn3Ll3p4eNNzw/36kmljt92rxjm2gh29edgqxnoXBx4TRRwEznagSSny/MqG7Ftqc BI3KkJi7WywI5wUquIM5nLa1O/Uqr9tK08YVtI3tMus6RdiI8QF/9zjVDcoyl/ZeDc hUlFHffGyRAudZRj8IiFcc8wfH48XK5c0h+cc7L8= 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 CC69C3858C5F; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC69C3858C5F 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 CC69C3858C5F 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=1697811125; cv=none; b=uoMdDSVwQLQDViqrWH7Y0rjyAqjzqbxS5AVZy0BG05eKkamhQKamEjbyLNuMrmU+zcvJdWAIFTgbrxOHZFCOfYrlNsugRvtll274bYp0c0Nn2IyomZ7CVl0ZhLIPZy2IhL/iy/IFauBIpeov/nrzsQkrnN6LkEi6dgofYQxOqNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811125; c=relaxed/simple; bh=/1qcFEm4P/QLiMl/jAKWkbnYQhruObr98IEbIB0r71U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=f1Gk7RA4y+nkax5c4d0sh+AylwpLZSOew0zTwvOsQkanZJJqV7bz9VNpUza/Y6pOn9RDJiIuSKXYuSF+3ejfCuCwTc6ArEDkYx9waRIqRI9R/7xQOrWIXM1r6V/1pgIvOWFXzbVl9KybJIScmOCdf99Uepu7uUa1R2h6b8xWc8c= 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 39KE5Wc9012149; Fri, 20 Oct 2023 14:12: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 3tuc8gms8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88nl005576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKJ011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 05/33] libstdc++: Optimize std::is_const compilation performance Date: Fri, 20 Oct 2023 06:53:24 -0700 Message-ID: <20231020135748.1846670-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ZZiT_yxmw1IzRK9ZxFrdbacW1ztkiJVw X-Proofpoint-ORIG-GUID: ZZiT_yxmw1IzRK9ZxFrdbacW1ztkiJVw 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=766 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002951185557558 X-GMAIL-MSGID: 1780284120682930013 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 Fri Oct 20 13:53: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: 156144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1090272vqb; Fri, 20 Oct 2023 07:18:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqATQhGc7Nxk+NTJp6F+HuxblE0GyLFMRG5rRBTE+sECgShmcvCjhCe+/INTLkdaW0jzx6 X-Received: by 2002:a05:6214:29eb:b0:66d:37be:47d2 with SMTP id jv11-20020a05621429eb00b0066d37be47d2mr2582538qvb.37.1697811518613; Fri, 20 Oct 2023 07:18:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811518; cv=pass; d=google.com; s=arc-20160816; b=KXmGcfhXCZnUaLwjHjEPKJhqvFzKJ/duz53Li1EbNPubVTjkkKrz/iItM6qaS/63u0 n8Hb4g0TYKa0dmEpV2Jth3Kl3oXmfhwNymUzwCm68tpmrz3uF3wN3KZqjg3L5J2hkhRA OZotbNjNME8LKRSn4KEuXhzMd2dzoDxRPHIiUwUUG+m3u3RcG53E6RuM72kCi6CqJJXG LpOPBhU8g/fMczdSo6+XwpmWuf9Pi9W8zkGke1Na+FOdAdgRhwPeGG+bbIiUcOY9QYH2 w27wxnlpgnf+Aacis/TTWDfJNRIu+MnhnWEt0yL2SKtTgnOa/S5/Wex+UKlhbW2fAvSV 05ug== 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=QmlndpLp6w1HPYDZaFiM0ZExyQZL7pfqlRWpZ4BY2XM73XAk3Y2wNzDP4dsvTGlTqD vuV39wgvx6Sxi8mvQ8NWODKW6zywvNQHNP5waUhvuoD0weSQWOt+x11zACIXFfVxHekV ysxlOGZslq/rgJgMa7sVDrmoGZzTJ8/EjbdraK/mj1RYbxLnPEe3O7rmgLjLKwYTQDAj ml4pLK+T7CcQVSfyASO0X1dgtFt1owJKbIC5LSFN0X7TRHW2IT2SHnlqYWH1KwR7PoE1 zNwMMbEDLnkdbcTkmSUegxy3UF0btS/XBULXp/qvxdjuRbhyb8WZFyIjdQYwFqPIxsJB nxjQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MY7Kg2EO; 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 m12-20020a05621402ac00b00653589bac4fsi1429788qvv.48.2023.10.20.07.18.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:18:38 -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=MY7Kg2EO; 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 D0596385C6EF for ; Fri, 20 Oct 2023 14:17:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0596385C6EF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811468; 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=MY7Kg2EO0wZAw9GJ05ZiZdyydMtabjdBDSip2TVlsaY77mpHfwFoR56vNEtw2huTi aDT+eDOOvTe2vr7h+ObtUSuZVhXd6Jd0vHEz3b/N7gQw3Q9D6rrACp7UK7+6WapuNH yYbK55HpVvZD4MqxeFnb8tZYJ3Hfc8qnCfCgwU28= 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 ABAF33882175; Fri, 20 Oct 2023 14:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABAF33882175 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 ABAF33882175 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=1697811425; cv=none; b=FuovhH5WJlRA2wd7WaUNXyfWn5tMjJUthJLQDzJ3d0UlmkzyHVfelGVXpT1tR7OTQp7RQwGwSyxSuKDVZGPvvOHzIV1z3IMmwGRWIfQeTv/kRqw/HDXy06UxkC+XF9wWGZrpjkMAScwmZKGdAnVGAvGZHGyxOe4ADFkX9jW0dbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811425; c=relaxed/simple; bh=1rHsyPoqaQXKsQOFdJbK+nBdkfKdFE5DDiprWTj+Wuk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UWXpmE/DluglGukZlTgLS3/DGIGYanmz9DYuOwlkIpoWVxX3MBHjSkslwg1vm/84x5lG16Aue+1qICI21rM0FFQfF+Q7Y+UFxxoP2B9yV0/JxrNEav/RapNFBCZNuaG8sfg13tjA80VmFykiMBroMLcvy3loyrbYjn9/gPzSqko= 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 39KEGPnW029589; Fri, 20 Oct 2023 14:17: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 3tuby6mtr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:17:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88Dv017237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKK011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 06/33] c++: Implement __is_volatile built-in trait Date: Fri, 20 Oct 2023 06:53:25 -0700 Message-ID: <20231020135748.1846670-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: xZaFkSundLD39usW2B_pzeWBbvPLKJlr X-Proofpoint-GUID: xZaFkSundLD39usW2B_pzeWBbvPLKJlr 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=912 spamscore=0 impostorscore=0 malwarescore=0 suspectscore=0 adultscore=0 priorityscore=1501 phishscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200117 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780284411230768456 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 Fri Oct 20 13:53: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: 156139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1088600vqb; Fri, 20 Oct 2023 07:16:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI2GkhRW7dTsCoJ1XXiDKdqgCeNOXdpWZsQTCnagMxUfvj6hXmNOpWpRFDciKlbokJ+jCW X-Received: by 2002:a05:620a:44cd:b0:76d:aa66:f7b4 with SMTP id y13-20020a05620a44cd00b0076daa66f7b4mr2362879qkp.11.1697811377826; Fri, 20 Oct 2023 07:16:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811377; cv=pass; d=google.com; s=arc-20160816; b=j0X9kpn4+BWnQwfmSLXvrS24dJ/IiEYMuOQR0zckxKq3rliirrcSA+MIRNFDx6uW3v Q6MRQip4f6flxm03eDMlNFenggfiApzr6DJBVpz2VZfIpwIYDCnF8KkvxHEYwLgnPKG1 iQVWqBmW7k1WXOGR0YRwZQEFSnug8pXBAto4KO9QeabDgt5fN2wrfBUDRFjMTqO7N5hh X0zT5ltRzcNFOv6fSCLz8bOtJh2T4M+OF/IBWhSIMLlBwvUgQzhrCYBvGusjQ9Dw/ZvY y26kVRJSAlbh3oS5hgDQWcEo3rvqqSjvd0zMz2/DbwIYMXYTMfN5QhfF6VId13wOpEmB zasw== 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=ummGKeb/PpgiB80en2mVSqvDQGlT2fDA71dReU3QvKiFY5f6EaF+nZ/EXTTBBdYG/E IK14ohUxEC/w1EfRXmjqzOHhP3PCrwEriBCOIikl506CTfvWJv3YUqEifC2X7DwGuEwP EYlVveBfZOMboDDeiOC41Em8sBIWgLAiNS93kXX1iMxX0nNgRdabXHK9h/jkHuTPSYcu DIAyc/+UU0DVbvLHygVP5LQbDGbgU62Ph1WSpSvRh93HLMQ2qjUo5oaSe2DlO0pBizko LgP0aN9YHNlcQs/ZmHPwpWkFyix9nhOgqOzoVigCiA75HoQArdoycLlR0odt6sj6coqj /6bQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="WEW80Kg/"; 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 z19-20020a05620a101300b007788d7c09f8si1364578qkj.573.2023.10.20.07.16.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:16:17 -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="WEW80Kg/"; 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 259F83830B7A for ; Fri, 20 Oct 2023 14:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 259F83830B7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811339; 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=WEW80Kg/8t5fP9QLAyJobVfdsc2UjJWQNdSXAujn8dpoaorkK90iR4PP5uzD7ywcN F04DwfiplQGVdLcw7BxrmO6TznwPxu44b6VcR1SzAaXoCg7chf6mbwquSFb69oc4Bh Bf/85Q6uIotSWbVY9ZaxuSCTYjsYSnxyiLjO54pI= 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 3959B38582BD; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3959B38582BD 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 3959B38582BD 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=1697811126; cv=none; b=aRs+czVWyf+uuzN+qdgDqIF/ULQSF0jyMk20o2g4ziK8LS0zTdUXzR3/iE6jt+EBn56cbEQoOKK6UqEfcLUe3veQo3LaKVgR6CM+PXrorwRbN4s0RsaHHr1Qf/NdVeozohPluV/29zg+einQydyx/vpxMNi870Yi6BXt2mNyZDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811126; c=relaxed/simple; bh=OOSc7LXvSX0VabJEFNwZWDP0RMhq6XkmejWzDYjnE+o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c5Jhvf8DrqlqrkavpQepzS6mIWu76GaKXiqTEI5Vmlsn0LiTDMewV7noOT1tAwNZJBnlc26dB8T+qhCrS9qpAakc1GzVQgOhm250+Sr2ojujU6hYMepN3APDDZuD67cqyjkXTJReVmrt6c6I/uLtJZuO7SGXDXmQBpTON7+rLc0= 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 39KDwhZN004794; Fri, 20 Oct 2023 14:12:04 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuecbu85b-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8819015896 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKL011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 07/33] libstdc++: Optimize std::is_volatile compilation performance Date: Fri, 20 Oct 2023 06:53:26 -0700 Message-ID: <20231020135748.1846670-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: CP07bBVWRpBCWZD1Xr6hcwlAUkI_wxJL X-Proofpoint-ORIG-GUID: CP07bBVWRpBCWZD1Xr6hcwlAUkI_wxJL 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=692 mlxscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002988961806506 X-GMAIL-MSGID: 1780284263466470378 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 Fri Oct 20 13:53: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: 156148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1090950vqb; Fri, 20 Oct 2023 07:19:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGf7NdRsEQXnzGe13qU9cRD0ewqNELA2sXHGPkc9UVr2YfoK8gYdohfgg9LUtwt0EGplZWP X-Received: by 2002:a05:620a:17a1:b0:772:749a:ec13 with SMTP id ay33-20020a05620a17a100b00772749aec13mr5921228qkb.2.1697811581362; Fri, 20 Oct 2023 07:19:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811581; cv=pass; d=google.com; s=arc-20160816; b=eyHpYob4Pz73XEOaldRF3oP+ILXXJaSRl8H0c84RDzCpkjhXsh3FOSDKAJfnC3ANh6 W7DNrXPE2O+j68iYm018B9Gkst1+GiWO9YW2bcm1wAQoT+mFQy1r1mLN7ViEgugsiHBn fOpx2vX2F6sFntZb5iRqG1JJFmV8c3N42vBOPPPJHvtUEwowv/N7qBdfIWEywAiJsx+v dsByOzi6C7DsU4//K3cs8si7YsIjfjybQZnrBIzwJA+XLxSkHB/BfdHBbpIyWIup5nKR q+Q5I2B74FybFb4qm2ojH3E6jP6BTxwBrTrRTCbTH8lMSS9eQm4xEOgVeM9SZfVi36rp iHNA== 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=Gf/mUSCIk1D0ng++KrXm7LvUS4zgy9rB2K8y1+wvE4HK4MAapxdFsNEATmEIBjCyJa IlNlVy9MznwE7h09mJH/nDFXJHez9i8HiQJ/fxJsHBvjH/vt+tq6zGufeg6QdyYVm5T9 zp9zK/qjNL4ugXjpf5w0HCKj0/2fk4hEUmpqzwNutA3Nq48kBscGQNmnJY1QQ+PO9gLf ctgwscvZxaYetAFMUaEURYD3L7IIhHGTmRO3jqIpri3RD76+0pM3ULqm0T44jiUbcCZL o+8sVF4g7kC9I3pr/LEdDf2PKjm6/UWY+bX/L0VG2HLBczXcMiRTzsmZvdv5QPMOTRLI za1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="uAfX/uCy"; 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 o14-20020a05620a110e00b0077421d5f27dsi1356634qkk.571.2023.10.20.07.19.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:19:41 -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="uAfX/uCy"; 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 7F9D73831E28 for ; Fri, 20 Oct 2023 14:18:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F9D73831E28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811532; 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=uAfX/uCyi2kUU1A1u3enDQltrp1EK8/nG+yuLHvAv4fl3cevZG4Rxsey0paDfLqlf DluPK2vbSQaM+zH/lJAJmQAY72TATS0+2CY40a2axhK6VTUtylE0MosB5O1ajKMjY9 rkqg5RmtCe8I8BlzcEzI8uGU4ka2UZjoBQq+H/uI= 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 4E14A3857705; Fri, 20 Oct 2023 14:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E14A3857705 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 4E14A3857705 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=1697811129; cv=none; b=MLVCZL8N2P+zUMbWfhx6PHdo1E3eGBTDzSDwUxkEY7APzJLM9PLp+ho7P9rVNEg+2+cPbLP+AHMfZpzmAlFsEkdL89j+eZNnIqApGU7KqJ0f1kHyY6tZMETATKptFFLWskeCcTjLWrwJD41YBUmPL3bG3/NBlOpUZrYX4tWmrOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811129; c=relaxed/simple; bh=8TftqluSpQljNHIfpPcj3uNIi87MZCtc8a0jE8Eje+k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dgI8x5RADn6DjoGiYui6o78RvVwhB0FCB/7TU2px1a8qPz5ntv4Mamb9h4r+ivmW5SDz00sox0yQP2pyMTdUXn4ZpE3/C9Vc5G0jhsCATHixd2j3EWeu/RYxB7TOXyGFjR7h2ybyxcA6RO7tSMqZvpNlbWOSi10vrvZWsX2Q6U4= 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 39KE1AGI031126; Fri, 20 Oct 2023 14:12:06 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmhee-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE884Z023513 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKM011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 08/33] c++: Implement __is_array built-in trait Date: Fri, 20 Oct 2023 06:53:27 -0700 Message-ID: <20231020135748.1846670-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: nOJtNw6XCC_PsvqeS9lo7avq_BZ6GP0k X-Proofpoint-ORIG-GUID: nOJtNw6XCC_PsvqeS9lo7avq_BZ6GP0k 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=720 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1780284476516615586 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 Fri Oct 20 13:53: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: 156125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1084089vqb; Fri, 20 Oct 2023 07:10:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2X7xpGxA5IEwchB+ozu5V4lqkwd5kvyd7pw1zLSVC3L+K9BRrh2j3koANWnmoSbxfJd4x X-Received: by 2002:a05:6358:42aa:b0:13a:6748:9312 with SMTP id s42-20020a05635842aa00b0013a67489312mr2240721rwc.19.1697811018201; Fri, 20 Oct 2023 07:10:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811018; cv=pass; d=google.com; s=arc-20160816; b=P698wskM6FBn+eUe/jlaFkUZelc3PP91eBrvT0YDuuqTq3C0eLqDVO7jSeV0kDDdTt ht2e2UXPmUZpNGeQZrymjVhtLH5RYIfI5uwnLpJSIxlraIx+qopRQq+vtfB2o4zoAznu fuKpdL6w6lSsgIZ9BU3Ro5qmQXr6gEtkEhMJpo/xY1C/+Jpuii3R39ULfR/c/b80bDzO 5GbJ0KYF0WFnWy03zUtHp1Oyylj5XkJ1FLKtkCsior7WjDShNAKs7oOXa2Rz4bILDciN UtWDv68ufXFrdBWTPf5la9y6ULUVNAx5oqICl5dFw8VVwCXBZdqTBlyaVo8TpuQogbYm ct8Q== 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=W8MXJIsDkYDxiaIHitDolfC1mUK4d69/BGP8v0zB/f/liX1NftK9m24IYWUeZpneNe wtI9WbhXfAslIdpKQ1vIolGukZvL7x1AtdlHaukdrdsdmMeim+C1faR22/a9HCMBVPv+ uy8nj7UpR1MedJ/CWV4XQgmrznvFK93XDmw50C41VrISiTcSvplz8013dY5zewSzbS8w mHs0XGFmDdy7eU5Ayd4i1Sex9xPh/+aoZWYNsWwFzL9WcljAzjuWahwsUS+1fXi5/uqI NOcCuOZgqzuD+oFK3HPrlMxd43vAiBDAjEw8kxSbNkEqFuHsmpnN8MZHbqC6fhctN8Gk sTPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TRavRtuG; 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 qr6-20020a05620a390600b0076d7f2abf63si1289882qkn.310.2023.10.20.07.10.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:10:18 -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=TRavRtuG; 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 111DF385B532 for ; Fri, 20 Oct 2023 14:10:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 111DF385B532 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811015; 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=TRavRtuG67bS5vdqoph2g8VsUMDdszhkmsEhLOGvvbLop9KN1+J4R/MvIISJQA7Oe U3GAS0E55PkEoUG71nWTvvYKU3FAGH8RN0WV9foohVynndKXVDI+vELEpK0nQ48JGL wrILOIvOIbWGLwBlKcvuDOkPf4xdx5fhEKGIMNV4= 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 B1DC33858C62; Fri, 20 Oct 2023 14:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1DC33858C62 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 B1DC33858C62 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=1697810936; cv=none; b=TJNvd9YB/DN7lcyKpAlh9+Z698fZez6ybA3dj3KNL/YkIafcI0IQ1NSDWtI3l8bG1eANurrctC6fHdkEu3SANajRMPblnlNmftmZFbXBJpt3/SXuJOJ8GEEcXALND7SZh66JUMRSTegO59AulqH9DxbHOM3yCfsQS7kTK1qi3W4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810936; c=relaxed/simple; bh=LWlpKAqSPh2SZMP3ObLq+s/FTCguucm8HDdrx5fwRp8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wsawNyNZtbjTB8A/sY9/Lewk1qaVSfodUm2hUotnwtBvALYfMYK8lbg/Rn/7a1X2jwGWHWoJiB06tpGOHXKHmP6J1iM/QgPF0Fn3RnHNYKJH+Um3/tUQHF6V2YYYXSSqTezF8ChLA8aJHrhVf8+w8d6NMKr/yG3qWZp6pH5Z8nE= 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 39KDxVQs002438; Fri, 20 Oct 2023 14:08:54 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucermhgm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:08:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88we032131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKN011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 09/33] libstdc++: Optimize std::is_array compilation performance Date: Fri, 20 Oct 2023 06:53:28 -0700 Message-ID: <20231020135748.1846670-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Uw8JPuSMuX7aehnYlsYDNE24tBoCwwKK X-Proofpoint-ORIG-GUID: Uw8JPuSMuX7aehnYlsYDNE24tBoCwwKK 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 clxscore=1034 impostorscore=0 malwarescore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 mlxlogscore=527 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780283885902527831 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 Fri Oct 20 13:53: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: 156126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1084352vqb; Fri, 20 Oct 2023 07:10:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtLqPBuPSqdg+EjuL7R0XF4SORTdoJuGadKKbnIxSnbEFHC9qH/yPcso4IpZW2AIHa4mEx X-Received: by 2002:ac8:5c0b:0:b0:417:b700:b13e with SMTP id i11-20020ac85c0b000000b00417b700b13emr2521322qti.28.1697811037524; Fri, 20 Oct 2023 07:10:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811037; cv=pass; d=google.com; s=arc-20160816; b=tOjXx3c7pB4tx7c1dI4jnkqjAtpAN99kfNtBCj1gZKP3Av/zNytpA9h0zNxBZjVgbR OlFnQ2qcNUal8K03e+bBZZSLRkU7Gsi0/EDKBrat3DuSm/sM2hQuj1Jx60hCYSPIjUM1 aCFAakioRP7tMrIjGFBfKKrMSCCedLkDppsYOosEgtJ7r6pxe74AqsC+MBrDyMiAlloe xGxtZRyr7/onJvbWV1zKJab+sF7gU963zWWbCkudXRDfDdibpQQhOerxFNBQ5+p0gdiA mbb6VGO/1m72D8IeLNl1735jMbvZFdKTOw9CRL1qpgY6W/nmmFt6OuKhQVB4/mfqMRu3 lDBQ== 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=M1OpUcs8Q6jB4Z9KEOoPfE4tT9/EBxKaz/3ElRCt9vNasZHRyWf5jqrGmOT75XxWj5 TG8gbcg6tc/7wMhfkK5a1frZkyVIQ/MuFrv8kaHnp1dfeRNhrAQAI5TERx4T8V7rsRiH 6prbAxs8/7b9jHqzzAaqzIEMOQ2Ybeg8v4kGPjOb5gIF7irL/Uhn0R6E7BkurAvrTOjw iAy/KXlfySLYIkr54EKwU+VePP62Na66X7bzbmUxtiQicfUG6CNdmIlUV85W0UDAWRYL An2PzIB4FlbyAlmxg+9Y14ah03z3ZEGVTBkNR3L4UiL0hLJbep9wJqq2ARqZOBCfsmqS /TfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Kxtlie+E; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u13-20020ac858cd000000b004109d1af4d4si1289939qta.647.2023.10.20.07.10.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:10:37 -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=Kxtlie+E; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 437D0385773A for ; Fri, 20 Oct 2023 14:10:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 437D0385773A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811037; 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=Kxtlie+E9urpLsVeF5nJ+gVXSBiRP3QxlRZkKEWP2on3W/uuLHdI24BIOVwoFLU4h Ki+f+c8x4GYNPYILgzMiSwxCfY1pB3zV4wnQ3Hp+0cquxB8BmVn9Xz2sXcSB1EdWWz eBJfFLmxis3qXpxVCPwIxIchjoMv2bD2Qc10EwCc= 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 97C1E3858C5F; Fri, 20 Oct 2023 14:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97C1E3858C5F 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 97C1E3858C5F 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=1697810937; cv=none; b=pYWPASFvah3gA4SlcUsVlQX7+kOi/IXOI1L/agfoCrljlY48HggeSfBp4gdsErmdttYliYKSHeRFOvy7yD3QASu2bdzIyFqZJA2RL3I8jA3lO7ZPk93eYMP2SemhnzcUNEYQpf4G3RclU0u7XPw9czPK0gqMXlwSa44pPqOac34= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810937; c=relaxed/simple; bh=NhasjZWVUqUpZZmXqS8d6jkCFZVEX8IRPI+dI1G5T3g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=os0v/khemEz+88EFtMhgJYuyQ+s0Em3aQmmZwHb5LY0qf1lkR2PezWKkl9QGKyeva0eT25TOR6nqGMYjKE37N598KAjnRKgkGsH+8JD6EuQZ+BLLm0iQzPN8iXF0H4aTfIekqsHLWDpRv2R03wy2yUHws58yJmUGyc46ayeRmeM= 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 39KE5mjx006222; Fri, 20 Oct 2023 14:08:54 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc2c4sta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:08:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88ro032132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKO011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 10/33] c++: Implement __is_unbounded_array built-in trait Date: Fri, 20 Oct 2023 06:53:29 -0700 Message-ID: <20231020135748.1846670-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: VMR2xWg-kL_Clu26SepclbKUWfKnmaqK X-Proofpoint-ORIG-GUID: VMR2xWg-kL_Clu26SepclbKUWfKnmaqK 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=728 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780283906225543802 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 Fri Oct 20 13:53: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: 156127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1086278vqb; Fri, 20 Oct 2023 07:13:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSeFg1TzYfZFqq9VpaF/Y9jOTBWt5UeST4y+ayxmbSVTNHd3bLrwzHJeM8amNOXCmrhX7r X-Received: by 2002:a05:6830:718f:b0:6b8:82ed:ea2e with SMTP id el15-20020a056830718f00b006b882edea2emr2175802otb.4.1697811189707; Fri, 20 Oct 2023 07:13:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811189; cv=pass; d=google.com; s=arc-20160816; b=pSvmKCo8oMrZCOEzRMqXDMALTInwtGbrnKZDgtcXkjtzLbXN0FyfaNppc4Os3f7SpB c545Du4neO3yx0FjUwhMMSHGbbfNrGPAHWfli3GKxh2jFkeCpJ8IqFuictbkcE4DjFAL 5xuFGyl0jvMihbBGGEStvQ3Qu/L0ayaBBm3UKnvQ1kUcNDdFO+THpkIt/71bpZqqnivq 0WcaLZ6OkC2bQx9rBvOSZWDZsxc7cxRH3eJpih2HJUmQ3+60RMWFiliB6Zs2/XVOd9WM u26kmV30iBUNsaibLedR6r37Z3CzqAtdDRunp0JnpEjjwXpyLi6WSyB6O7kAeNvNXasx pm8A== 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=ZFAyWrHzS/NKg3aE8sYCEG4xU9k2qpIkcNbbHdN5c/JLdATykFr1dkwSD2mvdHaxDX tLc9ZeMHMWdRx8W5dQHf1GHP1PHtHpXTUD4FqKWFFW7VwiRY9MTfAyqWgX4BEQcgnqm0 eXRSB3G21T2qNHY55AphQXo7JCWzC/nfO/T9Yq/lxfxQBsfZOexf+92cOwCdft2ntYnC uDoly95F71F/CAaat09hDvirvKyIwU3ldcwVbCyfVtfvkNhFY/N2S/uYayusTLZFSN/v OkFhIjIvVuIHxL2kTOhrSDSCvt5qSr+reFDdvXJwrYvCWTRAfqY6FncfrEuQIvYOPRf6 xf0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="BoKg/CJj"; 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 s12-20020a0cdc0c000000b0066d1eae483asi1467313qvk.297.2023.10.20.07.13.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:13:09 -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="BoKg/CJj"; 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 DC4943853507 for ; Fri, 20 Oct 2023 14:13:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC4943853507 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811184; 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=BoKg/CJjv/FzzM1B6PvxR1fT15kNATalL6yWFBJajjwdqre07Cq3qAp2pGgGuO3AK awKpwEveWyrwe8aWsvGgEo0tO8P/1djyo+TPtJGJZu/SHyuyv+VxhD/JgI88RTq5Zo 9lWmwujPs3g1AHJVJ1OY2kBTZg/amGcQK31i79eU= 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 8D9F73858CDA; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D9F73858CDA 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 8D9F73858CDA 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=1697811124; cv=none; b=mWQKE5cxk1ZNd6911AXxjEzBMSXxwh64HSCeRrhtO/eCZXYx9TxNh0CF+d32Q1TrmzabsADcT/TGCNAClP9/2GbwxFBLOI8bJ9na6imtrg6BbVa1EpbyUpJ5mMJFwg434uwMQmrtL05EM9nujEEsJOToV/ka/9PxLOUVyI7tMGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811124; c=relaxed/simple; bh=K00IDF5zEbYHxaGvNxA8OxHa/yILcGh6RlZf6vWDaAo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iOP9nSyc6KzZyEHo+wUe0t4qlfn4RMuPSLycqSS/Crdm2qIoZumwW37+9ZmNQPs+OXsJUAJXk0MiCPIVg/4ut7y70/nDIzLJecJ6x82/giUHkpCubInrpsRC8RbuwBY0BRmvJiiZq0CcZpXGtwY/gRAtPd/iULPrf4dLhtOUEEw= 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 39KE8l7P030533; Fri, 20 Oct 2023 14:12:03 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuecbu85d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE883P014699 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKP011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 11/33] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Fri, 20 Oct 2023 06:53:30 -0700 Message-ID: <20231020135748.1846670-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 3448k-4PqS-bIeI-hAiscMqSbB71tKki X-Proofpoint-ORIG-GUID: 3448k-4PqS-bIeI-hAiscMqSbB71tKki 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=557 mlxscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002967013735782 X-GMAIL-MSGID: 1780284065682991139 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 Fri Oct 20 13:53: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: 156141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1089138vqb; Fri, 20 Oct 2023 07:16:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4brm6EQ/PAubvsncw+HOshIHTdNxkcw1LNwgElSFQSEeLYMSM25SJPIEx0lnmmF7JqF4o X-Received: by 2002:a37:e316:0:b0:778:9886:71cc with SMTP id y22-20020a37e316000000b00778988671ccmr1811421qki.19.1697811418433; Fri, 20 Oct 2023 07:16:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811418; cv=pass; d=google.com; s=arc-20160816; b=GcJlie96HcnDEALCqYWNu9EIHBaYZf+VOMSyJ5n9mTwSTBczWUOLBufk2qlqgzt7Hl N2fXKHcRMZLwSfwGvr6xPsHKx/PMlrForOeBcCjWnDM3cTCkzx8emuRD0YfWxn4/GCb9 cVkDyjKIL84kU4t2kMNhuIFwGOl6oIhjLJ2hQJvsvrq79rNP79Vl1JvBOPyRPE2MEVhj dSc2NMpWpwZXUfM+brMzl+W9PTy7U/pVLOn9eTZJCJVXw8BaDEfsepwJ5hjfD80Ymmwh cIo4mPhIZGwNEjciKaw2fd3O0t7cjcwYLAhF1IPxAaKdrr2SdQo7BKJLzm6BC8C8YAMQ lvTg== 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=MhhagKGeG3rXfhHr8RkxU+ppuLzm3KYEQvVS+gWM2f1MgA1PXoH54V92/OTtiShqxV NYs2wnEpbeZer0n3knu75eQHS/JWIw6465zGGrexgmny2hn9/m2H8L/ThDafRUFWWDby ClkgCLg8SwiW8o63UNQwqhA8mCndTqF+SKYqjGKS6AT3Y5AR775Q1Tsjj6wRjD4CQnLv klxvBlt9EI1oa8xXB2wW5kIQUKkj0EyHFW3nY6mcAA6/D7B0Bl7BOT2lTaMm1XQYASeL H9GK5mbsnYjS8kEaj6Ea1Bkx1hfcr2DUwBSJzJmHRdipbILrg6VsHXYvGJADwyoveUvu jS6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kOZSe5IG; 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 bi32-20020a05620a31a000b0076d990f8864si1450178qkb.259.2023.10.20.07.16.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:16: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=kOZSe5IG; 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 411173861848 for ; Fri, 20 Oct 2023 14:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 411173861848 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811378; 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=kOZSe5IGNBX+zPYXOKPUcNYklz4kffo8z5bBAWw83Mm+H3QvzzC4L9R4EbCJSl3jr HJG2RS781xY93G7/erdrb87GUx5h3Ag62JRNLY1BMkGK7ztoyNTCy6szswwDxyk86W d3LRDqlcpA6264s2m7IigQc/KJxPc+PsZU7qaZCk= 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 20E7F385843E; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20E7F385843E 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 20E7F385843E 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=1697811126; cv=none; b=qLehjinbts9PxNIabVGn3o3JLO1tUW+qF1c92l0UfCXFjTJ56HCSawYeQl3lnSHFjxLA+BOkYbW1Kx+xa7Jp9gAUsXTAo8joCeiJl8qHyAoKua1+dR4w6Zzlv+2X+Wwt04tn2EcU2qvadl2gDtToca/oXVLMYSL7XAH5oSPtUik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811126; c=relaxed/simple; bh=nZ/pEsqPL8Mwkgwx3MhbngeLpQUO9kpyZb6eSrDGXGc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=MPrZlz3JSCWpBa84AWVeMZoUaeFdMSDBGEedVHa+/kvlFVwcBNoW3ufp1eGpgjJKPXsRloBRDI8Sm7OOnXAilNbTK39vvpGAF5rHg6Q6ymqMIcMVyHZ16L57/TDWeZXjHFlhQLzmnNpD25ozIod3kVapYL3Q47bLdVO65QGzNh4= 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 39KE8l7Q030533; Fri, 20 Oct 2023 14:12:03 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuecbu85d-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88X4014700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKQ011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 12/33] c++: Implement __is_bounded_array built-in trait Date: Fri, 20 Oct 2023 06:53:31 -0700 Message-ID: <20231020135748.1846670-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hEGNCt_kVDM2wJgMaC4-rMmMTeuh2dSV X-Proofpoint-ORIG-GUID: hEGNCt_kVDM2wJgMaC4-rMmMTeuh2dSV 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=688 mlxscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1780284305791717007 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 Fri Oct 20 13:53: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: 156128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1086685vqb; Fri, 20 Oct 2023 07:13:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENq5fSbMQSK3mQQW+1iaqQJiS8w+ZiLbje25aNMPPmCY3dT1fzE4feYSJhWAQ0F1JS7wL1 X-Received: by 2002:ac8:5a0e:0:b0:410:9b3c:e828 with SMTP id n14-20020ac85a0e000000b004109b3ce828mr2133827qta.37.1697811226397; Fri, 20 Oct 2023 07:13:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811226; cv=pass; d=google.com; s=arc-20160816; b=aL6vxDPEEsszITJJdetL03lpc8DkmjVYJ56J6d4Yld1Ue7HPx7vl3vAsoy0M/a7do+ 368wjoLteCXkIaKzibbgszC0biImIMz+P8i21HXxpTthirawo4ec9BytCYGpUVfUTxNu kBSGJlRH2DwstS7/h4uR4OLDZhY3EhpVlMzeEwR2kfS5vqHqref8N3BtOl2NZjtNkmBV 0i05qs/hwyG5kYWF2nKyIAt0OgOup/OV/w5FTs/z0EKH9isFVicKeoJrkVdNhBYa+Nun 2Y/mBV60JffAK7vAakZyPginqN07tsGLfM4X0qDCmxulSy/0qiWiA193gCr9K4yfhUxD AyYg== 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=zfBjhQUYQCgBww42+cTiSskFz0lXGpGSlJ9GMgGEjsPAKKHDy2JdfJ0gh6vi1q4AgG coOPqKa1dLtHmVE26kQi5OLfLfntjxPgUdh6vW1E3gE7UpEkmC0Qn6wItrOwiiqmlXJI 5RBXc35NiALgb5DEciA0MXfLJV8BJklKRtxR7mpGxdkwflbQocW0YZzgnIm6LTfsOUAj wZxhIob6Oe399uHlrbdbDLuf/f/x3Q2c9+DCRz+nU18zWGbKl5AcYd8MANH/l2ljhok7 Ce7/oJvIcXtJg4xyQIQjv4v2uFxDiSoQiSAImwpc/GhsAGJVs0j+mRHUr5ph+7rtcExd gRGg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TRQTWxLD; 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 p5-20020a05622a00c500b00417ce695031si1410264qtw.258.2023.10.20.07.13.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:13:46 -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=TRQTWxLD; 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 B1CB1385735A for ; Fri, 20 Oct 2023 14:13:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1CB1385735A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811216; 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=TRQTWxLDsGEOoz+6FLkBKVgjNKvtt3XdRCuPGTmavdN6zQqnFsaOci/3mvHaBo41e oX5ErqP5v6b9CIBle1wWrxM2FRcTzKI8GhOEaDXtLBdHAwfM4+EAuGueloYNXrWafr BpTXWTR21zznhHd/GLLyiSNe/381vSpi1zq4V0ys= 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 7066E3858D35; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7066E3858D35 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 7066E3858D35 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=1697811124; cv=none; b=wfaQsaovFpOOyGRpACTpmUa5xVXQQRG8A4tX9p5auQPwj6Yf4l2W//Cf8uwe/4oZS+KTWBszC73DahpG2zRncdfQZ6JqBNoSDPKvdFY6xf7tWIaRmamgI2r3CObc/E6STDwqdT5BzbmPqv/8+EBrgV8am/GptKETFv1NGKNYZks= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811124; c=relaxed/simple; bh=Gwln+6kReoTjeSwMaRkvh0PM3wCmQoJc6szbsyWoD70=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rgzRNOcEChAEj4hdDcxHWEs29iJWJRMcyzVIlvVui/wd2IEHNlzImbhnXhNTPnTAGM3gZmwOUlOHJMdEOun4AvMyyr2a1LKUXR6PzfjoNE8e2QjH2SPq3CVRnOfub1wX4O+e3BxTp9OtLJZESGCPyfH7xBcASbD65GNo0NzG610= 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 39KEBgoK000390; Fri, 20 Oct 2023 14:12: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 3tucktcebj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88Cv005578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKR011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 13/33] libstdc++: Optimize std::is_bounded_array compilation performance Date: Fri, 20 Oct 2023 06:53:32 -0700 Message-ID: <20231020135748.1846670-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QbktX3xzzXXc1-LVEjYpvPBP3m5bj3_7 X-Proofpoint-GUID: QbktX3xzzXXc1-LVEjYpvPBP3m5bj3_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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1034 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=550 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003208222706603 X-GMAIL-MSGID: 1780284104380741392 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 Fri Oct 20 13:53: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: 156149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1091187vqb; Fri, 20 Oct 2023 07:20:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXqiLR+8nOwFXueRAjfXcN3UEjiqUZeKJeTuQ6/spnGDsgTnpvHunRoNYpIWWedI2vu0jZ X-Received: by 2002:ad4:5ca3:0:b0:66d:6585:e787 with SMTP id q3-20020ad45ca3000000b0066d6585e787mr2374526qvh.39.1697811603819; Fri, 20 Oct 2023 07:20:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811603; cv=pass; d=google.com; s=arc-20160816; b=xC/v/TFr6QDp3+e7Tn/J/IK5/JNYO/7yU2M/PTk6eYxmY9PnZrAGPeGAdMTi1gjpHL xpy8xJfKL06x4S6QxjJgaEuQfsX8xODJOazPQivMb7UU0POCTt4ARS/IwaIgG1TifYYi RuOqIEKwDBd4FHfpQvIE62TqFbraJ66x22aGyOT4airz5AGXS6pRuJ4H8kh8+JYq4N4/ CNL4aARgsS0m6USJ5xqfxhx1PiSWjrniV544LFjZ/xYV3xaA0Cw1fWlaxoe7IBA9n2xX WbAjNaxyWkAQBA8bHDJ5ve9W7q15pb222FaTui0rLhVOj35Y2PhVU+QpzSSkKkcWjAHR Wtgw== 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=iX1z9hqDmpbpBXXwwJWZYp8BJMlTeXeBAxXRTojCnqKoLH4enwJeruGmSk8Hy0WzBL 3Az4Hm9JoeKfu5Y040D6Oa0UojA7dHUGU+OdE8VxjP3c1ft55Ck6+d6gOlJKUXU7gbuj eO/jXDBIIzfgl6JDT17j4F5M+c4uRU6ZVJS8mOcmubROwqGapyeSbY24pYvtu0qKLn76 pHViR5SL44lBss5SnWpHhW4wfxVCi6fJ4nbkMN9mVgZOZPB+z2OYv+4qhCZE61F5Kr23 nmnxRdBQfwpkkOSaAXBjti7Zx2UA51oAhmLV9v94i81Q/8Z7nBUEjfJogY1kJRa+5IZK NOQg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jZafBtVB; 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 u10-20020ad45aaa000000b0066d15c73fbesi1565065qvg.117.2023.10.20.07.20.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:20: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=jZafBtVB; 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 A09FE388302F for ; Fri, 20 Oct 2023 14:19:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A09FE388302F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811560; 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=jZafBtVBTjL1hV6+C3ktcpQQQkHG5RszKfDqAMEjOBTJrZt/3BA2QFxJ6QQr99iy7 VSO7mVFwBvKn6AEUtVhe5RJ3bV49XKIrDeNMOu8S+lB2j5EebyrJSOtnzkdbgytH9g oXiFh6v/cN6Gdz8ewd9Ma8tGmkl0kYSBdhTxl04Y= 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 A4A1D385C414; Fri, 20 Oct 2023 14:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4A1D385C414 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 A4A1D385C414 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=1697811177; cv=none; b=lAZI7SarjPLJpujSySJDOMxB0R7Sq7SvgzSbqIVzX9iZjexNvMczDBZx4hycHLMZdhoYtCetQNpnynEtzBQKc8T7fRSfx75cGSRWNWtoLRGcIVdrYGVjdonwphfyF2Gm688zc7GKr4Fo0oBgGvSRKb6kEFAm3gs/cBnSbBy5rCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811177; c=relaxed/simple; bh=fkQruCseJD3dB1E16vhUv/gGSDDVp/cL6/48GiYilPI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TZFzt782+X/lV1J49DOO/BsaQM65XXBPUqPFjzKTwjQVd0EJqK3yViVnymFzfykBzKOAiwstyclPz++xVSnf0d40L/4QrAQlmHQeMZQT8kwd0wGD2qZ/uKKld4kt7AquGxvpTqfj5AsvvomNpiUCfSyYHpGGIDBTE+bd/+JXW9w= 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 39KE8ROQ005885; Fri, 20 Oct 2023 14:12:54 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucu1mb7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE88wh017239 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:08 -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 39KDvqKS011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 14/33] c++: Implement __is_scoped_enum built-in trait Date: Fri, 20 Oct 2023 06:53:33 -0700 Message-ID: <20231020135748.1846670-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: tnyL2vkczzEXY9wr5m8SYLtRC8RKexPL X-Proofpoint-GUID: tnyL2vkczzEXY9wr5m8SYLtRC8RKexPL 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=710 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1780284499963687557 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 Fri Oct 20 13:53: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: 156124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1083646vqb; Fri, 20 Oct 2023 07:09:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkNIxss6G/NU5IFAwuvurDqSMxd6AlA2uV5ckuexm8siemV6KMPNAjzA0sl2HZw9e2mtzw X-Received: by 2002:a05:620a:198f:b0:774:1e07:ea0d with SMTP id bm15-20020a05620a198f00b007741e07ea0dmr2063967qkb.44.1697810986412; Fri, 20 Oct 2023 07:09:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810986; cv=pass; d=google.com; s=arc-20160816; b=DIhN6e3yOBz++TO6hLmzeMIkLlySjNf0OfaPw3mydQCN8ocd/P99B7mdagxpueeEHW VeXXAOHqsgxD7cMMvdTeXTxKL17nXpr+C3d0ILx2b72QkbV0D2rpQeltBaTIoMo3eJzV nfhJ2MLRX6hWUxZwfgOIWtJEq+l9aIGsdIsrJLJE9pmn2OK+o78czdWtcxK1RIdJ5W76 rPZp+hGHzuwEz3NA0GkXSJx7jTA+j0IaiKY3WAe/v9EPUmwRcWpzSyDs2/+ISN34sF6y ti3evJCy++GGt8SMyAf1+CUf2WQxgeIF/6DJ5vaIHwVZsAx6plcwEz3CAKRTsUg9amaV uHIA== 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=nq3KN3qZaMueYhhnkWh28rTdAqZrlz+CN6KJVwyQfqYiF4kT940L1GnXcD3brwBW3P gQ6MAhxjjuRKeU5X2mvqyMUzsimhwEXC/zHv6LKxkAL3KM6RbUqsNdQ5GZhiMcLNwchp u+9bol0CF9OffVePq8L2EUOvrgJ+T16yDIcvo86LdIM7W4D/59sQzp8tiUBoBCtmPvlq Zq7I8TTOkV+AmU5vrQJGxYsAWMUPTkDwPtU7Ovgt3IbdD4psqg1nP8SkiW4INx08iMx7 mpfQHoshVf2DUNa/qPWwWDfO14hw6RiLsZOfpN3A4xeafqMd+3RL4tw/mXQPYLMyQ4Q4 mrfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tvAJWRPG; 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 j27-20020a05620a001b00b00767b3a5d245si1272604qki.125.2023.10.20.07.09.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:09:46 -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=tvAJWRPG; 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 ABC00385C6C4 for ; Fri, 20 Oct 2023 14:09:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABC00385C6C4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810980; 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=tvAJWRPGaBXQXLR83E+dPkRB/dQtLknvaLb/PRkfLrjrNESN4mwWcTjlEOILwfj4c DX2f2xqPFRIHi4qrZerhkzIxd/ZWW7K0iUsf/Wvn03dWJJAy+9TKOiRPXLft4zTrEo 0Ha+WKpDu9fh+THJZhUY4s8a6f2Y70kfQIQ7vWYA= 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 4CF2B3858CDA; Fri, 20 Oct 2023 14:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CF2B3858CDA 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 4CF2B3858CDA 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=1697810936; cv=none; b=hdx7wjK7LjaSaAMmDbwQQxjc6zLPLBvlLsAwtRuwVBgJbCZG2cpkc1sEhpaPjUsXS+tdzwQroMmCOzIkgVCY8UMRLV6a+78FsiHmpY96YnW/oMUFfhVAtB7VaCO1ChSvFzaxqzPJFkMTY826UMo9LICixW5DFCn5ryWonAR3TF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810936; c=relaxed/simple; bh=0fJjGclj4XvwKH8AmhnNT3eHruG+WCMpFlf3cIH+UjI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=J8S9Kyjlu0ubBF4ZGte/TyhOAwB19/gbKtGqMOvINJ0XV+Vt3URUe89CnU2WXCDS3436muRkiRdjBdnFHiObtBes21ivXoVX2Z3L2Hgqg9g3oS2AnXZInenEay1V44N/kzO5XKf3vbbNShfhvBWwUbY2J9mLoPcvWzNsIoDqF40= 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 39KE5WbQ012149; Fri, 20 Oct 2023 14:08:55 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc8gmrk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:08:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE89sv032133 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKT011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:08 -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 v23 15/33] libstdc++: Optimize std::is_scoped_enum compilation performance Date: Fri, 20 Oct 2023 06:53:34 -0700 Message-ID: <20231020135748.1846670-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: RoNHzrpFZtP-MxwC9jYVNjFvd0-3UxuY X-Proofpoint-ORIG-GUID: RoNHzrpFZtP-MxwC9jYVNjFvd0-3UxuY 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=818 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200115 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003114363271989 X-GMAIL-MSGID: 1780283852477334196 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 Fri Oct 20 13:53: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: 156146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1090458vqb; Fri, 20 Oct 2023 07:18:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaNFNuNNfBe68T1YhERAN20GhjKXg4jUeaO+m11Zzp8m3TcelKT5IYufTY7QCsrN66RmdR X-Received: by 2002:a05:6214:4009:b0:66d:20f7:8d89 with SMTP id kd9-20020a056214400900b0066d20f78d89mr2113223qvb.43.1697811536047; Fri, 20 Oct 2023 07:18:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811536; cv=pass; d=google.com; s=arc-20160816; b=KTEeHh2+kWVCBmqldlSTfVufTS0sny6Iak6mieJiR4RiuEokFIjRCwNKnHYMZlJ2TF qog90VFDQZA6gUkEePn5cButKLmkEszTROQfV7QHDVTRrRT+nsDw3Jsl7v2y3pZV+ejH INCUg0FxOkVRQQRYCh8q/rzDOKeaJPuou3AWB3wn8PobgXwpCMbFcTZPES2f/5Ijr9ul /DKYY6spbkFbULU92oJipMJ8RjjS7OvT/p2Rq1GY4yYxWqXj7OLFzTSgFZ6GvwFS4SIj ITAsJfurvMXRUlsc/IfUJfjaIppefn6vj05Mai8b8NU7IRdv32sp9bx3jEjXsvkECcuS 6rgQ== 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=MbHOka1wQ8PJ0XTp1sjXwa4jpOG8HxOQhH2CdetJs9xkOBv1EVm+NMB/iKHsUA1NDL JAUX2VfAZpN6TnQUVMxFSQzhKPo9raMfPVXLzJlLClnaSBjJvT3VfBlxOv/+gwvQgVd5 YdOmGZ6DvMJQkWOSdqlCtpPSo3WyPI8P8icMhy69Do2iQN7SBOvq6qKEpf3jRX46ND8I FuqESMkNEHwGlVcTW3lj8EzIDKBfiVaaGyb14CjIq/guEdOoG/wtOf/3IkA+8vIk4wPw vPBpvsFN1VJAfHR42yqk/SRcDBKHufh3CzEWYX0N8m5Lc68OVL2REldLYlttIajCy6vK olCg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Sn+63hj8; 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 if5-20020a0562141c4500b0066d12b4f281si1510313qvb.477.2023.10.20.07.18.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:18:56 -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=Sn+63hj8; 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 65AF83830B56 for ; Fri, 20 Oct 2023 14:18:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65AF83830B56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811482; 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=Sn+63hj8/50TxvwuBomB49/STwWuLLTkCLm+JOiPgL08ps7s50wEo5fwpSmKRqAtx Dx066A3F/i4/zH5IOrdxBmymz1o6An1Q4PFYpeUT3RVCXnwxIqZ61FkRiAV/rbIp/6 aKP/O2xpd0mmaQHfwn/NRCaGHNS1X2V8oLoFlFBw= 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 20D2B3857732; Fri, 20 Oct 2023 14:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20D2B3857732 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 20D2B3857732 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=1697811128; cv=none; b=j3pSVFp9ED7uZiF65kgF35a1HLcX7dvViDmr+bGpxPBs7UxIjXT8vs6pgsbZY34kLIaP5/wSe0lsxYiLqDkU0hMYDCm25qxl5lP0A/lwtrAo1UtT/oSd7MWw9q2baL4c6lYIKGmUoF2W/g3LP/H3B9zaEliJlxVWrYUKJ+6GEC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811128; c=relaxed/simple; bh=tTsXR07ddbRuc8GHnZgjHVGOldxUmME9x4Iwp7/K0aM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=drrPSf3Hp57Vt8HNkeXFtqOng8XzZ2hFKmynlLyyxx3fkA8CZ5xFdoysljT51EPqG/m+e8sSEC6Zpt0RTXItxF0joKm1zohaTTqeGXyzTO6hgaXy5N4wai5g3ETWs5ez6wMuKLnE8tp+NFSIuHGjyGucdxChg25mJkwuzS3+uek= 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 39KE8l7S030533; Fri, 20 Oct 2023 14:12:05 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuecbu85d-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE89on014702 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKU011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 16/33] c++: Implement __is_member_pointer built-in trait Date: Fri, 20 Oct 2023 06:53:35 -0700 Message-ID: <20231020135748.1846670-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Hf4mUcP7ISRXfDUeOBcCW80j7-g1wGDP X-Proofpoint-ORIG-GUID: Hf4mUcP7ISRXfDUeOBcCW80j7-g1wGDP 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=859 mlxscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 clxscore=1034 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1780284429525226338 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 Fri Oct 20 13:53: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: 156130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1086728vqb; Fri, 20 Oct 2023 07:13:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG85O6415hFnUbZyHm4QdieUUnQvCvLNAPMrgyfGWKoFDGVT2f2NRTShZGGKzPGmCi4Pt7B X-Received: by 2002:a05:622a:24b:b0:41c:be07:c6ca with SMTP id c11-20020a05622a024b00b0041cbe07c6camr2144720qtx.32.1697811229367; Fri, 20 Oct 2023 07:13:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811229; cv=pass; d=google.com; s=arc-20160816; b=lQftzOQSgOw+WBpMNTv1j99eA0EnXUhLMm4ewSqmqrzhDV2VsmPrM0tWIdAfL3z/AL GWAk3N6rhPK1Mhf5WCUP2OfYJ3o0RGSRVrehut8EBUWmnzsG3rCHoyvcdQ68IcowejuA yYHPBDhe64Pw4FIs9lUUTzDLQR4VO39AdRqmrHkhEX7AkyDy+EU9+cWvla6bI8SUfbmT D4Z0CSXDdNP+vkNNWrUK5njlas+dkZu0T7EGkENcafBh6PiFarnDi2H2bYnNeFLt/m2e N4rOohrd5MTzay9nKTyH2R1xFA/UtX46tsinCdW9Jm/J9qgC5F0F4dciQ3IRycOBArQ0 ZStg== 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=t9WvjYHU3FGGf65qwwycYPSuKFxCouqyRdJo8s1MarnkqTj8gItlSzj6qBvoYZTjrr KwvECTBY/OHCwwD2Dv7i8pU420hX4e1kUSlLmIXQ3rv6Ql8/6FvD6WRIiESFzCbeyhvq uM/iWFRwCiKljG4x9WXNSD6gk+XWjpNYD0CwCws4z0kZiW0xC+Y+ZnmHPgJ1CaVU+Qg6 xKjEs8+NQGQ2eB9VRImVHpGSuMwOYiFNK2FTEgHA+HyamOflCTJYM3eVpmkodwNG/3XW 8b4D8Riovtq3SkiX7ne7DMR+5kP5wfm0lb0Uh7596Dg4Gl0SHbkIkOyybeq30qsit0lb JojQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xqzKKf1F; 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 w3-20020a05622a190300b00419628da44csi1333737qtc.526.2023.10.20.07.13.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:13:49 -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=xqzKKf1F; 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 335AB3853527 for ; Fri, 20 Oct 2023 14:13:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 335AB3853527 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811219; 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=xqzKKf1FPOnMVXFM82y7eERYUago88sPQnbE7J72KSx8pJnqldNF2tUj/W6i8Sasw vIuoliZgdxMj9I4zstgWRVIM7udojXR4d0LISCHwfedHsoZ68gc6e446JFwPOquLMq 5p1CG83QljzwHHb3qX+NaR53Iz2aiG+F8tkwTedI= 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 44BAB3858D20; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44BAB3858D20 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 44BAB3858D20 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=1697811124; cv=none; b=Bg3JuothHaQVl4g8iHvohihkwYqwfpnjR5YfDLztCmKGdrw7GxZ02oZL9kSRFNV02+4P46JmcYw/6ofLNdckzHmq3bR8HYyfC2ks6DPvHcBVFP9qs0euQ5hMOD9JPMalBgNJy2nxm1Y5ZHgxlmqlbm8QfcQ3mOiJDNqs9+PBYZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811124; c=relaxed/simple; bh=f8Yn4ts+8fO+dAvSx3E1hRc02AnbIXSjgLj2daX9YKc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iFs1qdn6BE2kVNEpIyE8aBs+DfKvFI545kIlHlAN80D1T46MWJrCKP1Y1FoUIFIXOvOOSBtWw59Dmsfrm3k0BPARckycGT78zJI64zlkIMnmtA6YCirFiDXI+CsJu5xLliTML2vei6pBJg4k+4VzHLBlwDfrwXDDELf5JQEpap8= 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 39KDxVE6001003; Fri, 20 Oct 2023 14:12:02 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucwu44hg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE89or015898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKV011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 17/33] libstdc++: Optimize std::is_member_pointer compilation performance Date: Fri, 20 Oct 2023 06:53:36 -0700 Message-ID: <20231020135748.1846670-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: tuHh4hoxIrW0k0YOF5eNqCkrxpn8dOAS X-Proofpoint-ORIG-GUID: tuHh4hoxIrW0k0YOF5eNqCkrxpn8dOAS 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 suspectscore=0 phishscore=0 malwarescore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxlogscore=384 bulkscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003567680885453 X-GMAIL-MSGID: 1780284107937927624 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 Fri Oct 20 13:53: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: 156145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1090306vqb; Fri, 20 Oct 2023 07:18:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVhyLykew7ygR4vQHaNjOhJHioUo97j0o2XAETL6IsIG6FhLraRE9Eh+ZBZC1AOwLTGDB9 X-Received: by 2002:a05:620a:4491:b0:770:9bd2:b3be with SMTP id x17-20020a05620a449100b007709bd2b3bemr1935826qkp.5.1697811522120; Fri, 20 Oct 2023 07:18:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811522; cv=pass; d=google.com; s=arc-20160816; b=wBWgzdc1r7DHqvud1aiHAA1ZIVBqbSCRPIgkr+bMsNPbFNoQWpogYjUCGsjt6VNq4I jQkkXb+FiJej12TRtoV8Y6OJiZJkC7SYzdf2/1EPnRk2EF0IvdKmFIHFyia8mA5N6l+E Ra/8EUClXnA0kKIZ8uwDA4Ub2Y0KHnuPZz2JNfWYOOmtEboM3AkbIPhucnfL+0OrQRx7 CtnOFFzdWCwYOuKozO//VWWgwB/tGByOn32H5UXQmcRGqxIyRgXitsuFKfTeVwlUDLl6 wTIbi+jogdQpxNObYp33sDUL4b7Wq/oKwY4+5vcXQsv3wqiqVxv0AihtBu5FdMV+z/iC 3QxQ== 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=DnzsuoxKVASKx1mR31XpdjwB65RoJxbH/Hc6k4efDN//AlW++xbdPXOEabnqtC5ere eMgRLf874HY6MWdxIqDuEhHMpEZMD/ek3pxitIALL/70Y4SqdNaKizwUXgFY2pkG/jof 1mYRQPZfGfsRdAAMtA034UxYloyYs6s5snhXvxpR24nLAbXQd5/8SBlcwAqrRUIGW2tD XdE/4KZPyq7bgPztFiwd7ElQrvy+mgNpaCD1JU3Dl5SOCXKv+M6/emlwLhKBUkQCviWy qDVCtzXmbluVHCWrlpbnoVWTk+GmjrCLg5dqRKdr+3lRQoju0jPrIFIncmefrBfd2lGk hx1w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I7hX8V9v; 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 1-20020a05620a078100b00775cf5ea68fsi1316934qka.65.2023.10.20.07.18.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:18:42 -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=I7hX8V9v; 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 4107A386190F for ; Fri, 20 Oct 2023 14:17:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4107A386190F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811471; 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=I7hX8V9vM+cikdRzKgyF3nVi3tgR9DQDEqAsraeeyXhl0coKIKeVePb4JmwjJVFdO GCWmHT+NKBXLw7EsVAJrH5ZjDEX3/nKCu5usuPNW2LSoNs1hwTgIyOU+LFPTXoKqe1 6rhx1/6t30Mh8ZTJB+7ShNScHzftBhVlCiK6npUA= 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 C387B3857707; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C387B3857707 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 C387B3857707 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=1697811128; cv=none; b=ZZsfmHyg+D9oR7TuzOsVovMUgSKNX3/Sh20r0gyrlrossbMMl0uQddgiW933W0EtDCmrRVmuaz/P7B4S/OxC4nuHElTIzotROQ9fNCauNh+CFOkwnOjwHNJmZZvPSbHRWjAOQQ4Zv4MV39z0uT2XXV1RoCO0MSJiRuKJZBAYTIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811128; c=relaxed/simple; bh=Wu6uxEsGT7DwvMgeZmQ/CUhdHfQIMcBEaar3J3BUDrE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lrbjhWFbc8fL1cEJrhmdP04E8cocQHgzbqrgT4/Tw64G25FRYKsw21Zv5oKRXgttnjmc/BedcKxj3eZ4RhVwgqH0dVL152bQ0qmIc7EVqLFNSZyQ2mkMaFb0TP86qaWk5lP7CVZWF7FI7ceptIbCMpBjalPzXrHJTzcOjMpLR40= 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 39KEBXIf023139; Fri, 20 Oct 2023 14:12:05 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmhe6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE89al005579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKW011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 18/33] c++: Implement __is_member_function_pointer built-in trait Date: Fri, 20 Oct 2023 06:53:37 -0700 Message-ID: <20231020135748.1846670-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: xUAWYs2O_eqXv5U4T8H4H9T4q-vjiQdj X-Proofpoint-ORIG-GUID: xUAWYs2O_eqXv5U4T8H4H9T4q-vjiQdj 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=915 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1780284414690858083 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 Fri Oct 20 13:53: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: 156133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1087511vqb; Fri, 20 Oct 2023 07:14:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXv0Q3k1yMvpDz2aXHAOW3lAm59qYew5ej2Ud5OpiGugpnGf5oLCSEkjKjB71zGL7B4LkQ X-Received: by 2002:a05:622a:11c2:b0:410:87a:be98 with SMTP id n2-20020a05622a11c200b00410087abe98mr2342537qtk.20.1697811296573; Fri, 20 Oct 2023 07:14:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811296; cv=pass; d=google.com; s=arc-20160816; b=nbYCiaLdelDszZqQEwUPjtQwoiKas55a7wmvhhJrWy2hhkwZgdbnp0Ty1tntxewuac I0zxhWxvwMRQ6b3z/TB+0YUFnxl3XoL2tMsy5j3MRjoK5atEv6E4oTh1d6yxq8Dz4b2m o7VLyC3WKI8Xoffv9vnNzsdIVldTyAuFudoIzyTQQTcFzgGyCQDFI1Url3As8BiOK1yf UQmPriOHYy6qvfOP9wdsFVQvc8CUubDoso3O8UXWl9GVbuOXmnMY70JxzgggvLOhpF9X LWMELgCvKTD9QE/N2klijJPYnbmXMNhICyEfpzV6xRqS4RVq2/HywPuV+FXr/n3/hjz8 Mzeg== 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=S1OR0X9yND8hQywvQ/oBs/fh7N751SFySs20P7w2PgyOpVT67BBjZnvOjNSHF47qH8 Bw8H64FXTdzYa0YD8+WJjrRTyeu7WBrPbKd47x6KO5S8y9SI9dojL4pkZ8T8eACPObcR cstTmwvZA02CMzL+uZ1gPUHKg1ZkFfg5ayp87KK+5i8TkZP1goFLkJjNVwoMPU8vuS5h tzb0oR+9AH0miAz+RWzL35NIyM9UfilbDuIpD0tbzdl6r93AbfrT+jPPOFEHAz8vTseO SAcJbv3gHGkstfrgvPn9ymLPXcEQ2Rr0hOOlu176rRFLmPflDZMyHrXvJK4A12+9Mn7m gSTQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SvBg98H7; 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 d21-20020a05622a15d500b00417d26b122esi1357379qty.354.2023.10.20.07.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:14:56 -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=SvBg98H7; 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 3877B38618DC for ; Fri, 20 Oct 2023 14:14:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3877B38618DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811276; 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=SvBg98H7SCyQ/baw176Hq0/5swjhctLBsN51bc4SWNf0UZCpYDgLRH1Ze+MtgfV8r LJGmqnD/ti8AGlQhQgowcsgHK6hlhhd/fEosGoFBmgHuvDFiZfha5KQBOC4bwAdgCG YXPF0Qc1YI/Bvcf4HLrgWH+mGZrqVgIcgzi9uP8w= 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 95C163858C50; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95C163858C50 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 95C163858C50 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=1697811125; cv=none; b=fDDNkpFGxDWdmRfY+jc2Z2az5dAFP0hEuXQdgfI4fHUHGcBSjP1MERg4we1tVj/p0wF8LGixyEmhUd+NUkrOUYhw1j3tLQUsX+q0BjLvwX0jhqmM+OiFhlmWcX8BTWOKXmlnWJmY4Fo3W+VvnY6dO/WKZKqp1iFnkg/mBX+LGsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811125; c=relaxed/simple; bh=BeAwYIzK7d5/iToyc1oLwLq2kGHJhlp/l7AS5fX4HMw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bLgQdL205P/vHh7lUPjwFlqi/NeZRzgXaPHyt5I9n3opV6i/UlaJJ+5PKzIFt04/IucNjqUpRxV+GEgJZpU8Uo1WDjr4GZyeSnNy912RQsSyqFAW3ZoWNGDJ15vDm+TZsY81AJwECi7HskgjpxFfP4kykDzCSco332HlDsfc/Xs= 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 39KEBXIY023139; Fri, 20 Oct 2023 14:12:03 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmhe3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE89UF015899 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:09 -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 39KDvqKX011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 19/33] libstdc++: Optimize std::is_member_function_pointer compilation performance Date: Fri, 20 Oct 2023 06:53:38 -0700 Message-ID: <20231020135748.1846670-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: nVxAcyGlyz08wE8bAtlGV_ZC-2OQTJmQ X-Proofpoint-ORIG-GUID: nVxAcyGlyz08wE8bAtlGV_ZC-2OQTJmQ 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=474 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003547168618314 X-GMAIL-MSGID: 1780284177997490646 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 Fri Oct 20 13:53: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: 156147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1090633vqb; Fri, 20 Oct 2023 07:19:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrOAN2803QBSsv9wiqKAd8KsiBqA1p+mLpAS/tpIUp57vqabMefhDKh2Cc/LHN4bkJ24+W X-Received: by 2002:ac8:5791:0:b0:412:d0b:12c0 with SMTP id v17-20020ac85791000000b004120d0b12c0mr1822034qta.22.1697811550949; Fri, 20 Oct 2023 07:19:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811550; cv=pass; d=google.com; s=arc-20160816; b=et9TZjFDKcfGydXFxGouUz4FnUdtjPS9txFkgt3mmGcJqrsEo5vU7DoqpE5r8JHWmI Xk2b+7MYKCyywPwBnSxPPc454bn1WoC5++sfZMOhN7fav/JOcLjD4yxlghVdd2rWSEzy mqrLL+E9rvh09shWnqFYcqREtKv/VMHM5z/10ouDRuMsSjhCANgyz035a88D878B4PA/ 37D4Jgickk1v8LUjtR4EvfTcNGcwiCin9EgGLwbwJchEV4c7yt1XVm16Z6Mv8Z+AxTui F6UxVEbB2YKIq1grvgxRmuhy2UMvNu+Inee/f0nzoBjiWx1Iq3AYbpCK7MQhvckf1vir deFQ== 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=QqFajbxmwb+rrd2WZIkrsl68KMOaoCl8U4jYj0jKEOug1jzM42lic/Y8LuDsgYUd2v w2OdCkHehbX2zerHmP1LYr4qxO45nbFRo2NnIMZxjFUY/VjPcNSZwJZlZpq0OfGaBYKB WjEsa9JlVG5m2AncK/UaEmpPWLnBqkskBWvFjhetLQ75U+FuQonGjlINWfZfMiuHViFx ds5JQXAIrL/gxFjsq9qK4Yzg7D15zjjuI1oy1ZdOmCv4H51blNMpGraQbWjdN8MOhkdu 9T2kKBWeHzM74awyDxNJtSGQe3P2TYOnB5uEa/zOfYQ10QlDjRiakVlInYak4Rgbc2qj DQrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pwKLvv8B; 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 f25-20020a05622a1a1900b004032845a061si1349632qtb.0.2023.10.20.07.19.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:19:10 -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=pwKLvv8B; 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 96E803882036 for ; Fri, 20 Oct 2023 14:18:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96E803882036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811497; 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=pwKLvv8Bt76Oe/PlqCX3RJ12C2wY7ZFVxNlSiAmFWXskttlrq7puF+ZOalFrKcmTB zqGfbBzgu7Cwo/1SYlQRvMn/uVlocSapeK6cSoUgbVSuiMYf4OWe53mNumFFqAn7u8 VK0Ft2XEwplngjO0q4+8fiElbRs5Okt9ZgUIF2kg= 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 7718F3856DE7; Fri, 20 Oct 2023 14:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7718F3856DE7 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 7718F3856DE7 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=1697811133; cv=none; b=JWkEvyNG3TTOuU+bHVqfc8XQDh4Ya5JeNeILLNjWO//EHr/dnJDdpqQoV1SLLfBBxwW8uoYdLm/Qm2HkgiXS0gaXrLKmsTj61tvpt2Fdh71oxTnC3f9krfsH779c1LG4kuqBWRo0vzzwiZf/mthVbfSzQM3ueQaBI52Da6m7BNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811133; c=relaxed/simple; bh=UVqQ3VYH2YZi75SlDBCPNmo7P0UtuVGM7vsj+lXPHGU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DKcRDU+SlPq8W8Bv/XmYdu7jbUwJ92iQtAHgnbeC/d2ZUGf6CJlwfsZ0L+BsAfmMHuf/zuK/Lm67f+jhiJoRSItazh6n/CX+Gk1BEUSS81nwFRmpmK24GsCDhx3vvgOLmHKcP+AU0NfodfqoYO+rt8XlMtO4+hn7AuvCoICjrG8= 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 39KEB9ih009070; Fri, 20 Oct 2023 14:12:09 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucbh4mh9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:09 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8AfJ017242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKY011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 20/33] c++: Implement __is_member_object_pointer built-in trait Date: Fri, 20 Oct 2023 06:53:39 -0700 Message-ID: <20231020135748.1846670-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: tY36FMUOjxLv62wL1ifb3Q6-tDW55XTM X-Proofpoint-GUID: tY36FMUOjxLv62wL1ifb3Q6-tDW55XTM 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 lowpriorityscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200117 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780284444761874306 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 Fri Oct 20 13:53: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: 156137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1088357vqb; Fri, 20 Oct 2023 07:15:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTGb5QxZfLdmJRjLX33sFj2MXIWsKfthihN2AaRIX52huO9UtvWBZUvosuZcTZi+dmF4d1 X-Received: by 2002:a05:6214:c45:b0:66d:3a89:813c with SMTP id r5-20020a0562140c4500b0066d3a89813cmr2282980qvj.53.1697811355734; Fri, 20 Oct 2023 07:15:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811355; cv=pass; d=google.com; s=arc-20160816; b=JY8aQn4EIphTYaooti/Fewzye5hPtTc8eMrjAnXoYUAVq9TPYTQ3Bl1OvbRcgt3IfP t68kfsK0ARKXAisN7/WEEqMqiLMzKDX4ynQwhmRtBJrlYKmyyLWOSUchwwukTUXIc2qC 5m+JpgovtmNPM/8s04S371/9+9cbGYs210XcMOF92BPemJ4iFS0QUjUraowShqNEmFEW uSVQO/M4cerrWQMYFm5L6DO8gySIG4wXVJNpr5+PEyUBd3vjKyzScFRvBrmeTctiuwK2 W79FuUyefOkXyXsDm4lslOqKr40MTxyai7q6iunPtgeDhbqIwx9wCdPNg3tDTCAIanC+ 2EUQ== 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=hH4hmP+Kw8Nb47ksrYKSYGpo3rATD47QrnhB/yIN6mIq540QF8SOHlyK6nw6NEMK1c 2FdB1TZg/w+ZCc6TYAUUo8rQYA/X72qE1dxjrg/lLUdR/rB1HXpGZUnUEkews+Mly3RZ j1O+E6ImSzVAUx4Wq+aE4UrxfqmeH9ber+bL4XcnA3SyDsefhrOD30hbjbo68fD8sqvu peFQO5t3KCMkAyqTaIsw44X17a7s18RvrDQWdSIWTrH8pzJYIWW1OX8szFDTpsYwWT6V wYadYc8PFydWBi4+8Q4xxPMvDCebTejlxDkOzUwktEVsjwwtD6YzvQLq8c4ynrlOHsnU P+1Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Voz/B8Uo"; 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 x14-20020a05620a258e00b0077419b27784si1393418qko.21.2023.10.20.07.15.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:15:55 -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="Voz/B8Uo"; 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 EAD383882175 for ; Fri, 20 Oct 2023 14:15:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAD383882175 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811322; 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=Voz/B8UoT1nHW9NY18phiYXnGQ5cVGUXcG/n5YdvuVICowNF987/+TQRhNWdfUfrV NUMM4X9r21d9asxbRSase6IYpvah2JVmD0IgYMbrFYggAKBHtTR6+jGRe7YY2n+mni EYxK3qLwtgA1Y/P1VjbfiRb06sDM6BRMrVV3M9mE= 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 B76DA385841C; Fri, 20 Oct 2023 14:12:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B76DA385841C 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 B76DA385841C 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=1697811125; cv=none; b=CLwNi+STroW41LKvzT8SzJi9l+Z/++wrjeNTa6AlQS/xt9AtDPxyTyX9PVsSQ2JBq97w9Z3XbictmbO1cRbadAVvdQowTC/9cNY5payfxoQqwA14gGkZ+TkLuw1Z9Hh5hvmnkXLCSPQo0jcmHgJnSNF7tj2/KmIzOpfjFLNglTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811125; c=relaxed/simple; bh=xgV0HhbeIOEZQRGv6DisRL5pSBe9b6hh3c7MgByCqhs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=RiZMylvFO5cfqpJ4A78iUd8wTNNtSuCDySe2XywDE8EGIEEztKbHFlIIYdQMcG8Sp8PTMOUdWP24CZUy9fp1q6gtjgQ0CTbctxFPmWmS4rZ0tmn4EgmR009Qa7UAFQ9NrtQiqe6vYXwqF0c6d7MAVmHUK/sBqqiyipSsJ+vg+cE= 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 39KE5Y18016876; Fri, 20 Oct 2023 14:12:04 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucwu44hn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8AKV023516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKZ011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 21/33] libstdc++: Optimize std::is_member_object_pointer compilation performance Date: Fri, 20 Oct 2023 06:53:40 -0700 Message-ID: <20231020135748.1846670-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: K3dlJ4_ZNZZ33wlbgigBvxA92dkuqEfe X-Proofpoint-ORIG-GUID: K3dlJ4_ZNZZ33wlbgigBvxA92dkuqEfe 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 suspectscore=0 phishscore=0 malwarescore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxlogscore=525 bulkscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002886817829020 X-GMAIL-MSGID: 1780284240224693480 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 Fri Oct 20 13:53: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: 156132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1087216vqb; Fri, 20 Oct 2023 07:14:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYTGIzB59O19yWl5w3/bTKxPxo2H4GZmmf1y865HOVLV1Gx6c03sADkM5UQuqUuXwMQwuI X-Received: by 2002:a05:620a:244b:b0:76f:6c6:f080 with SMTP id h11-20020a05620a244b00b0076f06c6f080mr2074016qkn.37.1697811271187; Fri, 20 Oct 2023 07:14:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811271; cv=pass; d=google.com; s=arc-20160816; b=u4etkXJ4pKWrZ8pa+4n+J/YymYZElzePVkwQIILp+CGirkaNBOSkhQA19U4x5UF/yq lp2pdtMJCJeLWqfgdQVF6uohwFvZ7weshYr59kdpmMAcp8wuC410i1FGghrM5DF8PdCV cqrc/A0H8i7mzAWFbK7stAy74Do9ZzaoImN9DkeFB813Ss9MgSErqno8+2uazOZIBczq fp3wYRvaPnVcff+x0tgwoJZg+oCaMinxxCT9MkcdyF32F4n+VaPud6nKFUFLJjHoN3o0 ylMs9gTvADp2P1k+u4su/7Rki7DWZfb6gutQqD8sRALR6xxuu64bJ03Md5GqdR9KxTem /zsw== 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=a5EsX/rwa7Wyi6lKEmco6GxaK3dMSXYD9zci+L9RvycQ1yy8NnQJTZEJVrrT5Dvgm0 /8evLH97xudC3tCTd2IL9adeJiTI1lxrmEgP1St+bFqqfI9Wnnfq0pyd1Zv84HJPS4M6 pJzj1boAufwAv7vWrHXqScpvzRRp5WLvAJZaIc3m292OD4hewRatnX8UeWgn+7e7cdkM 3RwF4hVmYNeoF3jXpZtRkrgJS8wrEL10RaVHJ0auZmRHZBcRA0x9HS2je9N/GwUM2fcT wqFovFslzu0qM5EJUvs18kdttyu3wO3E+gwCKkHInn1mO3KKIZNEIsmNIZABxthAB8ql gvcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SAHwbCF+; 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 a18-20020a05620a02f200b00767ba94e0b5si1365118qko.217.2023.10.20.07.14.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:14:31 -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=SAHwbCF+; 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 AF466385C414 for ; Fri, 20 Oct 2023 14:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF466385C414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811255; 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=SAHwbCF+4QunEn7e3SHS2zzIKaxP79Fg/OZxwuooluwBiPNpLis6NneKuHt6Erskh inhZNbiY0ULMxqh8o7SKfOFo2GdmrOmUKCBv/rdwwoQtGvP0Vkr3lZUQYPlJoFBB3Y OnweqbPedSgVK56/+buHT6zwFTcoCyUdcjrqzff8= 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 621A53858024; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 621A53858024 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 621A53858024 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=1697811128; cv=none; b=j6g+qYz5kW1sqLIYZWF87Oz36srgG746Yee9H8cCJSkUSpB2UpRgVGruJpnH7e0RIDYCGhSOTri2PDnxpOIrRyfNSxwVA4imZiccCqyFsZUx49O5sSHzxD6y21dQ0/gIk/vTrMju5p75Nd3OlqQD/QVrnVGMwhOlBy4c4Jjh9JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811128; c=relaxed/simple; bh=44mnHb56z+5WE1rdQYxHO5/55BkAITix9zVSDG7Bbdg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VDpXyXK2wO6O1Em0K0/yIp4fCCENKO6mwjDkrQhBR1VBzBFDW47dGJfXabkIcIqRCYdpM/RmW6nfN2l/7V3p6Da6Y/SsCmLb5rFi4ITLGGWDvN/3T3HuuIrnuQH+EwYOXycg6InqacRP1x5vMoDIq8d3imGvDLJdaya+YlJBn6U= 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 39KDr2cs002996; Fri, 20 Oct 2023 14:12:05 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucu1maxe-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8ATX005581 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKa011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 22/33] c++: Implement __is_reference built-in trait Date: Fri, 20 Oct 2023 06:53:41 -0700 Message-ID: <20231020135748.1846670-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: vnInh1TfjIauacNNEY8Y-Y8b0yRyqB2X X-Proofpoint-GUID: vnInh1TfjIauacNNEY8Y-Y8b0yRyqB2X 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=746 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1780284151154194753 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 Fri Oct 20 13:53: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: 156153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1091913vqb; Fri, 20 Oct 2023 07:21:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBSF0p3SHkhu9A5Y6OR0OpQAOeEAEuoEiTwtz0vlJq+ZfBlz1XJiVCvtPIBxY7zZU4xSZA X-Received: by 2002:a05:620a:2995:b0:76a:ece7:2071 with SMTP id r21-20020a05620a299500b0076aece72071mr2180592qkp.41.1697811662865; Fri, 20 Oct 2023 07:21:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811662; cv=pass; d=google.com; s=arc-20160816; b=MkiVE8jM0DIFn7g9S4KCL9n9Wfsg3N3J1dKZm45YK2YBRyKv7p7DEmX+3envctxH5l +lRDwH8dVyIaqbbvNmRr6Kvyf4eZSzd3t9jHBbhMVY+ZdjiMX8izonPklzBQUMNOTTYl f7cGRrD3/aAjDN5ZZe2qp4+yCqAK0y7FO4PAiZ4nEbXNCJvczMzsK0I1B3spfMtDAV49 Y/k1QxM7anh8axnIFq8XPCiApY00spj2g5V0JhsEefMSsdrXQZaWo4Fn1xnnb/a/HfpJ tRrInmpj+esreuWcDhC8vS9y+qOx+PEyDliQyuPuLMAcKTKm39gdt90U/9p7ELPAegH4 jUQQ== 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=SIGBJH+3REeV55UPqUk02qZC3O2JdSrRTaypPh4wMnw8gclnaHxaM88aLTd4sZa485 GQgaUcAqg4+R26fwo4riLw+EGzwudsYzJLzA3H7QzRe5MzIALMHcIwXfJwfJJMNbqIXd PnYzXxHxbExT6Jl/EyLn8L5AWaGyW5WnwGBNC/0PnLenPjsYM4fxLcOPf9KdmWfjiG9T OtyAZwolHWEvoublhH7zSEEzK5itq4XDJeQQU6rwnWRSJPnTEVYeeyNB1oVZ1U+NKjE5 Jk22nUToDBFSHxmIjG3h3T7L0ymn2W3XqkCR2bKvPNdGnOuyTrw6+wYd9ZhGXIkl/B3J HMkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=egyWJj5Q; 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 p23-20020a05620a113700b0076cddf8521bsi1323116qkk.148.2023.10.20.07.21.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:21:02 -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=egyWJj5Q; 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 BAA7E3882079 for ; Fri, 20 Oct 2023 14:20:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAA7E3882079 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811617; 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=egyWJj5QJKU6EyqhA7s1utO/VXGJfYdinqnhATvCI6QwV1oI5tTsbf1YwSrGCOzzM hynXdmycQsFlWsKqVlwj73vDCHU1lgRygD82IY3NB18X60s2u5If2viKg6b7Swhi6g 0/xYsJ958m+UzzOlMEaj0P6rW7Hk3ZSsAc3kiBfc= 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 C644D385DC3D; Fri, 20 Oct 2023 14:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C644D385DC3D 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 C644D385DC3D 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=1697811177; cv=none; b=icOpmBGZaUMglzuuvEQvkWeQUCiTyY/kkeYvcGu9zGGAJYgBtTd8YUSFj3T54symyE4ZFHnAHhMT6dwABqi2i7m8X0/Ui6CFfc0gTP8q5u7byqUuB79uYheyGkVJqN2QkLAmUoQBDsutYyNyyBWzxqpr/vnl2tV4KLNcptPTOs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811177; c=relaxed/simple; bh=XDazgY1fylMM2iWndx0Ss7j6lazHiqJTozl1aJbBepM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tkyErL2/ap5XSXhDNHOpFSmfrD23iBRvcL4NWCZauVWkLCgq8ZjfmFBRdZH/HQ0qdZwj0BNRpXDZg2Ey6IT4f0tAXu5uhj13YjFvLCzeVu5Nx6zc1949cQHMd810zzSBRIivsfZIgEyhoaS3yPwMYXbXcvK/fkyTW1UgJuo4dFQ= 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 39KE9RYC015956; Fri, 20 Oct 2023 14:12:53 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc2c4ub5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:53 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8AcW017241 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKb011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 23/33] libstdc++: Optimize std::is_reference compilation performance Date: Fri, 20 Oct 2023 06:53:42 -0700 Message-ID: <20231020135748.1846670-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: nEAUWrZPYkevxIBrHcdG5kta8XpKIHVe X-Proofpoint-ORIG-GUID: nEAUWrZPYkevxIBrHcdG5kta8XpKIHVe 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=711 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200117 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780284562265004000 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 Fri Oct 20 13:53: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: 156143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1089571vqb; Fri, 20 Oct 2023 07:17:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEybxdIp6LgLGT2uMU3BLRy29ri7wgZsxg04ylAfFqUfBmlro0tMik4G7br+bvnzWAlFUkb X-Received: by 2002:a05:620a:2688:b0:777:27a5:d1e with SMTP id c8-20020a05620a268800b0077727a50d1emr1853344qkp.41.1697811454266; Fri, 20 Oct 2023 07:17:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811454; cv=pass; d=google.com; s=arc-20160816; b=it9OSoTgff7koO5+RlI+x7uvYI4Ysxd6z0duZZgslxVh5yN8+CXJ93AoZH4yF9jTiR 5270IwstpvGMnw3zy7NUQ8/1LjwZ3IuJMyvB5g0IShC5SJJopv4+LhJENCzfo/DU8h2G Pylph8XjTuFyiEV+Au0wpEF8BsZCJjyowTOMyG58D8Kv1S+OnkgXli2n9hVaEzQ+j7gS Si4M14hVPQdxP/Xh34ffE77xMxsL42hcLqpEpuWZ/q4jzR78K7PjiEfVMOfV6kHkWoPG QlXwzhzVpA8nYeQT8sliMabFLLbeZeULsEoYSoEUsdcTadvZKWYvWZLt5I2FWCNoZ8mQ lzKA== 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=tMEJzcMpUGD2WWqH3gTn9BhJZ+HDt5jhMEFi4k79MVnAQLVpP3VFOnTKbzYnO5ZDXB nilie/bZgrH/6Pu3wFhNELoraiLJxO5i8AuYsQdE7uY9D6TP6Idham26Y8DwSRHndYnx rtxmzHcie3pjGIhnyrO28C9PyMJVDHMBD9XG6CIydVJ5aRUW0lyYEjC7INNZho4LO6cf I+HLwQ9cnRfSmuRR7djOKFyZn8F7OiZx+04sdD3lKCzxTz4Y6wSl8SdAXcV/OaLdrtxo gOmQLSMph95ter1Dlg9f6yZ3DwYWa0onyYN3QG1Xz7fNdWbvJslrCQz5SveRERMKS4Kk zAIw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hpOZPjQg; 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 l21-20020a05620a211500b00777731bf89csi1274445qkl.150.2023.10.20.07.17.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:17:34 -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=hpOZPjQg; 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 661CC3875DE1 for ; Fri, 20 Oct 2023 14:16:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 661CC3875DE1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811412; 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=hpOZPjQgi86hDjOzEZl+wQo8OlfGcsUamPrg50HXvDcuF29oaOdO0BuLYVsZmnZ+I VsWIH3DS8Hwcpp0AaSvHvW+56mBQZ9iDU7LYrDjhzh6MOyLb3L6DFU/WG5QQB9edmK 7ggq7JAGdyDOuAkaxmogoxpWqckEuiPu1h4QHI+o= 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 657163858028; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 657163858028 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 657163858028 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=1697811128; cv=none; b=MR69+fZaAfa6YRmgwtLVJX/9xZEcVmEwmMXppeSp9301rYrcr/su5BlaHMeC28wTdpM9NUbI44USWpSQnokO/l5gtgG+KVIE6avHKkM0aTp1bVsoilDahTpOoM4pXk9i/rpsGwa0I+tqkl53x/URLMHWAH+5IYv3Kyb+xOsHsvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811128; c=relaxed/simple; bh=mJ/BPkZ4Q1g1t1lvGmGKWZc/pKhsmt8XDUgZwN2ajRk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ws6f5cTMAtAvqLqbKOcbI3V7HI48yXw9hndo9SlqnVXWkaryKtGyinjhcuSglju3wvZX5R3dxY7CxJS9DULdhOQTTBfeAy0iUGnULco1hHr2CxsedYmk7EQtsC0bcLAO+2IPJ7gyiTaSQxqfxT90LI1sJVzXcH1p738NVHEmV5E= 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 39KDu4S7021523; Fri, 20 Oct 2023 14:12:05 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmhed-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8AT7023515 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKc011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:09 -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 v23 24/33] c++: Implement __is_function built-in trait Date: Fri, 20 Oct 2023 06:53:43 -0700 Message-ID: <20231020135748.1846670-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ehQ01kXzpdZuPuqFznjtmv9tLzK5x1fj X-Proofpoint-ORIG-GUID: ehQ01kXzpdZuPuqFznjtmv9tLzK5x1fj 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=984 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003586802560888 X-GMAIL-MSGID: 1780284343372362674 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 Fri Oct 20 13:53: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: 156123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1083637vqb; Fri, 20 Oct 2023 07:09:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEETHnGYrBQRiDb0ByvReAIsTCD5MT6rrnoTrxQ54ksapU0r0fo7CKJBqo/mgGy0ZuJXNye X-Received: by 2002:a05:622a:1910:b0:41c:bac1:6ad with SMTP id w16-20020a05622a191000b0041cbac106admr2070549qtc.18.1697810985623; Fri, 20 Oct 2023 07:09:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697810985; cv=pass; d=google.com; s=arc-20160816; b=baiPWS9MCxmxIGC+6/ifzWf+zmDsNgrdLQyaGorN+qkgJvb4NCrq34rJfn8Mv//Khq OLNQ6o+asBLF1v7KoQW4AsNv2cK/DKKI4AoBaCSZbEmVK8MAPQ8kZXNDPYHS9K1ReJQc pBPe9hDtRl5kPM4YDwb93WJSiqvIbUo6Tbi3mKeUIvKdBf62b7e8zTeCQxkqxKFZuWW8 bnklyVYKoJCT1c/Xlf6s6kqkvlnYphm9N+/IIQuvmDnaswMC7kwwI6nZvOhmVgVGs65O bjPQz6eLhEZ9FiBbFvwl2BUYCLC8AL4oysqL4dE3i1dBdcEUQuLFA9MkfP+XhDAS0CWl YNxw== 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=A4m3F3c0Q3UBcu5ZDDsQ8/u85crfsCPfqlmfxxzg/rQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=umcxWNKAUvaN+RoyzaV1nNLYOKx3E3WgQvN1YK2bR287n4fRYXnuk3zYDiGTCpr1Ku TXy1PJ4A1hzqnkkO6PlvgyQVKlS0xzriQPw7ACp/t4F8OlKtu57BVSo24i30QF14/4To M1vYWWywn9N5F270Ys4V6JbxSp0supmyCIYZjmVrcMqgsLXxS8W3WkOMaG8zu18SGo4J ToqLkq9ZS6dcbH23Qs/fLvFRjt7rHAaR77LoTXZCBwaiveX31bMmTf7mwg/zGeGWpJmt jT4eiXW6PGdCVvkwUjuIQHa7dvs00CF01o4kYQg1tArC0bhDBbB9yp0xyVAqmyggwkHS KpYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FUf1eCnx; 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 k10-20020a05622a03ca00b0041975795c17si1268818qtx.230.2023.10.20.07.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:09:45 -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=FUf1eCnx; 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 D3F2A385696B for ; Fri, 20 Oct 2023 14:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3F2A385696B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697810979; bh=A4m3F3c0Q3UBcu5ZDDsQ8/u85crfsCPfqlmfxxzg/rQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FUf1eCnxbsiu8fZA38+7pRoXlmmKPrWBd6mHll7mFcM5/ubrWlkk3uS15RdqxNyYM WPa/Ujp+Ty6rQxsqQqfVp63zdKBi0g/+sA0495T3AKe4bqkb6UtVICZwhsOytxMGPH 3/ATJs4uwmpr/4im2V2y98mPUDKTI+VU9V8Y7SNs= 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 4CC1D3858D39; Fri, 20 Oct 2023 14:08:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CC1D3858D39 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 4CC1D3858D39 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=1697810936; cv=none; b=OEgydeGzBkXfviEljcec7t7nTemkkeTGX0FyhCkebeFvmtYD9Ahd+QZ6rSXSXjn3qi0sSn74zynJsySg4Bw8eIwoqVpduFUzd8WZ1x8003v9KPLtCGVviXzQTpMpMA41BNTi3gVZ2OHGq0M8GZGk36LTDwe0tv5d9aQI2ORbN7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697810936; c=relaxed/simple; bh=yr+Nbqbr5kr1INtvUXOqjvsquVgC09enU46DfOATdv0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lpkkFWNZ2Y4etwkyIh/Ldn8jEPTu/ip8NaGklRJyVzHyt737zjkvTSVACMhjVatHDy4wuK8vZE0czFGEDzJ4UHgyFVnoqjwKRRCxA+TiMe3PoIEnyY7U78oHimwh86ONt+k/KmlUkxS+iesQcXJ5Q92CYPKsjEYhgQFuqypObkQ= 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 39KE8LSJ013903; Fri, 20 Oct 2023 14:08:54 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc2c4stb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:08:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8A2l032136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKd011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 25/33] libstdc++: Optimize std::is_function compilation performance Date: Fri, 20 Oct 2023 06:53:44 -0700 Message-ID: <20231020135748.1846670-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: dNhgfZ0uyLOdXFCxYpTNqn6L7oxLbGo6 X-Proofpoint-ORIG-GUID: dNhgfZ0uyLOdXFCxYpTNqn6L7oxLbGo6 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=535 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1780283852365292732 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. (is_const_v): Move on top of is_function_v as is_function_v now depends on is_const_v. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 39 ++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..1e561c8ea38 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,28 @@ 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_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_function_v = is_function<_Tp>::value; + inline constexpr bool is_const_v = true; +#endif + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) +template + 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 @@ -3303,16 +3330,6 @@ template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; #endif -#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) -template - inline constexpr bool is_const_v = __is_const(_Tp); -#else -template - inline constexpr bool is_const_v = false; -template - inline constexpr bool is_const_v = true; -#endif - #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) template inline constexpr bool is_volatile_v = __is_volatile(_Tp); From patchwork Fri Oct 20 13:53: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: 156142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1089309vqb; Fri, 20 Oct 2023 07:17:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm2UElNsGaVReLALVNw2tIY+SD95bCAR1afnpad+Khhs0VD4rmAOIeIURtt6A6EzpwzZaJ X-Received: by 2002:ae9:e201:0:b0:775:f1bd:f75e with SMTP id c1-20020ae9e201000000b00775f1bdf75emr2008495qkc.39.1697811432828; Fri, 20 Oct 2023 07:17:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811432; cv=pass; d=google.com; s=arc-20160816; b=LjJDtHeL8C2eiEet8c+9HDK4Q/c8T1sUuFoSWGW/5/dVt80mk10OfUfHa4IPsjBdOr Zecc6ciQSw739b3ABtzm1NiKYIm6ozFNXYj4jL3ZkgZFUUnQDngINYmFAtD2w4/kTELH syG/eyBGXPf37moluOrjr7XR+osYrAaZwZprPAT8F+zGwkoneKGHku0Y+WKuFDzA7ddz 09tvfmjRs3pmkbyalJ73o5gLCDdSdtHwK/Z6ev9m6+p0Z1JnnYl21ZtyeG7skM9jIRuq hGArqYgu0VL5M8onDJ9j5jD/NbWKa5vaUQNnBpaV8gumV888B/B6Mn0196Ppik93oKYV WLpg== 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=SSjEfPJgJhRS61LaphWmiuzkHqo62ZNhhNOL3XFLyCcvUL4mMIID1px5TXgDRSNVtc FzHxXVNWskackGi7iDSYn155yViNOho5RiqBkvF62zqGElcWx3Xj05PHmH6TWmrVhlEk RNpeQPDSTkHyLxgw6wJPFr3ibtxU7w0SnZZoe/1stMTHsHlKeph6K4zKltIB4z7/gpsp YbWzF5MoCjXyGT/EPPpYbYwe484umW7npVN3rwa+Ik7ty914Ldt+xf8qcuOKT9baGo4P cRZ9I5lUZZhhE77WOlNih3dAwzv/Co97msZ2CBjyuyHce+Nv3seC0vHlLebgrjzchBQZ Dgbg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yZI36fny; 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 az15-20020a05620a170f00b0076810d8f04esi1397243qkb.266.2023.10.20.07.17.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:17: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=yZI36fny; 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 2333D3884506 for ; Fri, 20 Oct 2023 14:16:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2333D3884506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811393; 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=yZI36fnygpdofMxq+lFAC8LnMkLmHCupLs2kNjzlJwDg+22ofMN13zYMHGCGnKRFO p5QbNEWlfvtISK8ZnueaWnSgEiRsu2kGSfdWYx9h1MapG1WHfBMihq4ep0HXpLCjGt 7rW5UIyyowdUYMF2XZm5r6tDtTLzO+tVt0UJkq1U= 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 3E94A3858000; Fri, 20 Oct 2023 14:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E94A3858000 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 3E94A3858000 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=1697811128; cv=none; b=GQkpbvpVPxgyHJv99HlMNlJaXRofkNqs67/J62ul7ebBhQihHuq6q2peD0eMNPZzsLvHaRhOkShlpLe+k6YpLSLM0VeRd0vJDlE17SpfUfj9MmzY9sIYObYXzFrpgL0ShbKIflewQX4bP911Fm0rN9YjSKQJOKnDq2lKvXtkj9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811128; c=relaxed/simple; bh=ESB1diD1iUYt/kFPVJWJ9UAIk7o3wFY2Qiy0kMZFkcU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=f0Usn4PBuAevvmjVu/jcTdJ8iV6r0Es8SaGiNGxlcxtCoijN0QWve7iW85aqb6V/usKzqFeMrrziLHvrn4J3DNSMhTB8nSzM0mhC1FMad9DmrJYBFbqu/5Nez1YHTqeb8Ls1vxJIWCi1raBsCRCbAyjZQRlFXlPoda9SfBxGojE= 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 39KE86kh005283; Fri, 20 Oct 2023 14:12:04 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucu1maxb-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8A5r015900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKe011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 26/33] c++: Implement __is_object built-in trait Date: Fri, 20 Oct 2023 06:53:45 -0700 Message-ID: <20231020135748.1846670-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dgq8olef6ahJKeuCkQrahN-MoHKxvrL- X-Proofpoint-GUID: dgq8olef6ahJKeuCkQrahN-MoHKxvrL- 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=799 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003280955820114 X-GMAIL-MSGID: 1780284320767433251 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 Fri Oct 20 13:53: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: 156151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1091405vqb; Fri, 20 Oct 2023 07:20:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOKuHsrFnIakh+AKFmF7ctKqS8fX2C3J1fLDTm8t55ZDmiI2eAozUKzJywWmmdTPg20o+5 X-Received: by 2002:a05:620a:28c6:b0:777:5120:d5ba with SMTP id l6-20020a05620a28c600b007775120d5bamr1678589qkp.8.1697811622401; Fri, 20 Oct 2023 07:20:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811622; cv=pass; d=google.com; s=arc-20160816; b=c0gPpZBveka/JavZ1seVo1hMzuYPA73BXdYMq4iO6Ub+lEVxmmzpl9ZT0UJl+MXan2 d9p2FrWGwQYfIu2Sl6m8K52OW5evRgmx+YptKPfOs9x5V1u1tTCfroYYoB6TWbC+uOL5 /Bs/eIP/Z4lZs7tcDnJgB/hal20MJw2pwydczH3lahPqKwfv/QdkjDJ6zaPeta1Uwcne 3fTbXdqDqL8oflKbzeF5hRhJEt4JIUj78MS1lFmuLgpc3GKQcNgc2K/qA3o28qZ31V/1 w4rjAQMZ5TZ3bt1hAOvaqaz1vcS/ofv9Om0l8PVp9haGDTIegtBpuIH3Y7KgHi+Hxb/+ OzQw== 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=wIJBJpTeWfekh0iF8pcpeXWFZVmVeNW9Z8LCdtvDiE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=dFZmFASgYO0HbOtmTDEWLAqvCpFbsl7XyNvJ3qF5vv1Yw1FCQhOFWslmiBFHRmdG8a 0jDByzNEQMtfC7hHKLXA+AnO3PhjyY9gIk7ORouJqEKg8y6I5kYMwEYj8PF7xWCrbcy5 eLUMpwYPamSd/sWT/ul71TBc2akjB4wyp2IDWbGKONWEyoDpcHGOyK2zqOTRSE2SlnFJ BcFkp81nZCkx/yEvR5mejRsUFQIRsuUzP1RKTEMIarPQMIki+T6UGoE4FentLVyq4XYo nvVAg8hK9ekDvgdJ3h1Tyu7pi8oCnvNlsf7AXV/Q1l1Zc+r2BdTjlXksIbEpp0mvhFWy nlKQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WWJxPuH6; 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 d13-20020a05620a240d00b0077435f2b668si1377569qkn.207.2023.10.20.07.20.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:20:22 -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=WWJxPuH6; 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 AA8543830B7D for ; Fri, 20 Oct 2023 14:19:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA8543830B7D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811580; bh=wIJBJpTeWfekh0iF8pcpeXWFZVmVeNW9Z8LCdtvDiE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WWJxPuH6rO99uQhuHTr9yfwpdMii7WVO3VDfyNaMnuZdCdc54hiRlXqk+iHehAocf 0Ra9oC30/5dTN9Ksh2qpmOVOKPxBMZfL+0Xafx+xtXvCe+oDaOlJOV+hMl/tiHrsqb 7g7YS5Il7hAf9L0UhmnRyxcNnH6CkZpxrPn5/aHw= 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 6618E3857344; Fri, 20 Oct 2023 14:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6618E3857344 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 6618E3857344 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=1697811132; cv=none; b=sxVbKunFUCwwL3jIXyhCOrCMkqx09+WRicbTTKbf3pgyBepTBb5OmyzJRqrpi4uYmn7sgogc7Bf4vC+2aK5d0x9vAeqT0W20tseBons1p9ZDKgyuJavYN5dXTiFNDdoxiolcU6Jz5qaBvNZl/1EeJcwJMhKX9U3+gV5gVpbsLQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811132; c=relaxed/simple; bh=8qxALrU8IQ9Py+th3NMo4Am++sznQbILepl/liOJcmA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uN6F54JV2VE3m8qe33EJ781V1jdeDSDcWrgVP0lWPhK40l4yXlO3+w3Py004iatpTnl3FESD2lg74gt0eTSgT+rU0NXqGUxxpv1gj1yQ7GDCMpCDtGq+w3kcoVHPCzJaxHHHIdo572Wddw9ykGA9zm7dEOcJKRRPvKQbQ1x5r/Y= 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 39KE5Obo030470; Fri, 20 Oct 2023 14:12:06 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucu1maxp-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8Awk023517 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKf011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 27/33] libstdc++: Optimize std::is_object compilation performance Date: Fri, 20 Oct 2023 06:53:46 -0700 Message-ID: <20231020135748.1846670-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: YMtwmAuRqUyANXDZNLUC_qeVOGhgXGKz X-Proofpoint-GUID: YMtwmAuRqUyANXDZNLUC_qeVOGhgXGKz 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=595 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003092679074239 X-GMAIL-MSGID: 1780284519560387026 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 1e561c8ea38..80ec0fd5475 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; @@ -3315,8 +3322,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 Fri Oct 20 13:53: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: 156140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1088885vqb; Fri, 20 Oct 2023 07:16:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYSAm1fBvPFhE3hwbYUou0gUW2887XUsI+iqdD28PIKq129oXUTSRMSmPRRqMQRXc3SI5P X-Received: by 2002:a05:620a:2d82:b0:76f:93e:4b30 with SMTP id tr2-20020a05620a2d8200b0076f093e4b30mr1598966qkn.67.1697811397451; Fri, 20 Oct 2023 07:16:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811397; cv=pass; d=google.com; s=arc-20160816; b=Bfkm8wIG2GqfyO/lS13Dn7tpp+fQo4U1Dj+n3MuI2kAhkYhBTrL5bUrmq06VNy8IN+ YfuSoBu7sK/JELDDj+S8mxZhZhWbBPt4hNkHEWhsENOBCu8AgcNFKW5LuWqNAqZ4himL 2Z4mbFtWGwJHvvtBi89dMgZPn6kveLnZZTIDgPQEN+Stv2ThPxC7ab7GUhhFPcbvDfOO 89C+q4B9ijEzSwK998654PWemoUpSPJGUR+s8nU60aU3++6iGwtL7yE/Qgl2zCCvRnfT Lxv+M2bhik+JfNxo81BoSfk8/09k87unUaadqMtNhlFjZhPgEiVH5try1xgsdgqJzKL9 fuyA== 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=wWf53LJuRlJdKn1yaEVDUQOLYIHNr/67fMBwx/rXQuJf3ZtRBru2QL0uND5b6rvkig DTIEDoleXTyF7xVWYFwYPH/Z89TJIW7Eap/IkzoQCFZSeJd/Mv89crZ7Rj/wAkICZNNO YJYwnCc4cn9jSASP6Nz7v8ccnq1y376zNU6nsrIcnsmf6uM2woLOOD0ZyK4fpN3c4+NR x5ouImkPQuhDzjipOyE8HIN3Gj2+DOQo4p9W1K4aevLPE09OCtBKu6LAJU4czJGaXp8K szVRtER75Qpx4KNgwD1BVsInHRSZZ0tyecWL/bqZrGfe2M7MLQuXGVvhaBYj28HAU+/p v31g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ejsgqpj7; 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 de32-20020a05620a372000b0076db12d14c2si1308040qkb.719.2023.10.20.07.16.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:16:37 -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=ejsgqpj7; 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 9935C3882174 for ; Fri, 20 Oct 2023 14:15:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9935C3882174 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811355; 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=ejsgqpj7BlZy/DYUjO9kRryQvi2x+B1w5iQPBeL4K3VKuJJsDVLxFZZb/CHkTMQHF HGJ5NbtjA0XVzVuadgEvv90nXSPCTT8tUw07G0aMQ7LCyRP37rbR5eFziIDOFXVbre okvmiIwymofQ9Rdg99RY7KpespGmjtbNx0nRg5bo= 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 3C4FC3858C20; Fri, 20 Oct 2023 14:12:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C4FC3858C20 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 3C4FC3858C20 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=1697811126; cv=none; b=MsbL/M+5ydCQE1TGZWeTSRCFKUflmg0LJfSCnD1wJq6oq5DKf0bE2RLV4S+whLDlIVcAmHDnCJ+jmHUnpsuNZmM4P8SbnIBdU4nH8ISVB7FtVUuy/IkDWTodlwmg/hC82ynOl0Snxu4rronlS/pTApx9weqIdCITyDF/OG95sSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811126; c=relaxed/simple; bh=C0qcTRTV/TeuNZg0DDmxzdyb6y2iW6hZf2AYLVPf/ps=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=goR8Qd/NHveeVPqG0nQQPECNGglRcstETXC+L14f0kDYwL6PPZ/4A4hrSZYhSILYXQyMPGTrqgridNmuXSJLHB7ecJC14WCNoDjG31rz/pWRWdBqDlc2M7cnpQUfrwO2Ew+JYUZ5U4qmJj2w6/GAD33j2fGfDlC58g/QyCo0lAE= 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 39KDvgHs001194; Fri, 20 Oct 2023 14:12:03 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucktcebk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8Apw014704 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKg011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 28/33] c++: Implement __remove_pointer built-in trait Date: Fri, 20 Oct 2023 06:53:47 -0700 Message-ID: <20231020135748.1846670-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: T9umjz0HVmTs66VHsQd21LlE66bvFF8b X-Proofpoint-GUID: T9umjz0HVmTs66VHsQd21LlE66bvFF8b 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1034 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=630 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1780284284065185135 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 Fri Oct 20 13:53: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: 156155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1093313vqb; Fri, 20 Oct 2023 07:22:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGN9vNmyefo0B4pEIMZh7GfEc4ae32tMcsR/tme/so5UmFGDhrkK/u2KLeNlXZz13bx9e4o X-Received: by 2002:a05:620a:4548:b0:76f:b00:4e66 with SMTP id u8-20020a05620a454800b0076f0b004e66mr7339730qkp.9.1697811779125; Fri, 20 Oct 2023 07:22:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811779; cv=pass; d=google.com; s=arc-20160816; b=OlkV09BVsd8j5TPIAGN64BgQLiVqZ1lZGP9JneJfi/pIQwM64AlraBF52ZvAhSziOq xUCtVWhlvfVDMjALdol+AH5iHzwePYHmo0pKvQufZxyt9clp5HJHD0G3UYbwd/LzT9+o 4zZCImAPz3983nfp0LpWNDNb3+ndlHc7TQVm1Z9NPXosWBTRNjpANHVmDZXqLvagRZNT vJMID5nAd6C794ZoZ122bs4l7v9uGXLv4K76pJagjwwRcWU8j2erUOiWGVvfNqsixgab dtaLo7f+o+zSvrN2d6uIFfDzggFHZosvCAzDvoD2DDDa3/MtycVXE/37CyxB/XWemOB0 QE9Q== 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=hECXcu79WLf2MLtjvffQ4wEBTaHh2qFTarxYAloqGD4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mT504GEE/dq80xvEYNVyX2g7K7TTwCeGzizPz1uzN8Rh8Uo+dOZcSZkJIAb+lo903f w+hcF/Ss4+fcEbeukZSTq/Du53GIAOiOh1sJH8aVks+/ASr+3bFnBuSfl2Noc3hZpWbt xWxO4ivTyWgSNMXMZmOM8/LPwNHgkYTefHwKFsZzRi2xWzOfCSM/p4p8nYw7pvMzKwAH ONUiHJdOrB0iF6A47/MT1DmwhCQTuCh2/I8GSPfEo0QNxe/22sozg12auAoLzxE6HKKI NSR46VM+f/FkFpxbWlSu/HSwEo9mkxUinMBcSBWfqIFrGq3ePFLoscVi3FAHQtNgz1MG 6FRQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c9bvmvxz; 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 c27-20020a05620a201b00b00770f2f6e190si1284490qka.509.2023.10.20.07.22.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:22:59 -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=c9bvmvxz; 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 D7C75385781F for ; Fri, 20 Oct 2023 14:22:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7C75385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811778; bh=hECXcu79WLf2MLtjvffQ4wEBTaHh2qFTarxYAloqGD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=c9bvmvxzrqzT/Bvj+EimboBBv7BMfmV2zMmrotjg3mYXrqPlP5DT2cmoIOIr5MNXh mO480Q9xcdg5muCRJ9aMkX0lqkndqpuGDT+bqUWtbZiC5Zbi4gjMDBK9QvttMePqFJ a5T0dvIvvRDqw0cCbuGTs5X1Ab8b7z5rHYXbHaqE= 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 9E3E7385DC13; Fri, 20 Oct 2023 14:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E3E7385DC13 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 9E3E7385DC13 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=1697811176; cv=none; b=I/e8ctbYl6cGC7yz0LBaYvzly5Jo5wk4e3RswD4SsgrFqRD8IKFnPvdt5B4n/ih9bY4zYAuRpAF5u4eqR39jZBhBGdB/kVJuIznF5j7JswOSqJPwD+wdirn0eop3VrSCs7dSLjCQWbgeZFQUtwycE3RKi8/5HgAHNYG4jHG2WIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811176; c=relaxed/simple; bh=SuGRHw4g88ver8n1MtBun+9vWyPVhE/lHa1f7Tviwp4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gdXC0jdRQ4Fcbjay+goK0Nyw4gCgBLc2YtlJ+k5PghpeiW8qX7UTY+iBQRJJW/qhMPMSbhqHbWc5dLk7wei/ua+3L+hiqZ3w9CZBhB1OxX4KscAe8bG01ivJqpB6Yc6eaURoE5t673quDcj1VGjO/YOG2r5UtJPDl6zGVQOSTwM= 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 39KEA1UO021795; Fri, 20 Oct 2023 14:12:54 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc8gmsg6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8AxE017243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08:10 -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 39KDvqKh011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 29/33] libstdc++: Optimize std::remove_pointer compilation performance Date: Fri, 20 Oct 2023 06:53:48 -0700 Message-ID: <20231020135748.1846670-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: te2O_5PkgejgRjivEV5WtUKnJweDZ3DB X-Proofpoint-ORIG-GUID: te2O_5PkgejgRjivEV5WtUKnJweDZ3DB 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=594 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003274130707210 X-GMAIL-MSGID: 1780284684511032683 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 80ec0fd5475..0641ecfdf2b 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 Fri Oct 20 13:53: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: 156134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1087619vqb; Fri, 20 Oct 2023 07:15:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF+FI0aaE2FRQKEhsmferqcvsW430Ay6yeY9+BzC+rwGm5rhVtpEC+B1bGStlTCRgxXM32 X-Received: by 2002:a05:622a:4c6:b0:41c:c6b4:8c0d with SMTP id q6-20020a05622a04c600b0041cc6b48c0dmr1970269qtx.9.1697811304072; Fri, 20 Oct 2023 07:15:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811304; cv=pass; d=google.com; s=arc-20160816; b=pWalNl9E7eYjurBC0tZxtq2HCewCmr3WK58UZQSEFEdTffreEeFat8Jz1xIR9kkpa4 XWvIfZ+0RTrPvQwoCMEibpqdqpohSFOPIh8h8SLsjRSgACTwoE/U7JNgsdBxOPKPPCPe LsjOygouylef8rQkBvES9OJfJFt3nlr/QgcJDL+ZLbKJ5u9AhFR7Hp8iGKmID7HFPCZ5 ejgp3hFJTpBkgg+zNWZNiM82DxuClpecIj5lCuxZMM0IfcebkFlIEePK4SNH5F6cpK61 gBbZn6aIR46w5p2ae6u5GGCGlsW2b7pUfYGfU8I7fJANvFaNIWD9DgM6qlNGYUXyTov/ e1GA== 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=tNabpj3P83zrebMGFtpxbH7TFIDpXhQjxwMXQGgsrB51/Vg2FJfsw8D59oQ6srnBsa q5O3JN7oQXIoGFnWwKcpw5ol/COiZWdVOArpVkiAP8HC2OJpqJG7z2IoaA5S8d/TcgYX FCWrEkdAwElQjAyK/358ZbBhV0v4eMfIkfW0uD3hY1NvqtHahtGvRJ/npsFDIFy4gtA9 PEe68ZEYZc5L4kuCW/HmWKyP/A4a3jPhEi50IRGZRpaDrDYQklz3sF8mXif1/Gj/3KUp U3w8mOYOjXPFnxpljYXFGlPje/r2/qforX4txVO+7WQ+Quni1UuIpwTn6MmG6Aqz0wHV mN0g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TD3naiNb; 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 q6-20020a05622a04c600b0040ff58d67dfsi1302422qtx.599.2023.10.20.07.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:15: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=TD3naiNb; 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 183A838515D6 for ; Fri, 20 Oct 2023 14:14:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183A838515D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811281; 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=TD3naiNbFl6vYCk4HKH1/3XCC7OnfsYuMWoia5I/p1DcS0D7IrQUBAQAq4YTtYWai MX9BxzhGRhAabBtVHWnb4Fq46wcPSqIeI5uJYNqUfBOYsx4sLaASYUJPKpuz5bktSO SFCo5A8rDrRD3iNHdhxIKhEkRXFu6dVmAEYR5aK4= 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 CF2ED3858C74; Fri, 20 Oct 2023 14:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF2ED3858C74 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 CF2ED3858C74 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=1697811125; cv=none; b=Ph/qNikUtHHgYlDpL5gch85LtvfXvJf9wlxJUfitOekQk0dK18PF5dM7r4a4DLFMQEdDlndkwozFJwA8oZGB2UwuhmUldXYOovujAzNvxdaWFkpsOoj29/sH2RzdMYxajtX9N1R3ZRc3P+ddi6CtEbHsE2XO86RU43qBTL73TqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811125; c=relaxed/simple; bh=nUzdWNlhWch0UgIpHjoLMy3laHHmMznmZ+d5mPW7o04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iSV1TrKc5qP49VeBlGetLcgFTJFz4LW+iQqLbGElrigzNVOmFx+3JbyPfyhuzOZKHnxJl2++i4uxG9ylYe3s8rMiuVS1zelD+mF17E283Y38umIJdfUm0OiFMSZNirdNQmg3oEUa0ilLuPDoJSr/rIdQF2z2LfpLiKAnzpCo2F8= 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 39KE65fw010661; Fri, 20 Oct 2023 14:12:03 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc5cmhe9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8BNr014705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08: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 39KDvqKi011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08:10 -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 v23 30/33] c++: Implement __is_pointer built-in trait Date: Fri, 20 Oct 2023 06:53:49 -0700 Message-ID: <20231020135748.1846670-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: rfN47FkW0q_8gj67MQFohOVttxv_Lfmu X-Proofpoint-ORIG-GUID: rfN47FkW0q_8gj67MQFohOVttxv_Lfmu 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=730 priorityscore=1501 adultscore=0 impostorscore=0 clxscore=1034 spamscore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677497968726301 X-GMAIL-MSGID: 1780284186238527255 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 Fri Oct 20 13:53: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: 156150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1091311vqb; Fri, 20 Oct 2023 07:20:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJCTBKeqzoDCWWGyT0ZLib7UuR3PhmPtHdlsDw4HAHa4JQj/r9vTVwL2nAQ/kJwCSZJ7kE X-Received: by 2002:ac8:5892:0:b0:403:a662:a3c1 with SMTP id t18-20020ac85892000000b00403a662a3c1mr7480859qta.29.1697811615435; Fri, 20 Oct 2023 07:20:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811615; cv=pass; d=google.com; s=arc-20160816; b=a+ShcqkEv+IxLMozG7D+fR7UC80l75nQdTy6wsilwwl/n/od8XKIurGDKyWpAEXayl sHUHflvZ3XyytlsqcsD/49lVLsDO3KD+BndR8cx6Hb8PdaYe0rUu+nohtX7JJTrOD7bL FrCXrW9IRzXHcEAKuLrTLCTeHk1THqY+xAzU3rXo+NeY+WEJPGZnYE+1D9jkf7DNMZbT y4TSLbK0gYSSIa1N2hgEfHdYZ1Zsvpvnd17aK0ff043gSg3iDGExHoEmggKYrO8+OmNb zVtBdI9VcXuf7cskWwFaPgRlSBx7fP//0sPTkoEbQFISkHsQzvwCLYuT+whqlTxJmsSu 0U2A== 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=IgHeUECRUGUHeB2FDzyiPvx3wY2cqzwmMqAoULoyiO0=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=fMGKSMNgl0EVYRzJpS9YiOviKrsu/rArihWowZWTlkzsI6vOAHFJmfWyU+yTvWtwm5 cBM4Sh9f41s68VfBuSwofcqQkbm/kVJziR/XOAvHzrJbanhp+4kTm4EeK7MwbC38VWxK DijLUME+JkGST+8G5SqCm1sJw9kZyONxfvSsx0DY7GHddPXhqKTdG/TQl0qoKS1oGKJY Bf7JdQapzMsGlB5JeS98dLNvwhhMjgAMm9SRSKo7OWG2CaaaORDZgZcIMIAlXNl4cSD9 jIZ0rHUfEoM+K2Y8YPwtX4lYGd7Y4BJ8K/4QQnL1RM6S12TR+wPBABNKp9Y9MI+2GCZE cO2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=szzSMtXZ; 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 z6-20020ac87f86000000b00419785380fesi1358234qtj.508.2023.10.20.07.20.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:20:15 -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=szzSMtXZ; 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 DDD1D3831E23 for ; Fri, 20 Oct 2023 14:19:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDD1D3831E23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811572; bh=IgHeUECRUGUHeB2FDzyiPvx3wY2cqzwmMqAoULoyiO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=szzSMtXZjtKjRmbCug8hIvhn8yJmR0Izrt/0QFsb0+nDI43mrIPXqXGlpXJYiLwF4 48Wc57s3dDGFs7GrduUl7IBm8kRILgetCiS47FBtjLFtNiXnTMhniZPw6ZD+yWahYJ t0gtzq3mwpO76BNfXdIn0VoOPxWf/sChBl87dekc= 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 9446A3858002; Fri, 20 Oct 2023 14:12:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9446A3858002 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 9446A3858002 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=1697811133; cv=none; b=uDMGOi/CCG3GdYLu2vsSAi5RHnVlTsa/E7M6ABTNEwGQeFLH/dSMkOnIPWQBN6uUdOBMgjPLuq+98/zVQop6G6q3rCUA3Gn/XkCP5UDEg+J2i8O+UYoTnmJZc/vBoMjfPPJ4rpJ1NoWKq6fQMPZ7MoDt8aeuIdkQ09yw2ylR9jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811133; c=relaxed/simple; bh=flojPnssMLdhqKNQt8Rjq8Bo6meU60DkvOWrLGwYZDY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Pt5Nn2dpBTTKD1Taj5q78MSoI4LU1OinDeOfT2N4tmiWbkR9/HiT0+OojAN0v9kSlntBpAGlEBSBZ6H4s4jHxAMC204V6ozCnL961bUqr/Cf7iUKIJFVnxFXpz+GzFcIdVuXFpWYNNSgwdh4EHoT5wSsr3NsbaC51vzSTAGXF4U= 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 39KE0C3B002552; Fri, 20 Oct 2023 14:12:07 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucwu44hk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:07 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8Bcd014706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08: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 39KDvqKj011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08: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 , Jonathan Wakely Subject: [PATCH v23 31/33] libstdc++: Optimize std::is_pointer compilation performance Date: Fri, 20 Oct 2023 06:53:50 -0700 Message-ID: <20231020135748.1846670-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: NjrNP2I7_IURQiLZbr01BD-hDK3dJSkW X-Proofpoint-ORIG-GUID: NjrNP2I7_IURQiLZbr01BD-hDK3dJSkW 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 suspectscore=0 phishscore=0 malwarescore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxlogscore=411 bulkscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200116 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002690195991879 X-GMAIL-MSGID: 1780284512258106977 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 0641ecfdf2b..75a94cb8d7e 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 From patchwork Fri Oct 20 13:53: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: 156154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1092620vqb; Fri, 20 Oct 2023 07:22:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEahtq4TSEedNB3mbobWrmpeWU6prgCLHhKmGvsdINgiydqZMJ8zhn1EgvSIModdF+ZBudL X-Received: by 2002:ac8:7dd1:0:b0:418:7ec:7570 with SMTP id c17-20020ac87dd1000000b0041807ec7570mr1852710qte.64.1697811721298; Fri, 20 Oct 2023 07:22:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811721; cv=pass; d=google.com; s=arc-20160816; b=XCOnaQA1YKfU+d82QMNMgvLTcKBM204em278U8pWIVSht5Ft2jYZSAsPxbB41CuX20 uibu/REj0pSnU9ZNQRdDQ9KXK7X4sb+K+8MJsV06rHVCVsMqNDeYbt8Zs5mRtj3uhM9A Tk2keUmDLORUmbjHEdeiZwNXEfCTbxD6hQZgD51il3blhoYW0nx/nJ4mfzi4RS6flCSd nY3izXY6fUJiBLWBu++XvDN0oA4hElB9r2VYNkMyAuzvtGt/ziJ9h+fg5gSSo6EG0mT9 QzGZZyxbkhRLVUEAgeMlrAs7EWX3WLOmSQEAouP+N3XH4dl17se83Bg1y28RRR8jxjEf LlHg== 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=eFLL9kf9baBgO1hT1kebpByY1ZJzbWoaCLZie035yUs=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TO8SzEknBNMEyTGAvZDrVDu4EUzIno+2Hu6vu/OOsJAxyUKKnmDyJ8xJ2KAO8zD1Uc 9As9/41Ql+BUCL45qu4unMUA2a70E05WAo4WudU8sQY19OLT61mqCCgKdnrrlUCuhWus 5TQjHLKx5TEZzWcq4FsBvpJyzXccatUEbTx6udOtMZ5RA988r6f60Lvi93uLfQ/x0HY2 zrx7Bvd4ZT/maHxqaCrP/whhHHRiImT3O4Qww9i522fH/gU/FKaeIk8wVUX0Wv1wRcAU P/PQ0RiBhju0ilV9qVxORrUDguqeuuNz4l2YF70lYMO8Q1/JlKEI5XvxgRDQViKUsBUf VnDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RiuKJz3f; 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 o9-20020a05622a138900b00417d78906c7si1399244qtk.292.2023.10.20.07.22.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:22:01 -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=RiuKJz3f; 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 C9AA33858281 for ; Fri, 20 Oct 2023 14:22:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9AA33858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811720; bh=eFLL9kf9baBgO1hT1kebpByY1ZJzbWoaCLZie035yUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RiuKJz3fqLA/pxBkich49/I4IB35FGCqOh0FmuzGbCPSA3RYrsUEdeYUHmNMGQYri wQOBBiX2BfmSyzP6j/rkU8UvyoZDCP/Top1NyIAQi9j58eldjq5XhMR2Iqp66eRNxO QnKfssngp9B+4lK8ABNb59/9pNwBPKGv5Y8vcaMI= 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 5A84A3858D35; Fri, 20 Oct 2023 14:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A84A3858D35 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 5A84A3858D35 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=1697811136; cv=none; b=qYyRa+xQfBNdIwDBjNVFS8JgaqIZbILKOAxZ/ATpUFmjpeNVu65TvCrzWC04YY1lypOfb2qDJJZaO9diZeM7Y/EXAcsox8jSATxx1UGB7lU5ukFv9iWaOl6ICpVQMFJ+aF7bqZUQ6IpmUSviDpEgiyERkDzpl4OObtPeVqOZJiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811136; c=relaxed/simple; bh=mkZ2sKtwtoSUC8fkGeYUTY8ia782imflAE4LSksYnfY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UQypLrW0JoU5y63rN6UEpr05E3xMqSgztSiuZoFXl6JDnsfbws7xlzLv/lT0DjWCSmT7JfTEvPDVQKBlWuj63Yqawo7gq0b+ZEG2avPkCjZve5sD7KjABmhPS8Q+EBl6FX7w63hGQhPERs6DTIxlYrYQqDQDR6R5YiublYCfo9s= 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 39KE9Xwe016115; Fri, 20 Oct 2023 14:12:09 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tuc2c4tuu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:08 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8Bgo005582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08: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 39KDvqKk011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08: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 v23 32/33] c++: Implement __is_invocable built-in trait Date: Fri, 20 Oct 2023 06:53:51 -0700 Message-ID: <20231020135748.1846670-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: EASLFZ4wDBqkPoupDRWPe4FhJwZF5qxl X-Proofpoint-ORIG-GUID: EASLFZ4wDBqkPoupDRWPe4FhJwZF5qxl 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 adultscore=0 clxscore=1034 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200117 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1780284623556278591 X-GMAIL-MSGID: 1780284623556278591 This patch implements built-in trait for std::is_invocable. gcc/cp/ChangeLog: * cp-trait.def: Define __is_invocable. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_INVOCABLE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (is_invocable_p): New function. * method.h: New file to export build_trait_object in method.cc. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_invocable. * g++.dg/ext/is_invocable1.C: New test. * g++.dg/ext/is_invocable2.C: New test. * g++.dg/ext/is_invocable3.C: New test. * g++.dg/ext/is_invocable4.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 6 + gcc/cp/cp-trait.def | 1 + gcc/cp/method.h | 28 ++ gcc/cp/semantics.cc | 135 +++++++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_invocable1.C | 337 +++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_invocable2.C | 139 ++++++++++ gcc/testsuite/g++.dg/ext/is_invocable3.C | 51 ++++ gcc/testsuite/g++.dg/ext/is_invocable4.C | 33 +++ 9 files changed, 733 insertions(+) create mode 100644 gcc/cp/method.h create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable1.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable2.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable3.C create mode 100644 gcc/testsuite/g++.dg/ext/is_invocable4.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 9fce36e12d1..29bf548d30a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3754,6 +3754,12 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FUNCTION: inform (loc, " %qT is not a function", t1); break; + case CPTK_IS_INVOCABLE: + if (!t2) + inform (loc, " %qT is not invocable", t1); + else + inform (loc, " %qT is not invocable by %qE", t1, t2); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 05514a51c21..b8b7608c122 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -71,6 +71,7 @@ DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) +DEFTRAIT_EXPR (IS_INVOCABLE, "__is_invocable", -1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/method.h b/gcc/cp/method.h new file mode 100644 index 00000000000..1aec8ec5cfd --- /dev/null +++ b/gcc/cp/method.h @@ -0,0 +1,28 @@ +/* Functions exported by method.cc. + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_CP_METHOD_H +#define GCC_CP_METHOD_H 1 + +#include "tree.h" + +/* In method.cc */ +extern tree build_trait_object (tree type); + +#endif /* GCC_CP_METHOD_H */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7cccbae5287..cc2e400531a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -45,6 +45,10 @@ along with GCC; see the file COPYING3. If not see #include "gomp-constants.h" #include "predict.h" #include "memmodel.h" +#include "method.h" + +#include "print-tree.h" +#include "tree-pretty-print.h" /* There routines provide a modular interface to perform many parsing operations. They may therefore be used during actual parsing, or @@ -11714,6 +11718,133 @@ classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) return saw_copy; } +/* Return true if FN_TYPE is invocable with the given ARG_TYPES. */ + +static bool +is_invocable_p (tree fn_type, tree arg_types) +{ + /* ARG_TYPES must be a TREE_VEC. */ + gcc_assert (TREE_CODE (arg_types) == TREE_VEC); + + /* Access check is required to determine if the given is invocable. */ + deferring_access_check_sentinel acs (dk_no_deferred); + + /* std::is_invocable is an unevaluated context. */ + cp_unevaluated cp_uneval_guard; + + bool is_ptrdatamem; + bool is_ptrmemfunc; + if (TREE_CODE (fn_type) == REFERENCE_TYPE) + { + tree deref_fn_type = TREE_TYPE (fn_type); + is_ptrdatamem = TYPE_PTRDATAMEM_P (deref_fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (deref_fn_type); + + /* Dereference fn_type if it is a pointer to member. */ + if (is_ptrdatamem || is_ptrmemfunc) + fn_type = deref_fn_type; + } + else + { + is_ptrdatamem = TYPE_PTRDATAMEM_P (fn_type); + is_ptrmemfunc = TYPE_PTRMEMFUNC_P (fn_type); + } + + if (is_ptrdatamem && TREE_VEC_LENGTH (arg_types) != 1) + /* A pointer to data member with non-one argument is not invocable. */ + return false; + + if (is_ptrmemfunc && TREE_VEC_LENGTH (arg_types) == 0) + /* A pointer to member function with no arguments is not invocable. */ + return false; + + /* Construct an expression of a pointer to member. */ + tree datum; + if (is_ptrdatamem || is_ptrmemfunc) + { + tree datum_type = TREE_VEC_ELT (arg_types, 0); + + /* Dereference datum. */ + if (CLASS_TYPE_P (datum_type)) + { + bool is_refwrap = false; + + tree datum_decl = TYPE_NAME (TYPE_MAIN_VARIANT (datum_type)); + if (decl_in_std_namespace_p (datum_decl)) + { + tree name = DECL_NAME (datum_decl); + if (name && (id_equal (name, "reference_wrapper"))) + { + /* Handle std::reference_wrapper. */ + is_refwrap = true; + datum_type = cp_build_reference_type (datum_type, false); + } + } + + datum = build_trait_object (datum_type); + + /* If datum_type was not std::reference_wrapper, check if it has + operator*() overload. If datum_type was std::reference_wrapper, + avoid dereferencing the datum twice. */ + if (!is_refwrap) + if (get_class_binding (datum_type, get_identifier ("operator*"))) + /* Handle operator*(). */ + datum = build_x_indirect_ref (UNKNOWN_LOCATION, datum, + RO_UNARY_STAR, NULL_TREE, + tf_none); + } + else if (POINTER_TYPE_P (datum_type)) + datum = build_trait_object (TREE_TYPE (datum_type)); + else + datum = build_trait_object (datum_type); + } + + /* Build a function expression. */ + tree fn; + if (is_ptrdatamem) + fn = build_m_component_ref (datum, build_trait_object (fn_type), tf_none); + else if (is_ptrmemfunc) + fn = build_trait_object (TYPE_PTRMEMFUNC_FN_TYPE (fn_type)); + else + fn = build_trait_object (fn_type); + + /* Construct arguments to the function and an expression of a call. */ + if (!is_ptrdatamem) + { + releasing_vec args; + + if (is_ptrmemfunc) + { + /* A pointer to member function is internally converted to a pointer + to function that takes a pointer to the dereferenced datum type + as its first argument and original arguments afterward. If the + function is a const member function, the first argument also + requires a const datum pointer and vice-versa. */ + + tree datum_type = TREE_TYPE (datum); + if (TYPE_REF_P (datum_type)) + datum_type = TREE_TYPE (datum_type); + + datum = build_trait_object (build_pointer_type (datum_type)); + vec_safe_push (args, datum); + } + + for (int i = is_ptrmemfunc ? 1 : 0; i < TREE_VEC_LENGTH (arg_types); ++i) + { + tree arg_type = TREE_VEC_ELT (arg_types, i); + tree arg = build_trait_object (arg_type); + vec_safe_push (args, arg); + } + + fn = finish_call_expr (fn, &args, false, false, tf_none); + } + + if (error_operand_p (fn)) + return false; + + return true; +} + /* Return true if DERIVED is pointer interconvertible base of BASE. */ static bool @@ -12181,6 +12312,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FUNCTION: return type_code1 == FUNCTION_TYPE; + case CPTK_IS_INVOCABLE: + return is_invocable_p (type1, type2); + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12390,6 +12524,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CONVERTIBLE: + case CPTK_IS_INVOCABLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b1430e9bd8b..3a9bda1ee03 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -92,6 +92,9 @@ #if !__has_builtin (__is_function) # error "__has_builtin (__is_function) failed" #endif +#if !__has_builtin (__is_invocable) +# error "__has_builtin (__is_invocable) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_invocable1.C b/gcc/testsuite/g++.dg/ext/is_invocable1.C new file mode 100644 index 00000000000..2fd3906b571 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable1.C @@ -0,0 +1,337 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +using func_type_v0 = void(*)(); + +SA( __is_invocable( func_type_v0 ) ); +SA( ! __is_invocable( func_type_v0, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( func_type_i0 ) ); +SA( ! __is_invocable( func_type_i0, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( func_type_l0 ) ); +SA( ! __is_invocable( func_type_l0(int) ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( func_type_ii ) ); +SA( __is_invocable( func_type_ii, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( func_type_il ) ); +SA( ! __is_invocable( func_type_il, int ) ); +SA( __is_invocable( func_type_il, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( func_type_ir ) ); +SA( ! __is_invocable( func_type_ir, int& ) ); +SA( __is_invocable( func_type_ir, int ) ); +SA( __is_invocable( func_type_ir, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( mem_type_i ) ); +SA( ! __is_invocable( mem_type_i, int ) ); +SA( ! __is_invocable( mem_type_i, int* ) ); +SA( ! __is_invocable( mem_type_i, int& ) ); +SA( ! __is_invocable( mem_type_i, int&& ) ); +SA( __is_invocable( mem_type_i, A ) ); +SA( __is_invocable( mem_type_i, A* ) ); +SA( __is_invocable( mem_type_i, A& ) ); +SA( __is_invocable( mem_type_i, A&& ) ); +SA( __is_invocable( mem_type_i, const A& ) ); +SA( ! __is_invocable( mem_type_i, A&, int ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( memfun_type_i ) ); +SA( ! __is_invocable( memfun_type_i, int ) ); +SA( ! __is_invocable( memfun_type_i, int* ) ); +SA( ! __is_invocable( memfun_type_i, int& ) ); +SA( ! __is_invocable( memfun_type_i, int&& ) ); +SA( __is_invocable( memfun_type_i, A ) ); +SA( __is_invocable( memfun_type_i, A* ) ); +SA( __is_invocable( memfun_type_i, A& ) ); +SA( __is_invocable( memfun_type_i, A&& ) ); +SA( ! __is_invocable( memfun_type_i, const A& ) ); +SA( ! __is_invocable( memfun_type_i, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( memfun_type_ic ) ); +SA( ! __is_invocable( memfun_type_ic, int ) ); +SA( ! __is_invocable( memfun_type_ic, int& ) ); +SA( __is_invocable( memfun_type_ic, A& ) ); +SA( __is_invocable( memfun_type_ic, A* ) ); +SA( ! __is_invocable( memfun_type_ic, A&, int ) ); +SA( ! __is_invocable( memfun_type_ic, A*, int& ) ); +SA( __is_invocable( memfun_type_ic, const A& ) ); +SA( __is_invocable( memfun_type_ic, const A* ) ); +SA( ! __is_invocable( memfun_type_ic, const A&, int& ) ); +SA( ! __is_invocable( memfun_type_ic, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( memfun_type_iic ) ); +SA( ! __is_invocable( memfun_type_iic, int ) ); +SA( ! __is_invocable( memfun_type_iic, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A&, int ) ); +SA( __is_invocable( memfun_type_iic, A&, int& ) ); +SA( ! __is_invocable( memfun_type_iic, A*, int ) ); +SA( __is_invocable( memfun_type_iic, A*, int& ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int ) ); +SA( ! __is_invocable( memfun_type_iic, const A&, int&, int ) ); +SA( __is_invocable( memfun_type_iic, const A&, int& ) ); +SA( __is_invocable( memfun_type_iic, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( B ) ); +SA( __is_invocable( B& ) ); +SA( __is_invocable( B&& ) ); +SA( ! __is_invocable( B* ) ); +SA( __is_invocable( CB ) ); +SA( __is_invocable( CB& ) ); +SA( ! __is_invocable( CB* ) ); + +SA( __is_invocable( B, int ) ); +SA( __is_invocable( B&, int ) ); +SA( __is_invocable( B&&, int ) ); +SA( ! __is_invocable( B*, int ) ); +SA( ! __is_invocable( CB, int ) ); +SA( ! __is_invocable( CB&, int ) ); +SA( ! __is_invocable( CB*, int ) ); + +SA( ! __is_invocable( B, int, int ) ); +SA( ! __is_invocable( B&, int, int ) ); +SA( ! __is_invocable( B&&, int, int ) ); +SA( ! __is_invocable( B*, int, int ) ); +SA( ! __is_invocable( CB, int, int ) ); +SA( ! __is_invocable( CB&, int, int ) ); +SA( ! __is_invocable( CB*, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( C ) ); +SA( ! __is_invocable( C& ) ); +SA( ! __is_invocable( C&& ) ); +SA( ! __is_invocable( C* ) ); +SA( ! __is_invocable( CC ) ); +SA( ! __is_invocable( CC& ) ); +SA( ! __is_invocable( CC* ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( D ) ); + +struct E { void v(); }; +using CE = const E; + +SA( ! __is_invocable( E ) ); +SA( ! __is_invocable( void (E::*)() ) ); +SA( __is_invocable( void (E::*)(), E ) ); +SA( __is_invocable( void (E::*)(), E* ) ); +SA( ! __is_invocable( void (E::*)(), CE ) ); + +struct F : E {}; +using CF = const F; + +SA( ! __is_invocable( F ) ); +SA( __is_invocable( void (E::*)(), F ) ); +SA( __is_invocable( void (E::*)(), F* ) ); +SA( ! __is_invocable( void (E::*)(), CF ) ); + +struct G { E operator*(); }; +using CG = const G; + +SA( ! __is_invocable( G ) ); +SA( __is_invocable( void (E::*)(), G ) ); +SA( ! __is_invocable( void (E::*)(), G* ) ); +SA( ! __is_invocable( void (E::*)(), CG ) ); + +struct H { E& operator*(); }; +using CH = const H; + +SA( ! __is_invocable( H ) ); +SA( __is_invocable( void (E::*)(), H ) ); +SA( ! __is_invocable( void (E::*)(), H* ) ); +SA( ! __is_invocable( void (E::*)(), CH ) ); + +struct I { E&& operator*(); }; +using CI = const I; + +SA( ! __is_invocable( I ) ); +SA( __is_invocable( void (E::*)(), I ) ); +SA( ! __is_invocable( void (E::*)(), I* ) ); +SA( ! __is_invocable( void (E::*)(), CI ) ); + +struct K { E* operator*(); }; +using CK = const K; + +SA( ! __is_invocable( K ) ); +SA( ! __is_invocable( void (E::*)(), K ) ); +SA( ! __is_invocable( void (E::*)(), K* ) ); +SA( ! __is_invocable( void (E::*)(), CK ) ); + +struct L { CE operator*(); }; +using CL = const L; + +SA( ! __is_invocable( L ) ); +SA( ! __is_invocable( void (E::*)(), L ) ); +SA( ! __is_invocable( void (E::*)(), L* ) ); +SA( ! __is_invocable( void (E::*)(), CL ) ); + +struct M { + int i; +private: + long l; +}; +using CM = const M; + +SA( ! __is_invocable( M ) ); +SA( ! __is_invocable( M& ) ); +SA( ! __is_invocable( M&& ) ); +SA( ! __is_invocable( M* ) ); +SA( ! __is_invocable( CM ) ); +SA( ! __is_invocable( CM& ) ); +SA( ! __is_invocable( CM* ) ); + +SA( ! __is_invocable( int M::* ) ); +SA( __is_invocable( int M::*, M ) ); +SA( __is_invocable( int M::*, M& ) ); +SA( __is_invocable( int M::*, M&& ) ); +SA( __is_invocable( int M::*, M* ) ); +SA( __is_invocable( int M::*, CM ) ); +SA( __is_invocable( int M::*, CM& ) ); +SA( __is_invocable( int M::*, CM* ) ); +SA( ! __is_invocable( int M::*, int ) ); + +SA( ! __is_invocable( int CM::* ) ); +SA( __is_invocable( int CM::*, M ) ); +SA( __is_invocable( int CM::*, M& ) ); +SA( __is_invocable( int CM::*, M&& ) ); +SA( __is_invocable( int CM::*, M* ) ); +SA( __is_invocable( int CM::*, CM ) ); +SA( __is_invocable( int CM::*, CM& ) ); +SA( __is_invocable( int CM::*, CM* ) ); +SA( ! __is_invocable( int CM::*, int ) ); + +SA( ! __is_invocable( long M::* ) ); +SA( __is_invocable( long M::*, M ) ); +SA( __is_invocable( long M::*, M& ) ); +SA( __is_invocable( long M::*, M&& ) ); +SA( __is_invocable( long M::*, M* ) ); +SA( __is_invocable( long M::*, CM ) ); +SA( __is_invocable( long M::*, CM& ) ); +SA( __is_invocable( long M::*, CM* ) ); +SA( ! __is_invocable( long M::*, long ) ); + +SA( ! __is_invocable( long CM::* ) ); +SA( __is_invocable( long CM::*, M ) ); +SA( __is_invocable( long CM::*, M& ) ); +SA( __is_invocable( long CM::*, M&& ) ); +SA( __is_invocable( long CM::*, M* ) ); +SA( __is_invocable( long CM::*, CM ) ); +SA( __is_invocable( long CM::*, CM& ) ); +SA( __is_invocable( long CM::*, CM* ) ); +SA( ! __is_invocable( long CM::*, long ) ); + +SA( ! __is_invocable( short M::* ) ); +SA( __is_invocable( short M::*, M ) ); +SA( __is_invocable( short M::*, M& ) ); +SA( __is_invocable( short M::*, M&& ) ); +SA( __is_invocable( short M::*, M* ) ); +SA( __is_invocable( short M::*, CM ) ); +SA( __is_invocable( short M::*, CM& ) ); +SA( __is_invocable( short M::*, CM* ) ); +SA( ! __is_invocable( short M::*, short ) ); + +SA( ! __is_invocable( short CM::* ) ); +SA( __is_invocable( short CM::*, M ) ); +SA( __is_invocable( short CM::*, M& ) ); +SA( __is_invocable( short CM::*, M&& ) ); +SA( __is_invocable( short CM::*, M* ) ); +SA( __is_invocable( short CM::*, CM ) ); +SA( __is_invocable( short CM::*, CM& ) ); +SA( __is_invocable( short CM::*, CM* ) ); +SA( ! __is_invocable( short CM::*, short ) ); + +struct N { M operator*(); }; +SA( __is_invocable( int M::*, N ) ); +SA( ! __is_invocable( int M::*, N* ) ); + +struct O { M& operator*(); }; +SA( __is_invocable( int M::*, O ) ); +SA( ! __is_invocable( int M::*, O* ) ); + +struct P { M&& operator*(); }; +SA( __is_invocable( int M::*, P ) ); +SA( ! __is_invocable( int M::*, P* ) ); + +struct Q { M* operator*(); }; +SA( ! __is_invocable( int M::*, Q ) ); +SA( ! __is_invocable( int M::*, Q* ) ); + +struct R { void operator()(int = 0); }; + +SA( __is_invocable( R ) ); +SA( __is_invocable( R, int ) ); +SA( ! __is_invocable( R, int, int ) ); + +struct S { void operator()(int, ...); }; + +SA( ! __is_invocable( S ) ); +SA( __is_invocable( S, int ) ); +SA( __is_invocable( S, int, int ) ); +SA( __is_invocable( S, int, int, int ) ); + +void fn1() {} + +SA( __is_invocable( decltype(fn1) ) ); + +void fn2(int arr[10]); + +SA( __is_invocable( decltype(fn2), int[10] ) ); +SA( __is_invocable( decltype(fn2), int(&)[10] ) ); +SA( __is_invocable( decltype(fn2), int(&&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&)[10] ) ); +SA( ! __is_invocable( decltype(fn2), int(*&&)[10] ) ); +SA( __is_invocable( decltype(fn2), int[] ) ); + +auto lambda = []() {}; + +SA( __is_invocable( decltype(lambda) ) ); + +template +struct can_invoke { + static constexpr bool value = __is_invocable( Func, Args... ); +}; + +SA( can_invoke::value ); + +struct T { + void func() const {} + int data; +}; + +SA( __is_invocable( decltype(&T::func)&, T& ) ); +SA( __is_invocable( decltype(&T::data)&, T& ) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable2.C b/gcc/testsuite/g++.dg/ext/is_invocable2.C new file mode 100644 index 00000000000..a68aefd3e13 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable2.C @@ -0,0 +1,139 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle std::reference_wrapper correctly. + +#include + +#define SA(X) static_assert((X),#X) + +using std::reference_wrapper; + +using func_type_v0 = void(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_i0 = int(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); + +using func_type_l0 = int&(*)(); + +SA( __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper ) ); + +using func_type_ii = int(*)(int); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper, int ) ); + +using func_type_il = int(*)(int&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int& ) ); + +using func_type_ir = int(*)(int&&); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( __is_invocable( reference_wrapper, int&& ) ); + +struct A { }; + +using mem_type_i = int A::*; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); + +using memfun_type_i = int (A::*)(); + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int* ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, int&& ) ); +SA( __is_invocable( reference_wrapper, A ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A&& ) ); +SA( ! __is_invocable( reference_wrapper, const A& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); + +using memfun_type_ic = int (A::*)() const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( __is_invocable( reference_wrapper, A& ) ); +SA( __is_invocable( reference_wrapper, A* ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( ! __is_invocable( reference_wrapper, A*, int& ) ); +SA( __is_invocable( reference_wrapper, const A& ) ); +SA( __is_invocable( reference_wrapper, const A* ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A*, int ) ); + +using memfun_type_iic = int& (A::*)(int&) const; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper, int& ) ); +SA( ! __is_invocable( reference_wrapper, A&, int ) ); +SA( __is_invocable( reference_wrapper, A&, int& ) ); +SA( ! __is_invocable( reference_wrapper, A*, int ) ); +SA( __is_invocable( reference_wrapper, A*, int& ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int ) ); +SA( ! __is_invocable( reference_wrapper, const A&, int&, int ) ); +SA( __is_invocable( reference_wrapper, const A&, int& ) ); +SA( __is_invocable( reference_wrapper, const A*, int& ) ); + +struct B { + int& operator()(); + long& operator()() const; + bool& operator()(int); +private: + void operator()(int, int); +}; +using CB = const B; + +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper&& ) ); +SA( __is_invocable( reference_wrapper ) ); +SA( __is_invocable( reference_wrapper& ) ); +SA( __is_invocable( reference_wrapper, int ) ); +SA( ! __is_invocable( reference_wrapper&, int, int ) ); + +struct C : B { int& operator()() = delete; }; +using CC = const C; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); + +struct D { B operator*(); }; +using CD = const D; + +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper& ) ); +SA( ! __is_invocable( reference_wrapper&& ) ); +SA( ! __is_invocable( reference_wrapper* ) ); +SA( ! __is_invocable( reference_wrapper ) ); +SA( ! __is_invocable( reference_wrapper* ) ); + +std::function fn = []() {}; +auto refwrap = std::ref(fn); + +SA( __is_invocable( decltype(fn) ) ); +SA( __is_invocable( decltype(refwrap) ) ); diff --git a/gcc/testsuite/g++.dg/ext/is_invocable3.C b/gcc/testsuite/g++.dg/ext/is_invocable3.C new file mode 100644 index 00000000000..e2b0c5ef406 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable3.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } +// __is_invocable should handle incomplete class correctly. + +#define SA(X) static_assert((X),#X) + +struct Incomplete; + +SA( ! __is_invocable( Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int, Incomplete, int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int, Incomplete ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete() ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int), int ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( Incomplete, Incomplete(int, int), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( Incomplete, Incomplete(), int, int ) ); // { dg-error "incomplete type" } + +SA( ! __is_invocable( int(Incomplete), Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), int, Incomplete ) ); // { dg-error "incomplete type" } +SA( ! __is_invocable( int(int, Incomplete), Incomplete, int ) ); // { dg-error "incomplete type" } + +SA( __is_invocable( int(Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(Incomplete&&), Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, Incomplete&&), int, Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&&), const Incomplete&& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&&), int, const Incomplete&& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, const Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int(const Incomplete&), Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( int(int, const Incomplete&), int, Incomplete& ) ); // { dg-bogus "incomplete type" } + +SA( __is_invocable( int Incomplete::*, const Incomplete& ) ); // { dg-bogus "incomplete type" } +SA( ! __is_invocable( void (Incomplete::*)(long&), const Incomplete*, long& ) ); // { dg-bogus "incomplete type" } +SA( __is_invocable( void (Incomplete::*)(long&) const, Incomplete*, long& ) ); // { dg-bogus "incomplete type" } + +template +struct Holder { T t; }; + +SA( __is_invocable( int(Holder&), Holder& ) ); // { dg-bogus "incomplete type" } + +// Define Incomplete, which is now not incomplete. +struct Incomplete { void operator()(); }; + +SA( __is_invocable( Incomplete ) ); // { dg-bogus "incomplete type" } diff --git a/gcc/testsuite/g++.dg/ext/is_invocable4.C b/gcc/testsuite/g++.dg/ext/is_invocable4.C new file mode 100644 index 00000000000..d1efccf08f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_invocable4.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +#define SA(X) static_assert((X),#X) + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_invocable +: public bool_constant<__is_invocable(_Fn, _ArgTypes...)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_invocable_v = __is_invocable(_Fn, _ArgTypes...); +#endif + +class Private +{ + void operator()() const + { + SA( ! is_invocable::value ); +#if __cpp_variable_templates + SA( ! is_invocable_v ); +#endif + } +}; + +SA( ! is_invocable::value ); +#if __cpp_variable_templates +SA( ! is_invocable_v ); +#endif From patchwork Fri Oct 20 13:53: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: 156152 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1091655vqb; Fri, 20 Oct 2023 07:20:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtDl9HKo+QES33cU2ntf7xGXj9bMNevvbQwniWS/3iLTnUC+waLawnvxYuGQZAjBmWFdej X-Received: by 2002:a05:6808:118:b0:3b2:d9d8:4039 with SMTP id b24-20020a056808011800b003b2d9d84039mr2111108oie.24.1697811640491; Fri, 20 Oct 2023 07:20:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697811640; cv=pass; d=google.com; s=arc-20160816; b=YUtQOqzOry0pHSP60mjAAZEusCLJv3Q9CUEbBt1ZlTxkIPM4GTCfeOQgmv2z1EDDk6 cjtnP9BA5zDX6iS9b5EpK0QuwuCsZUSit+JGU5l6ig8yFzBwYcM+N7ve2Z7tA3LgWVCv B9YZOTzMv87bzWlRhkOLGMl0KCnH/6AVMdwGWs/ytJY20ZCKp/+Ecth1H00HDJ5FMAtZ 61UcZtfWhfjptN6awLl/K+qBaklZSdX9JoxYT7kqyUCwfl8HVLTS/tihD3e//H6XmYLR UtTnA5EHKZc60LaaLhOS9T0bUzNfZINwDqm2VZYL3eItn3kyOtXq/WfXx4WU7brp9ujS F0NA== 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=GPoui+rxq4kXKgnqvNg8dhrl/W2LBqXo+b3sYOgt698=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=b84H7PzDJSIzF/9cBAur12pJKH51CPpxyMwuwyMQ/81qsjoy95twXDLnUhWlScQV3i 0j+77hddbN7tRKqNZjLd4hHjbl7MuE07gt0JNIIt5T4U+7yxRDOk2nj15xLvAb8XXDlJ bUzBQp/Cf3KGjx+U1xGoq4K6oZvN8qgIXtP7s979dT3KahSXSJ4R9X6pH+2Gt2L5MtZN EnRKwTlIimsNxxbQVPCkuwZGS2nt9dg4yYoB8oLOnNgHEk2oE9S2JQR/aEOiezcE5lq4 ULiHLoFhIDrlheOF6UtF4mZtZrSo1dHV/xRyplCfi4d1TMkgnkIJ3KvFJMFihvbQIRhL OOtA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SgzlMi13; 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 fc5-20020a05622a488500b00419930eb09dsi843494qtb.740.2023.10.20.07.20.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 07:20:40 -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=SgzlMi13; 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 627063888C47 for ; Fri, 20 Oct 2023 14:20:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 627063888C47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697811600; bh=GPoui+rxq4kXKgnqvNg8dhrl/W2LBqXo+b3sYOgt698=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SgzlMi13n4RBs0D00a2Q48nTJxwBkHvFAQNfxs5gjbfhzOUxazyvXLZ2a6WxAZj/x /NlF80jw/wQ5uP0i5f/WT6nqKcpzdkCg8fVtBwwBaKiLB5WFhjQ9v0/goCpIlLty3t WX8xMrd4/TqsW+OI+tcuLPSq8pSkUFZzAlzRf3bg= 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 086053858298; Fri, 20 Oct 2023 14:12:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 086053858298 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 086053858298 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=1697811133; cv=none; b=KrhKTIti7VbYobEMDiO+aCiXuaUNMv7f1cvVYbzo00hw9tayrDHycLVgyJ5asa4kSFZNMrO6y2wrHL1zvqOy0Jnn6bAnReb1+Dn7ORKl2UQ4fyKPRh+Tejgz7dRZkf5zDEEjABSkLbsIms6PAkeP5cyMgHSfXZ1LSX1jg5EP9r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697811133; c=relaxed/simple; bh=Ya78CWqk94KL1Qi/tZ79O0y/Jh7CV2hFvLiMENbSD/U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Yh22yMV8yuird2xGxLDZyjFQTjrZ7z9J9rZNWo6umGVKb5J7ho5iqJThENntaeE1s9B/gza5wMWJwkXEF4XiOVJ+AR/Zw+U1/35nBezvVD9WnEGRoLQocVnNXvYm8r1eI8ETWir33ut1r4voMojAMelWgg62q4eyflnNWU+Jg9w= 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 39KEB9ig009070; Fri, 20 Oct 2023 14:12:09 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tucbh4mh9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 14:12:08 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39KE8BSE017244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Oct 2023 07:08: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 39KDvqKl011267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Oct 2023 07:08: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 v23 33/33] libstdc++: Optimize std::is_invocable compilation performance Date: Fri, 20 Oct 2023 06:53:52 -0700 Message-ID: <20231020135748.1846670-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020135748.1846670-1-kmatsui@gcc.gnu.org> References: <20231017113822.677344-1-kmatsui@gcc.gnu.org> <20231020135748.1846670-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: N01IAuXXZWCJ-nOWdiJhqG6G3W2AZ1Ni X-Proofpoint-GUID: N01IAuXXZWCJ-nOWdiJhqG6G3W2AZ1Ni 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-20_10,2023-10-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 lowpriorityscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310200117 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1780284538906999082 X-GMAIL-MSGID: 1780284538906999082 This patch optimizes the compilation performance of std::is_invocable by dispatching to the new __is_invocable built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_invocable): Use __is_invocable built-in trait. * testsuite/20_util/is_invocable/incomplete_args_neg.cc: Handle the new error from __is_invocable. * testsuite/20_util/is_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 6 ++++++ .../testsuite/20_util/is_invocable/incomplete_args_neg.cc | 1 + .../testsuite/20_util/is_invocable/incomplete_neg.cc | 1 + 3 files changed, 8 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 75a94cb8d7e..91851b78c7e 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3167,9 +3167,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; /// std::is_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_invocable) + template + struct is_invocable + : public __bool_constant<__is_invocable(_Fn, _ArgTypes...)> +#else template struct is_invocable : __is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>::type +#endif { static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), "_Fn must be a complete class or an unbounded array"); diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc index 34d1d9431d1..6db004bdc43 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_args_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-error "incomplete type" "" { target *-*-* } 0 } #include diff --git a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc index e1e54d25ee5..608218b533c 100644 --- a/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_invocable/incomplete_neg.cc @@ -18,6 +18,7 @@ // . // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-error "incomplete type" "" { target *-*-* } 0 } #include