From patchwork Tue Oct 10 22:09: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: 150989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp168070vqb; Tue, 10 Oct 2023 15:18:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUwyR9rHn4tzs2CW9EUQknesSO1dRH+wVB6452RRfuNtSwoIH5OuhC7epugqtwi0DUI6eA X-Received: by 2002:a17:906:5357:b0:9ae:7681:f62a with SMTP id j23-20020a170906535700b009ae7681f62amr18703034ejo.44.1696976300575; Tue, 10 Oct 2023 15:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976300; cv=none; d=google.com; s=arc-20160816; b=gwORF5C35e7U1xPLAQBWDIeuqN77Hi8Z0hhaypwXhwApDaExtyfSzFlwUOEeiAmztj YfnBKYWOlrjatuFl4iQTbv1KZl9lu9nGHBsVyVDpwXjNffIyOmvHSXKXAszTPZRSeFGS aXl4HZOa3IRESwDaKPcrZJ/oktMJUi+fegmlbBrAP3I9sEzbZQqLgv8JSZQ+dORTFNVk ND6Vz9jCrQUhhciYTniZz0GyMOQ0/Vl7ZLdbPFohO7b2NoXR0zYq5P2n/4HAMKiI5Nvn NpEtNAjR74ubc3t/EsegIqlB8PmybrfA1R8ogX8oBTKtAzE50xtixowXKQl8Xiyf2i+h LnyA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wXLTABRFL60YAXS9CiQIOwQTnOd7zhR7eAs0KeuMBi0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Y/7yawvcfP4tyq0BIgcZkeGBj6g95+nMzbEGw74Mj3OdKqVWS6UfM7D5gHkbvLD0dt 79+2r6Q3jhKZG8FRXE5EF9TVRlhNAIM5Hadc9rlrF2geVn3YkyniGOTqvTUnUjCJMd2u vAb3e2spgUQzlloJlHBT9l4Oy9wMcu0Clez4w+5sErObpX5YqWB6qj4WDXgF/vy0C4Bf Ah5zWeiJ+rvbAnlV2hdv4rGKc+fdkCsmXuxSD+4v1OTHzWE63NJ11WYZiKpHVF2Rx142 IsLIXYJtKPDyajKz64LhFBeckc4iKZA1GeXge3Pn5Y2BaSMOmRnEdrJ12Xbt7Wub5tLF K0+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HqDj6X7g; 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 lc17-20020a170906dff100b00992c243f101si5826642ejc.854.2023.10.10.15.18.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:18:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HqDj6X7g; 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 109B2385B515 for ; Tue, 10 Oct 2023 22:18:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 109B2385B515 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976284; bh=wXLTABRFL60YAXS9CiQIOwQTnOd7zhR7eAs0KeuMBi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HqDj6X7g1mlkmHtHR7M32hoMqCbrYgYBTPYig6IfukSum/S7ds1y4h3Yhdx0bis6W 6kPxJQ83p5AX0Buu7/axHmEDnUZ/ieKjkQfhtaAvPG9llRmgRxA3so4Acn76WHHTDV 0Iqr8pAtJmfoN/pVZYy4a6mveas0NPU1mxkNGW8I= 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 A2E2E3858D35; Tue, 10 Oct 2023 22:17:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2E2E3858D35 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 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 39AMEXKD008579; Tue, 10 Oct 2023 22:17:15 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmu6qrana-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:16:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMGU6A010634 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:16:30 -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 39AMFOUE024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:16:30 -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 v16 01/39] c++: Sort built-in identifiers alphabetically Date: Tue, 10 Oct 2023 15:09:52 -0700 Message-ID: <20231010221520.3680267-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: uE67dRzmVT3m1WSJ7rUeg6Iak3hYC2fM X-Proofpoint-GUID: uE67dRzmVT3m1WSJ7rUeg6Iak3hYC2fM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 spamscore=0 clxscore=1034 phishscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776996705538360058 X-GMAIL-MSGID: 1779408621825912007 This patch sorts built-in identifiers alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in identifiers 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 identifiers 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 c9e4e7043cd..722fc334e6f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3702,18 +3702,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; @@ -3729,6 +3747,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); @@ -3748,50 +3778,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 80ef1364e33..782aa515da0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12090,15 +12090,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && classtype_has_nothrow_assign_or_copy_p (type1, true)))); - case CPTK_HAS_TRIVIAL_ASSIGN: - /* ??? The standard seems to be missing the "or array of such a class - type" wording for this trait. */ - type1 = strip_array_types (type1); - return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE - && (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) - && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); - case CPTK_HAS_NOTHROW_CONSTRUCTOR: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) @@ -12107,17 +12098,26 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && maybe_instantiate_noexcept (t) && TYPE_NOTHROW_P (TREE_TYPE (t)))); - case CPTK_HAS_TRIVIAL_CONSTRUCTOR: - type1 = strip_array_types (type1); - return (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); - case CPTK_HAS_NOTHROW_COPY: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) || (CLASS_TYPE_P (type1) && classtype_has_nothrow_assign_or_copy_p (type1, false))); + case CPTK_HAS_TRIVIAL_ASSIGN: + /* ??? The standard seems to be missing the "or array of such a class + type" wording for this trait. */ + type1 = strip_array_types (type1); + return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE + && (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) + && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); + + case CPTK_HAS_TRIVIAL_CONSTRUCTOR: + type1 = strip_array_types (type1); + return (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); + case CPTK_HAS_TRIVIAL_COPY: /* ??? The standard seems to be missing the "or array of such a class type" wording for this trait. */ @@ -12131,18 +12131,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); - case CPTK_HAS_VIRTUAL_DESTRUCTOR: - return type_has_virtual_destructor (type1); - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: return type_has_unique_obj_representations (type1); + case CPTK_HAS_VIRTUAL_DESTRUCTOR: + return type_has_virtual_destructor (type1); + case CPTK_IS_ABSTRACT: return ABSTRACT_CLASS_TYPE_P (type1); case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ASSIGNABLE: + return is_xible (MODIFY_EXPR, type1, type2); + case CPTK_IS_BASE_OF: return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) @@ -12151,6 +12154,12 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONSTRUCTIBLE: + return is_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_CONVERTIBLE: + return is_convertible (type1, type2); + case CPTK_IS_EMPTY: return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); @@ -12166,6 +12175,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: + return is_nothrow_xible (MODIFY_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + return is_nothrow_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONVERTIBLE: + return is_nothrow_convertible (type1, type2); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12196,24 +12214,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; - case CPTK_IS_ASSIGNABLE: - return is_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_CONSTRUCTIBLE: - return is_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_ASSIGNABLE: - return is_nothrow_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - return is_nothrow_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_CONVERTIBLE: - return is_convertible (type1, type2); - - case CPTK_IS_NOTHROW_CONVERTIBLE: - return is_nothrow_convertible (type1, type2); - case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12326,9 +12326,9 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ABSTRACT: case CPTK_IS_EMPTY: case CPTK_IS_POLYMORPHIC: - case CPTK_IS_ABSTRACT: case CPTK_HAS_VIRTUAL_DESTRUCTOR: if (!check_trait_type (type1, /* kind = */ 3)) return error_mark_node; @@ -12348,12 +12348,12 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - case CPTK_IS_TRIVIALLY_ASSIGNABLE: - case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_TRIVIALLY_ASSIGNABLE: + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: if (!check_trait_type (type1) @@ -12372,8 +12372,8 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: - case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_UNION: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12436,25 +12436,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { - case CPTK_UNDERLYING_TYPE: - return finish_underlying_type (type1); - case CPTK_REMOVE_CV: return cv_unqualified (type1); - case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return type1; + return cv_unqualified (type1); - case CPTK_REMOVE_CVREF: + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return cv_unqualified (type1); + return type1; case CPTK_TYPE_PACK_ELEMENT: return finish_type_pack_element (type1, type2, complain); + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..2223f08a628 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,9 +8,21 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif @@ -44,12 +56,21 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_convertible) +# error "__has_builtin (__is_convertible) failed" +#endif #if !__has_builtin (__is_empty) # error "__has_builtin (__is_empty) failed" #endif @@ -65,6 +86,15 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_convertible) +# error "__has_builtin (__is_nothrow_convertible) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif @@ -98,51 +128,21 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif -#if !__has_builtin (__underlying_type) -# error "__has_builtin (__underlying_type) failed" -#endif -#if !__has_builtin (__is_assignable) -# error "__has_builtin (__is_assignable) failed" -#endif -#if !__has_builtin (__is_constructible) -# error "__has_builtin (__is_constructible) failed" -#endif -#if !__has_builtin (__is_nothrow_assignable) -# error "__has_builtin (__is_nothrow_assignable) failed" -#endif -#if !__has_builtin (__is_nothrow_constructible) -# error "__has_builtin (__is_nothrow_constructible) failed" -#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif -#if !__has_builtin (__builtin_is_constant_evaluated) -# error "__has_builtin (__builtin_is_constant_evaluated) failed" -#endif -#if !__has_builtin (__builtin_source_location) -# error "__has_builtin (__builtin_source_location) failed" -#endif -#if !__has_builtin (__builtin_is_corresponding_member) -# error "__has_builtin (__builtin_is_corresponding_member) failed" -#endif -#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) -# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" -#endif -#if !__has_builtin (__is_convertible) -# error "__has_builtin (__is_convertible) failed" -#endif -#if !__has_builtin (__is_nothrow_convertible) -# error "__has_builtin (__is_nothrow_convertible) failed" -#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif -#if !__has_builtin (__remove_cvref) -# error "__has_builtin (__remove_cvref) failed" +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" #endif From patchwork Tue Oct 10 22:09:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp168868vqb; Tue, 10 Oct 2023 15:20:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4XHSvyGHQ6/okYkj7ZXKQoivfkyCQTOBkLCTSZJ5Lr1K5k8hqNaCn/57JZILN/+wf7jyn X-Received: by 2002:a17:906:1dd:b0:9b6:582e:be6a with SMTP id 29-20020a17090601dd00b009b6582ebe6amr16358159ejj.33.1696976421278; Tue, 10 Oct 2023 15:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976421; cv=none; d=google.com; s=arc-20160816; b=CviygNLUqbz163f2L9SLOlHeUH/XK1NJ8wq8oaXg9A2OHccxILGrKPT7ylAQCYknK+ iaxleDOW3oqKLLg9VGhHfaKIYQS88b3CIrUK8PkTLEqmL96lHGaSVQFA6gjRDI82iya9 fULyHxFeZwpcze5BU+DYA9sIbPebCv1TrLpmMCmRF1bhw1Fe7RpBCs1kNJLK0uM0UZ7v qtPbL9vxFYHfDC8gdylZ7XPC9u4SvmxkC7vvNqQM4o8JfkbxH3uxhX6Fl36hSOWMa2MT 2+u8lTgOpRQKmcS8Wd6gnjbWTno2k9mm7zacvcUPoP7Ki4NnlTJIfTfue85/ND8T6yTe eVLg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rtk1iNLXNcE8mH+oSkynZJZpFvr75WsUy9teL7vT5pk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MFr04mAmJQO+bx63DY9Cg/loNqqgu+j4YtNUAE1+vgA03Uee8H54ALq9m2kS8yl9ec ogwwDlA/3SHf0QC8C+IvUyr198kGwNnT3fv6Wu0z+tN2rfQu/7QmR3Yha6ZcCzHmPm2P Y/jMW8/1+tE+v8wjS3boUqm63KBL8jGida80ZzqAhfjwHec6tRNdUOaycbAWya8aHCmu zQoM8hr/zejchggzO/wncTMW6haWFMJTIgIKodaj/Cr8Utj+B7X5fcVgQ471nA6c0Jes HXfl0SA1sXpE4zrjcNLIJxoZ6YSB7u9r2NS8AcDhTEbfC3R5CbH51s9oVOdFZ7p/yEeG rLdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XJJE1gEa; 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 kq7-20020a170906abc700b009a9f295d7dasi5883571ejb.593.2023.10.10.15.20.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:20:21 -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=XJJE1gEa; 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 C65FD3856DD5 for ; Tue, 10 Oct 2023 22:19:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C65FD3856DD5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976399; bh=rtk1iNLXNcE8mH+oSkynZJZpFvr75WsUy9teL7vT5pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XJJE1gEa2DBqOtFxAedaB5i13pezp+oUbCrEjg8nDdJao/pIZctY2nBFgvn9pgdKU cTQYy69eTiy2H5RAp/T8zOfVnkaJFjaYPnZl+lQvwTsQU9Lpova7257LGJfnbVbWwO KB0JpWLMw5dSumRKVqJGBuXpKXkQmNwa42LFkC8Y= 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 9084C3858D35; Tue, 10 Oct 2023 22:19:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9084C3858D35 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 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 39AM3S1h012186; Tue, 10 Oct 2023 22:19:12 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tncaq1qy2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:19:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMHUPM010923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:17:30 -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 39AMFOUF024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:17:30 -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 v16 02/39] c-family, c++: Look up built-in traits through gperf Date: Tue, 10 Oct 2023 15:09:53 -0700 Message-ID: <20231010221520.3680267-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: RIc5nK87hjQ3PJrj6yBfRfgUliPHyREF X-Proofpoint-GUID: RIc5nK87hjQ3PJrj6yBfRfgUliPHyREF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 adultscore=0 clxscore=1034 spamscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779408747974559636 X-GMAIL-MSGID: 1779408747974559636 Since RID_MAX soon reaches 255 and all traits are used approximately once in a C++ translation unit, this patch instead uses only RID_TRAIT_EXPR and RID_TRAIT_TYPE for all traits and uses gperf to look up the specific trait. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Map all traits to RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. * c-common.h (enum rid): Remove all existing RID values for traits. Use RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. gcc/cp/ChangeLog: * Make-lang.in: Add targets to generate cp-trait.gperf and cp-trait.h. * cp-objcp-common.cc (names_builtin_p): Remove all existing RID values for traits. Use RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. * parser.cc (cp_keyword_starts_decl_specifier_p): Likewise, for type-yielding traits. Use RID_TRAIT_TYPE instead. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Likewise, for expression-yielding traits. Use RID_TRAIT_EXPR instead. (cp_parser_trait): Look up traits through gperf instead of enum rid. * cp-trait-head.in: New file. * cp-trait.gperf: New file. * cp-trait.h: New file. Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 12 +- gcc/c-family/c-common.h | 7 +- gcc/cp/Make-lang.in | 24 ++++ gcc/cp/cp-objcp-common.cc | 6 +- gcc/cp/cp-trait-head.in | 30 +++++ gcc/cp/cp-trait.gperf | 74 ++++++++++++ gcc/cp/cp-trait.h | 247 ++++++++++++++++++++++++++++++++++++++ gcc/cp/parser.cc | 70 ++++------- 8 files changed, 412 insertions(+), 58 deletions(-) create mode 100644 gcc/cp/cp-trait-head.in create mode 100644 gcc/cp/cp-trait.gperf create mode 100644 gcc/cp/cp-trait.h diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..f219ccd29e5 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,12 +508,16 @@ 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 }, +#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ + { NAME, RID_TRAIT_EXPR, D_CXXONLY }, #include "cp/cp-trait.def" -#undef DEFTRAIT +#undef DEFTRAIT_EXPR /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, + { "__is_same_as", RID_TRAIT_EXPR, D_CXXONLY }, +#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ + { NAME, RID_TRAIT_TYPE, D_CXXONLY }, +#include "cp/cp-trait.def" +#undef DEFTRAIT_TYPE /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..a1a641f4175 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,10 +168,9 @@ 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++ traits, defined in cp-trait.def. */ + RID_TRAIT_EXPR, + RID_TRAIT_TYPE, /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 2727fb7f8cc..8d4e3a1f594 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -34,6 +34,8 @@ # - the compiler proper (eg: cc1plus) # - define the names for selecting the language in LANGUAGES. +AWK = @AWK@ + # Actual names to use when installing a native compiler. CXX_INSTALL_NAME := $(shell echo c++|sed '$(program_transform_name)') GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)') @@ -186,6 +188,28 @@ endif # This is the file that depends on the generated header file. cp/name-lookup.o: $(srcdir)/cp/std-name-hint.h +# We always need the dependency on the .gperf file because it itself is generated. +ifeq ($(ENABLE_MAINTAINER_RULES), true) +$(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf +else +$(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf +endif + gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h + +# The cp-trait.gperf file itself is generated from a cp-trait.def file. +$(srcdir)/cp/cp-trait.gperf: $(srcdir)/cp/cp-trait.def $(srcdir)/cp/cp-trait-head.in + cat $(srcdir)/cp/cp-trait-head.in > $@ + $(AWK) -F', *' '/^DEFTRAIT_/ { \ + type = (index($$1, "DEFTRAIT_TYPE") != 0 ? "true" : "false"); \ + gsub(/DEFTRAIT_(EXPR|TYPE) \(/, "", $$1); \ + gsub(/\)/, "", $$3); \ + print $$2", CPTK_" $$1", "$$3", "type; \ + }' $(srcdir)/cp/cp-trait.def >> $@ + +# This is the file that depends on the generated header file. +cp/parser.o: $(srcdir)/cp/cp-trait.h + components_in_prev = "bfd opcodes binutils fixincludes gas gcc gmp mpfr mpc isl gold intl ld libbacktrace libcpp libcody libdecnumber libiberty libiberty-linker-plugin libiconv zlib lto-plugin libctf libsframe" components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc libbacktrace libphobos zlib libgomp libatomic" diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..c414d8f5a13 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -434,10 +434,8 @@ 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 + case RID_TRAIT_EXPR: + case RID_TRAIT_TYPE: return true; default: break; diff --git a/gcc/cp/cp-trait-head.in b/gcc/cp/cp-trait-head.in new file mode 100644 index 00000000000..9357eea1238 --- /dev/null +++ b/gcc/cp/cp-trait-head.in @@ -0,0 +1,30 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* 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 +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf new file mode 100644 index 00000000000..47e3c1af499 --- /dev/null +++ b/gcc/cp/cp-trait.gperf @@ -0,0 +1,74 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* 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 +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false +"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false +"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false +"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false +"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false +"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false +"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false +"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false +"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false +"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false +"__is_abstract", CPTK_IS_ABSTRACT, 1, false +"__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false +"__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_class", CPTK_IS_CLASS, 1, false +"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false +"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false +"__is_empty", CPTK_IS_EMPTY, 1, false +"__is_enum", CPTK_IS_ENUM, 1, false +"__is_final", CPTK_IS_FINAL, 1, false +"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false +"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false +"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false +"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false +"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false +"__is_pod", CPTK_IS_POD, 1, false +"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_same", CPTK_IS_SAME, 2, false +"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false +"__is_trivial", CPTK_IS_TRIVIAL, 1, false +"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false +"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false +"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_union", CPTK_IS_UNION, 1, false +"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false +"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false +"__remove_cv", CPTK_REMOVE_CV, 1, true +"__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true +"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true +"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true +"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false +"__bases", CPTK_BASES, 1, true +"__direct_bases", CPTK_DIRECT_BASES, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h new file mode 100644 index 00000000000..97ba8492d15 --- /dev/null +++ b/gcc/cp/cp-trait.h @@ -0,0 +1,247 @@ +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 4 "../../gcc/cp/cp-trait.gperf" + +/* 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 +. */ +#line 23 "../../gcc/cp/cp-trait.gperf" +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +/* maximum key range = 79, duplicates = 0 */ + +class cp_trait_lookup +{ +private: + static inline unsigned int hash (const char *str, size_t len); +public: + static const struct cp_trait *find (const char *str, size_t len); +}; + +inline unsigned int +cp_trait_lookup::hash (const char *str, size_t len) +{ + static const unsigned char asso_values[] = + { + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, + 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, + 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, + 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86 + }; + unsigned int hval = len; + + switch (hval) + { + default: + hval += asso_values[static_cast(str[7])]; + /*FALLTHROUGH*/ + case 7: + break; + } + return hval; +} + +const struct cp_trait * +cp_trait_lookup::find (const char *str, size_t len) +{ + enum + { + TOTAL_KEYWORDS = 45, + MIN_WORD_LENGTH = 7, + MAX_WORD_LENGTH = 37, + MIN_HASH_VALUE = 7, + MAX_HASH_VALUE = 85 + }; + + static const struct cp_trait wordlist[] = + { +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__bases", CPTK_BASES, 1, true}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + }; + + static const signed char lookup[] = + { + -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, + 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, + 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, + -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, + 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44 + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + unsigned int key = hash (str, len); + + if (key <= MAX_HASH_VALUE) + { + int index = lookup[key]; + + if (index >= 0) + { + const char *s = wordlist[index].name; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[index]; + } + } + } + return 0; +} diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f3abae716fe..432c43400ab 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "contracts.h" #include "bitmap.h" #include "builtins.h" +#include "cp-trait.h" /* The lexer. */ @@ -1165,12 +1166,8 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) /* C++20 extensions. */ case RID_CONSTINIT: case RID_CONSTEVAL: - return true; - -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE + /* C++ type-yielding built-in traits, defined in cp-trait.def. */ + case RID_TRAIT_TYPE: return true; default: @@ -2854,7 +2851,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 *, tree); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6021,11 +6018,8 @@ 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); + case RID_TRAIT_EXPR: + return cp_parser_trait (parser, token->u.value); // C++ concepts case RID_REQUIRES: @@ -11033,28 +11027,15 @@ 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, tree keyword) { - cp_trait_kind kind; - tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; + const char* keyword_str = IDENTIFIER_POINTER (keyword); + int keyword_len = IDENTIFIER_LENGTH (keyword); + const cp_trait* trait = cp_trait_lookup::find (keyword_str, keyword_len); - 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 (); - } + tree type1, type2 = NULL_TREE; + bool binary = (trait->arity == 2); + bool variadic = (trait->arity == -1); /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11044,12 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) cp_lexer_consume_token (parser->lexer); matching_parens parens; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) cp_parser_require (parser, CPP_LESS, RT_LESS); else parens.require_open (parser); - if (kind == CPTK_IS_DEDUCIBLE) + if (trait->kind == CPTK_IS_DEDUCIBLE) { const cp_token* token = cp_lexer_peek_token (parser->lexer); type1 = cp_parser_id_expression (parser, @@ -11079,7 +11060,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /*optional_p=*/false); type1 = cp_parser_lookup_name_simple (parser, type1, token->location); } - else if (kind == CPTK_TYPE_PACK_ELEMENT) + else if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* __type_pack_element takes an expression as its first argument and uses template-id syntax instead of function call syntax (for consistency with Clang). We special case these properties of __type_pack_element @@ -11094,7 +11075,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type1 == error_mark_node) return error_mark_node; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); tree trailing = cp_parser_enclosed_template_argument_list (parser); @@ -11144,7 +11125,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) } location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* cp_parser_enclosed_template_argument_list above already took care of parsing the closing '>'. */; else @@ -11158,17 +11139,17 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /* Complete the trait expression, which may mean either processing the trait expr now or saving it for template instantiation. */ - switch (kind) + switch (trait->kind) { case CPTK_BASES: return cp_expr (finish_bases (type1, false), trait_loc); case CPTK_DIRECT_BASES: return cp_expr (finish_bases (type1, true), trait_loc); default: - if (type) - return finish_trait_type (kind, type1, type2, tf_warning_or_error); + if (trait->type) + return finish_trait_type (trait->kind, type1, type2, tf_warning_or_error); else - return finish_trait_expr (trait_loc, kind, type1, type2); + return finish_trait_expr (trait_loc, trait->kind, type1, type2); } } @@ -20081,11 +20062,8 @@ 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); + case RID_TRAIT_TYPE: + type = cp_parser_trait (parser, token->u.value); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, From patchwork Tue Oct 10 22:09:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp169373vqb; Tue, 10 Oct 2023 15:21:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZa7nyD2dcl2SdyQ43uGanM25cP2YD3l94rbFjSDwdUw/fmOx0ziIIlq3AbULzACGtVCfk X-Received: by 2002:a17:907:77d6:b0:9ae:6a08:6f53 with SMTP id kz22-20020a17090777d600b009ae6a086f53mr17058143ejc.63.1696976491993; Tue, 10 Oct 2023 15:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976491; cv=none; d=google.com; s=arc-20160816; b=Z+55ZDop1UKWvbxYXVJOtNpO+enqIWqXCmOfzcrVhT1dOoNkOKVyrHXT/lrYLWH1Ew HwcZ7R/el3mSU4CrTW0DW4EivsQnZjlrfkdZHR5fl3s/8xtD7ocKkimEcioy95/sCwxa kEVylAv7PRx3cy7+Ntm6ec+0OE3WnXLJtFAwXAJhvS70sXrkzDPQXzaItMYsZHhyYF8m 5m813pQJGZMm9JRHdZA4Gidss2685PksvDiitpOgO6bj0o4UEk1OYBNsP2UcnqMogETO 8geLyqgeVG5gj0YbVry627Y54gBt/VuHNVExlGkz6i/wXCNLfbCjH0pOz7EEJLC02Tp3 qihA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=U2YH8qqMYfFaWsSHoBQyFiXArscz7bgx6YQrXyYABbg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TCOSafRHCHGKyZLKApZelplBAZ+dCaxHhyvwoL69jfibznRkT9HoTWQC6IEzWB7QIM LuseNjUcA7Dj73sUIHeLMHWHq/bmv6YpgO/J+XndY2K+CU9Cfhkvg055wdUGqOD0k3Xb vi5/Mcqy3mIVPaPZhB1vWy8aCBZ1KS7c1d+lljaijVXRBxG7zxvfY71tK9/vDXGNUyif jwrq/q+Pu8h7MAH3XTSwhCwGfKjbdmq/pOzsX+CJoV5od0PzCRQnZivgF2Y4W6wMIVKQ AuHy0wtb2/WMx12n5yR63avy5HUBy5/wGUoQhw678M0dw26hzWEZiAvWIemUfsw52h8P UJUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cYmZ4E35; 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 fy22-20020a170906b7d600b009ae3f7f47c2si5837060ejb.890.2023.10.10.15.21.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:21:31 -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=cYmZ4E35; 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 76CBB385CC80 for ; Tue, 10 Oct 2023 22:20:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76CBB385CC80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976451; bh=U2YH8qqMYfFaWsSHoBQyFiXArscz7bgx6YQrXyYABbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cYmZ4E35BwZ7EH9DUONCCSKEZK6rrAk1IEjFyIZtRg47xkYL76MFwHTpXLOlg4NE4 5veem3ZhoqvVLdIwrpYQQxt8ImxRhz2O86ukIHuXZqrEUcDIG2cd8T5/4m73oRqynu j/gNXUn7sHksEvkZazcEZ769KBWGGuRYtPzFFnrc= 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 B18F93856DE2; Tue, 10 Oct 2023 22:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B18F93856DE2 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 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 39ALuHHX027218; Tue, 10 Oct 2023 22:20: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 3tncaq1r70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:20:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMJfjY019870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:19:41 -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 39AMFOUG024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:19:41 -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 v16 03/39] c++: Implement __is_const built-in trait Date: Tue, 10 Oct 2023 15:09:54 -0700 Message-ID: <20231010221520.3680267-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 1NXYYaX5zFbWn4TDGpTkM84S3DKMIhQk X-Proofpoint-GUID: 1NXYYaX5zFbWn4TDGpTkM84S3DKMIhQk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 adultscore=0 clxscore=1034 spamscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779408821923061749 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * Make-lang.in: Update key positions for gperf, based on automatically computed values. * cp-trait.def: Define __is_const. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/Make-lang.in | 2 +- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 202 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_const.C | 19 +++ 8 files changed, 135 insertions(+), 100 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 8d4e3a1f594..b6e6cefca53 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -194,7 +194,7 @@ $(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf else $(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf endif - gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + gperf -o -C -E -k '6,8' -D -N 'find' -L C++ \ $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h # The cp-trait.gperf file itself is generated from a cp-trait.def file. diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 722fc334e6f..567dd35fe0a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47e3c1af499..47a5ec9ee6f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false +"__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false "__is_convertible", CPTK_IS_CONVERTIBLE, 2, false "__is_empty", CPTK_IS_EMPTY, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 97ba8492d15..c9005eee1ff 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -1,5 +1,5 @@ /* C++ code produced by gperf version 3.1 */ -/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ +/* Command-line: gperf -o -C -E -k 6,8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 79, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, - 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, - 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, - 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, + 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, + 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -104,6 +104,8 @@ cp_trait_lookup::hash (const char *str, size_t len) hval += asso_values[static_cast(str[7])]; /*FALLTHROUGH*/ case 7: + case 6: + hval += asso_values[static_cast(str[5])]; break; } return hval; @@ -114,116 +116,118 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 45, + TOTAL_KEYWORDS = 46, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 85 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, - 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, - 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, - -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, - 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, + 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, + 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, + -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, + 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, + -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 782aa515da0..23f1d1c249a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Tue Oct 10 22:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150992 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp169769vqb; Tue, 10 Oct 2023 15:22:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoZFt7Xz0dlSkfOXi8hpM9/Dnzb68V7V5o6aQqKv4fhBseNOGF687mBL50rK05B7M1uqkV X-Received: by 2002:a05:6402:4405:b0:536:169a:4ac3 with SMTP id y5-20020a056402440500b00536169a4ac3mr15833182eda.8.1696976549328; Tue, 10 Oct 2023 15:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976549; cv=none; d=google.com; s=arc-20160816; b=T6SGwETvcdH3+JMIHf3PHGGiuPzJ9xhhRDTptVGvfZcMn/ZS5IonE0bUqyz1391qun KJz8MC55p4dJF4sehMOLGEQFhjM1PRVUiDH3U/LhFHWWvEzZ1T54YfbYnDgQOOyHGGDd xoyHueaFSo/cns1wNOUoCRQmJLsgsQ4BC6eVUTwzzehFmM1vVscg9DPYCJekscMmBUrE VZLQRj1TctQlDY+kR4y+yzHnbmAXsCdF5/W7Cy4oUcGCY21nOk3VEvNLKi5WZsoZaT+/ K7kAUdDKVg4IjczBnKFoHrEJh0C4enztS+ZVqDgGrkTPxLFAMHp9tOBL8PP3mK380ecZ jMlQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ie+WZuzlrzqfEiiy13Mip9cShaZaUr4GRJ9sbR4j/5HYDPWu67WzE+7DQx6Gu7QuZG XmxY0W0L6OwONpwYKkTPqDQZLtvhGgX+R36s+JenjGDSR2GATF2bEmmEn/oPP4IEgeG5 g3aSSl20RJ2h/WTiEvnx/RuYq2Xsvbna5Q9raSzE2N8VpKKFzQHhyEhNMthUFCT0bITT JcRna34XEHzfvOgtEE4bUaxms2gFD8eSGapcrt0/2S65ZvFABScV5tMG0OfHFerBtpsP DBFr2RtLNj6pJVyeVouBv/0En+k51YUEymSV3yvOnAQ4sliUp03Qv0SoYBaxf3dAQ9yf bHhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="l/jhasjD"; 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 d25-20020a05640208d900b005382d29514esi5743145edz.574.2023.10.10.15.22.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:22:29 -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="l/jhasjD"; 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 B22FF385B515 for ; Tue, 10 Oct 2023 22:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B22FF385B515 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976504; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=l/jhasjDJXKAPlOLGIhNVOEcnj1oSKrVFhru9PRDkR2TsQ2coRyEpWPFK3T3aQfdV 0S/siDj/I0EUUSj6i2ZoARx8+3JRYit5G4lCbjrY0+DtiVc8TSPMd2STvi3YgZSB1i che7ysXK0GD4vBfrO+dToNrRzV5D7arX+S0xXEsM= 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 32980385734F; Tue, 10 Oct 2023 22:21:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32980385734F 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMIuBa030427; Tue, 10 Oct 2023 22:20:59 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v4ud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:20:59 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMKTgE018194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:20:29 -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 39AMFOUH024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:20:29 -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 v16 04/39] libstdc++: Optimize is_const trait performance Date: Tue, 10 Oct 2023 15:09:55 -0700 Message-ID: <20231010221520.3680267-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 86kEoPGiVKBk_5VdLQZ64sRgVZbpTXGf X-Proofpoint-GUID: 86kEoPGiVKBk_5VdLQZ64sRgVZbpTXGf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=837 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776995283749276021 X-GMAIL-MSGID: 1779408881996445643 This patch optimizes the performance of the is_const trait by dispatching to the new __is_const built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __is_const built-in trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..686e38e47c3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,6 +784,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -791,6 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3218,10 +3225,17 @@ template inline constexpr bool is_compound_v = is_compound<_Tp>::value; template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif + template inline constexpr bool is_volatile_v = false; template From patchwork Tue Oct 10 22:09:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp170202vqb; Tue, 10 Oct 2023 15:23:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES7Plu81BiYU0kw3Hy6M33sKcVnznoi1WXd3lp3QVTyTweKMCFs054m5qL285bXdttyzn0 X-Received: by 2002:a05:6402:22b0:b0:53d:bb21:4d90 with SMTP id cx16-20020a05640222b000b0053dbb214d90mr580665edb.40.1696976612244; Tue, 10 Oct 2023 15:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976612; cv=none; d=google.com; s=arc-20160816; b=Q1FTOGzckZ1NBrrc+0KASMsxoj9W15dAZEG5Li1Wkp3PYMXvwzxIxC9c8K1PJIDlV/ FHBsK4Cz3ieBioEjZKRmOqDGDy41RX4FuIETjncef3AuZg4R/DEjPCwIJMMtI7Gsizpd Ueec4Dy28RwJdkv0LUYLpYqBA5qRhIC7y/jUk+zK6yoyLkYuFSuy3M88EqHS9j8zGlkO T0VMx5igFQu6fReNJYLdaE55OQTa5OsQdoJYRYXEBtq0LFsmaK0o1dWVIJw+vql4DFmG BLHmZmp2Ek8r8/bfI0KtLF18eXjzkJwo2CQYWIF0k6n4A1IEFBucqzxAJXyA+xpILTGt WZ3w== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xwaCB/uZZ12L7KSWIEXJSTLaNg68MDINwTYoExzlXuN4DxAcd0nY4iLk2XAM4EOPL+ 3nFFv/bC41uuaTDzEfLSFXsRstjo5occAYKdi53UzWV49kKtz4kb+eIO7K0e7hODE5TV ZuTzPU1zmsuMsJJH9KwvHStUiMpmN4WP8/cGkM6rshrgBanBdrC8A3m7MymtbbXrXln8 sbmPpDkuKF7hoeVxRmHIhWFS44vpzY0PfU0bwxiIKA8WYNUunpaRIut0TVIKMV0ULiuI lXoZHLDtw3cBQbD171508zK/Nt4JYzpYj+r4UfB5/cSe5mFfdNW3XIoGmxRlAI5OvLbh 7ctg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cPq9lATY; 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 b26-20020aa7c6da000000b005380038919esi5893729eds.377.2023.10.10.15.23.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cPq9lATY; 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 94AE33861837 for ; Tue, 10 Oct 2023 22:22:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 94AE33861837 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976565; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cPq9lATYzTGJsFIBizWpkS60GWuwpE3mDSBXVjWS1sqyNahkMhjRLtabNtO69oZxq 1MsWZQWrpBVAa3tQDQokj8hB0y2NqDMO5kK6hPK72cJd6/z3aV+Xmik/Ax/RutZSzg 2qMj4coJMsEDUcKvwzTuemAoUonTGq2p+bThxBzc= 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 246C8385CC81; Tue, 10 Oct 2023 22:22:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 246C8385CC81 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 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 39AMLxKS011092; Tue, 10 Oct 2023 22:21:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3rfgm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:21:59 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMLs3r014950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:21:54 -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 39AMFOUI024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:21:54 -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 v16 05/39] c++: Implement __is_volatile built-in trait Date: Tue, 10 Oct 2023 15:09:56 -0700 Message-ID: <20231010221520.3680267-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Gk4urO0eskbM6Tf529bLZacfMG78faex X-Proofpoint-ORIG-GUID: Gk4urO0eskbM6Tf529bLZacfMG78faex X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxlogscore=846 priorityscore=1501 clxscore=1034 lowpriorityscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779408948055810202 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 38 +++++++++++++----------- gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_volatile.C | 19 ++++++++++++ 7 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 567dd35fe0a..f031e022541 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47a5ec9ee6f..ea7abda6c75 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c9005eee1ff..f462794d5db 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 46, + TOTAL_KEYWORDS = 47, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,27 +125,29 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 70 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, @@ -159,9 +161,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -215,19 +217,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, - 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, - 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, - -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, - 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, + 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, + 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, + -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 23f1d1c249a..73178540fbd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Tue Oct 10 22:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150994 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp170540vqb; Tue, 10 Oct 2023 15:24:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtFGiR3GLhIE2vtpiwf1u+7OCC5+ebrrxK3jlZOc2ol/XGZvq4i7dQsJWhHWcLZ54NVi4K X-Received: by 2002:a17:906:1d:b0:9b2:be12:d9bd with SMTP id 29-20020a170906001d00b009b2be12d9bdmr15470842eja.77.1696976670385; Tue, 10 Oct 2023 15:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976670; cv=none; d=google.com; s=arc-20160816; b=GiRX+h6ZYibKOXGVdTRusWOxVELT4VUFBDYqJgxgfLzkX5LlgceBvv6MH/W20gwiNr SEbwMYcrUgA6QQgMJgRVB5Scu//LUjz3gtqITtGgd7Pm1o1gipDMZ10pf5E71tVw1uOD c1T326r1j/eRSf7777tIEjdpkKbMGaQf8NPMoqLcn+zmPvERP5lchsZ2VTxNFiS65qwh kR6WvAjwDhYAxf3qkkBWdMglgjkFpN+qgVzvTo9ufUPpMlGfTlL+2HbuIXOG8CrfYrtF zOH5xecofWR/nhtBGRq8tOjRkyOnfXfapfPTCuPjYkbNjC9LbuTUObHUvUbPN5wkXUS6 HeNQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=VApYSrqyq1lNklUT2295CF430C5QLn1lZy2JYafPM4Rx1Xeq+Etxi+9f1lc0uFLwuO BLqA0dejTRuRSn3i5mcm58/Sb8FcgJ/9hQ7y5XsJCzxLsvmcQDb56a7Hf0Iw3zKE2buo 5eYrnYttzyMSjC9OLgcalXVU4+RUC+HuYy4YV+/AOmiJmcJVFdG45p5VXUKbjBmeHoQP z8lB8od48gddidnS3XFFJlFWZQsLlRQJK1ZmS+bTVMBBFKp8ZzildNY+5omz/dV2Sc1k h0mjQqx5m3jJUhXpDq5H9bCOoj5MFF8QzX5ISsebe7O3xzXfZneLPCcGN/jLJRU3VnlB 9F8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pyfL0m8h; 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 pw1-20020a17090720a100b0099d9806b0aasi5861986ejb.731.2023.10.10.15.24.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:24:30 -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=pyfL0m8h; 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 3364A385B524 for ; Tue, 10 Oct 2023 22:23:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3364A385B524 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976612; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pyfL0m8hsEUJY+e5uSWpXosv1IKuRrDo7xQcwNjq9IUiIm/PiXH7ygD6rlSw1Rm1p WfCMReMz9kbxLkTyJ/x/loB4uaD6crqrXPLyWBH8wVciMdfawh+Q+lYLVy3TYUM+Zx 3Gyc7RFQZGAS/dqvkd2VmQreiRwAGRQmOpQBRTRc= 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 ED7B2385CCB1; Tue, 10 Oct 2023 22:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED7B2385CCB1 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMM97b005341; Tue, 10 Oct 2023 22:22:48 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v5a5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:22:47 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMMXQH029374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:22:33 -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 39AMFOUJ024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:22:33 -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 v16 06/39] libstdc++: Optimize is_volatile trait performance Date: Tue, 10 Oct 2023 15:09:57 -0700 Message-ID: <20231010221520.3680267-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Kx8f8CBm7U8XD1PIldjBdKJvIstbgIyB X-Proofpoint-GUID: Kx8f8CBm7U8XD1PIldjBdKJvIstbgIyB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=884 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776997095680917896 X-GMAIL-MSGID: 1779409009326976217 This patch optimizes the performance of the is_volatile trait by dispatching to the new __is_volatile built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_volatile): Use __is_volatile built-in trait. (is_volatile_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 686e38e47c3..c01f65df22b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -800,6 +800,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) + template + struct is_volatile + : public __bool_constant<__is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -807,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3236,10 +3243,15 @@ template inline constexpr bool is_const_v = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) +template + inline constexpr bool is_volatile_v = __is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Tue Oct 10 22:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp170951vqb; Tue, 10 Oct 2023 15:25:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK/0wkcVlWrWTXzAQWi2zNJNxCAHAMy5mvdWA0rl+z/bd7+/WzGIRNT65uYx2goKmf/wn5 X-Received: by 2002:a17:906:9c9:b0:9b2:ccd8:2d42 with SMTP id r9-20020a17090609c900b009b2ccd82d42mr15550756eje.32.1696976730629; Tue, 10 Oct 2023 15:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976730; cv=none; d=google.com; s=arc-20160816; b=jeruy/iU8VOEkac/liLjE17qUhdv2NOcGg7souTGQvn/7rGNJNTO0tKuj2uwcpcc/W sEvsB4fkk80EqloSuT6nITPRMqD/sjAmfYNMHpVTG/CPVphjgI+T8/klm+P2NJGn9ajB rukOEnNMjo2c/3MNm+YKAWDnftW1QTROMPtzqAMrMSjwqrziKmWHxNgXvf0p8Y/lnP5E NoaYaAe4crpQ9krVeqSdkx3+OGVSSJsJYVvCFpYL2bPjMAXz+sKW/yA/uaq1q/XNMxcn zmWqvnLSCBjm1n3vbh1UaEhJnAFM2zbKVlHOL347xTuOnOfFalZD9cLxFLezsVHHL91i 7rkw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=R6xXZHHFOPaEH0nWWwQ/i5Ozub/bCu+kghiUkv+ez45YzKblHnlXSSKqpshWowJEyv 41UrYSUg2GtkkA7tQewcN1OF+6hhWqSyob+abnvCpBkNqTYNLDbzcWRdj16LysadTest 9PN6d3PcfJr/OdoSLnQpBeHbA+QU8Hr1tQETUTK/eR6/7Z6iL3k7TCqcKf+Tqvt6daVR pjwKX+iQCv7ezuGJbghqicMdD60T3Z8h0pXUGEx2xfmxNrhboXOzHBvwVu3Jaq8cTTTR 40B1atiYS9muxxZfgkYWgbV2vmkxwYFaXLjsJF995eVSvck1WApOAvLmcoBQ+SK3w1TW mu8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h8HU8V6p; 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 y17-20020a1709064b1100b009b953b4b961si5475217eju.189.2023.10.10.15.25.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h8HU8V6p; 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 79486385C424 for ; Tue, 10 Oct 2023 22:24:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79486385C424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976671; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=h8HU8V6pVw/ZAnoXbKLgMsJO4oSAtcE3N76oj0SGlBapo6iypRWrVw/18vxxh6QxA ynJ2MwTou55zdee6peQyYUBfP8ex1XfhqXgEIjkxTmuzHGmEPO0EF7srU3KtZEitdx AM6LKc+Yoj8MbxqvHUsiaXtvNDQC95N9xn3rVB1U= 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 1A8F73857343; Tue, 10 Oct 2023 22:23:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A8F73857343 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMJmdp031924; Tue, 10 Oct 2023 22:23:44 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v5r8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:23:43 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMN8A0024057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:23: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 39AMFOUK024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:23: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 v16 07/39] c++: Implement __is_array built-in trait Date: Tue, 10 Oct 2023 15:09:58 -0700 Message-ID: <20231010221520.3680267-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: E3tq4XEe0hNbqw7U591xcJ2icscmWxyv X-Proofpoint-GUID: E3tq4XEe0hNbqw7U591xcJ2icscmWxyv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=952 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409072132805271 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 148 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_array.C | 28 +++++ 7 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f031e022541..5e30a4a907a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index ea7abda6c75..fb162cac164 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f462794d5db..526e63dec42 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, - 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, - 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, + 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, + 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,108 +116,110 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 47, + TOTAL_KEYWORDS = 48, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -226,10 +228,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, - 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, - -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, + -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, + 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 47 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 73178540fbd..e1358afcb3f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Tue Oct 10 22:09:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 150996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp171436vqb; Tue, 10 Oct 2023 15:26:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxsdd6JvGp/KGSa5AWcuKWDNW8sivj6DAal9EVDXjAGUrBPuUWpbbzEIQEgWLOCy33e6oT X-Received: by 2002:a17:907:7f26:b0:99d:ddae:f5d4 with SMTP id qf38-20020a1709077f2600b0099dddaef5d4mr21901461ejc.44.1696976793491; Tue, 10 Oct 2023 15:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976793; cv=none; d=google.com; s=arc-20160816; b=A9TBQ/7jHkLJyN81tSTKF4TkBHEsxxzmptA5e3VHR+QTDPhv2Q9g5OM/18KZm2RvH5 73P3X1PtqHTfEC6iveO8y9rNIo+9OXz+XbbHGmO5QM/4DTneyAsYP0650TiLILCdZ1WB 5SKSBcs2aT4LXLxW6npSO2LqiiXkuXerKamQpqLU/RajvtZrEyYNiRqp0CMBrBgHyPKC ko70L+hJSQ2WKUBqMrf9hYCBeyTgpp8RfA1/D6XBgpZbgr+Fv70/U3SmlIda3ia6jokJ faQECnvjlQcXeSn2aiwdfXOxN7HIrAXImvTmSg5S9u0QvrfTWAh71l9DhJVd8i4RBU2y 6bag== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qDly3xNcTodk4HKINyechVgMum1FoLbvNb19XeLuAc8eCS/zGjfk/DfD8zM0zZiBEK NfZHzO71e3NznbOIDGuTQR88zsfM21NpYwX5l5pHX0l9qf/Zd+i+09jlH/H/1hws0mbf jYYCiRqOmgwmGrnI4t/YYiES11h7uReOfcQzE9LSXdR2qGENKENW3l7kPpKDfCi5X4f+ 6Z1YvhAqlvqzHu/+F2Z66yKKlmTJryFM1MQtlic7D2I0zPiAj1AuOklQenBrAozwoN5d ZbzKOXjzhkWANj9+7oEkwscn/j3ePVlm8rafUfMCvmVJv+xBxRd7T99SWcdhG29qdk18 k6TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XL1yPQhh; 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 i27-20020a17090671db00b009b2cda6d09asi5911054ejk.805.2023.10.10.15.26.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:26:33 -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=XL1yPQhh; 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 990913861882 for ; Tue, 10 Oct 2023 22:25:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 990913861882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976716; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XL1yPQhhlp6TAGLEnlNFnLOj3j2JIX4s0gRrSkOAkWhtadyAnCwy7Q8NJq9z/pUEO NJ89MUtgm7cgZRCzGRvJ1b/3lmFoFifbRZS6jtdwVupf2x1OzNvlM5lrvUoZsEF/qs 0ZP9rQ/GeTEeK1YOPY6nROsiLQ3DujTc4m5r/LqE= 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 1978A3857020; Tue, 10 Oct 2023 22:24:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1978A3857020 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 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 39AMLdWL032492; Tue, 10 Oct 2023 22:24:32 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnakfk858-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:24:32 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMO8Fh021017 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:24: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 39AMFOUL024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:24: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 v16 08/39] libstdc++: Optimize is_array trait performance Date: Tue, 10 Oct 2023 15:09:59 -0700 Message-ID: <20231010221520.3680267-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kc5fxKZ89QaI8zFj6TGYw0yG8V4-4dyB X-Proofpoint-GUID: kc5fxKZ89QaI8zFj6TGYw0yG8V4-4dyB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxlogscore=599 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776997263374731491 X-GMAIL-MSGID: 1779409138208164980 This patch optimizes the performance of the is_array trait by dispatching to the new __is_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_array): Use __is_array built-in trait. (is_array_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index c01f65df22b..4e8165e5af5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -523,6 +523,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_array +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) + template + struct is_array + : public __bool_constant<__is_array(_Tp)> + { }; +#else template struct is_array : public false_type { }; @@ -534,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_array<_Tp[]> : public true_type { }; +#endif template struct __is_pointer_helper @@ -3183,12 +3190,17 @@ template template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) +template + inline constexpr bool is_array_v = __is_array(_Tp); +#else template inline constexpr bool is_array_v = false; template inline constexpr bool is_array_v<_Tp[]> = true; template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#endif template inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; From patchwork Tue Oct 10 22:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151000 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp171898vqb; Tue, 10 Oct 2023 15:27:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN0kuGAbM7HS+qFITvzKFJ7yF6/xm2hFyipZ2ucA5Y98i3n1BObFsoTk6cCYuG8DpXh3ww X-Received: by 2002:a17:906:cc14:b0:9bb:a243:e6fb with SMTP id ml20-20020a170906cc1400b009bba243e6fbmr1568526ejb.3.1696976865873; Tue, 10 Oct 2023 15:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976865; cv=none; d=google.com; s=arc-20160816; b=Hoa8q/YN3jBkBHUZjqjt+w8zPeiMZdEGdvKF041KTrabcSzpw7CKRskxjImjC38h0h 1HFlQjU+DC0O5bkT8L6XOI/gHRugfJ24xDaYsArscxaA0NZKabl44k301noNp1xiEZMo ESYnKiOyISElTX8tl2oIpxTe13olkTJYQmF0fnl/uz3wDM6rNSWhBkJnZ/LY3ApeB+mE cVeuAOYMHRFcnkFQlHHuL6dnKXiGPYo6Mcw9lsA3YkEzU+AUYua+OMlmJxvbY9VJAQT9 6g7pLm/h4/TrugwsCWgUp1wLeM1R948h6aDz1Kzrqd8ocGfGtOXbrNSsdb/smu26zTk0 Ak0A== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uxO9WeJDHZUyV3mzz8Ujcdvcivtq7kESR7lDOU2z+ZKyznZ/HwaOoaz9PQ2r2b7ikh NlAzcFKjxBrG648rHldnwlNNrCesORsPFrYCZr5VX202MkFbtDTZ2amjwGhdHVC9NA60 TfFTNI7L+2ROorgisA/ATuZv0OhOMldPk8IrZNNyuG/I6P8xumN4lbDugXVNqfPh8Njz 3MGAl9Zh4UudX6N2jVhjc4+sz/kOveSddCtd/CcbEbBSHs6Wlm9a2GSHKrDbQsSM3uT+ Rf8XmiVH5BLuxH29mH13bRNlTdlT5yWglGwHLPIHdFPCm6Ky7bTPAGHjjyvKlve5W+Zi ZaBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I5BB9cHc; 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 y17-20020a170906471100b009a257565886si5906565ejq.954.2023.10.10.15.27.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:27:45 -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=I5BB9cHc; 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 3C198385DC19 for ; Tue, 10 Oct 2023 22:26:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C198385DC19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976777; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I5BB9cHcp1g8yN+ZEqs0BZBTT3gY2sdSsrBzWrkTddxmhr5L7tcSW0JHGmLv0fqas 1BBtjD3XEY+Lixj9YeQRIKJliDwkmHoW5jRw90vNbzFZmCiWtMAaMcB1varAIjzKa+ OICilpPXmrkxZpPu6kUoVgfw1WLKovCfVOLAHvEg= 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 C3FC73861809; Tue, 10 Oct 2023 22:25:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3FC73861809 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 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 39AMIfjg004523; Tue, 10 Oct 2023 22:25:19 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxq6yh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:25:19 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMPBtF019511 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:25: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 39AMFOUM024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:25: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 v16 09/39] c++: Implement __is_unbounded_array built-in trait Date: Tue, 10 Oct 2023 15:10:00 -0700 Message-ID: <20231010221520.3680267-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: lvG6-G2WNeVacIzFvpc2gGXq_HMkadM2 X-Proofpoint-ORIG-GUID: lvG6-G2WNeVacIzFvpc2gGXq_HMkadM2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=774 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409214036165039 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 42 ++++++++++--------- 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 ++++++++++++++++ 7 files changed, 71 insertions(+), 20 deletions(-) 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 5e30a4a907a..751ac61b25a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index fb162cac164..a894fc8c74c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 526e63dec42..47060ffbbef 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 48, + TOTAL_KEYWORDS = 49, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,30 +125,32 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" @@ -161,9 +163,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -219,21 +221,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, - 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, - -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, - 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, + 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, + 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 47 + -1, -1, -1, 48 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e1358afcb3f..0a2699be476 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Tue Oct 10 22:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp172289vqb; Tue, 10 Oct 2023 15:28:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFk4zJZWPbgN8qQhEX8fRrDcpdkRea6pVGjHpC9T/fPe2Sd/2cuHmKumGfnq1RUOMCsNCEt X-Received: by 2002:a17:906:9c9:b0:9a1:bd33:4389 with SMTP id r9-20020a17090609c900b009a1bd334389mr16211684eje.74.1696976926787; Tue, 10 Oct 2023 15:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976926; cv=none; d=google.com; s=arc-20160816; b=QVsfWl675/blCAB57f2QLJqC/9HEIbo49AYeGhrSau3fmR5Vlhqiu7r/MTZqTybaSX zdBtTE76Mc9C7AQPKrOriown148IF5GWF2EtrBGnFLYnX1M9lnFkZrsTCmX+Y5qFpDg6 bPtO8hfUwlZuurPKzskiR1Ahbpu2cV1wSNNt9Kb8IVPuQiBE5TgH0oPxpMLjsIjF/pwM dQZqBk0t9++iiLEvpes0iv0O7YCc8Kk6m4FBaxqZBKCaO74Db96MVKQd7bsW1gEk0I/9 bA1tQ3bPlUMxJmwvI5FUOYGC9eATPUxkugEKuhVtAXAiPknnXpyrOrXLCL6uCppa5DMM IvFg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=bysVbQk4y+bWoY/YCyt67VdNaK9rbiDgJvmNu++WAwtRnJFmE70vAOZLay4sgeFD1Z ZG5gGMyDn0b4QpEIH+UlIXKUFBYPeBl4lim3JQzs3gN8wEZcfNVnHU1vKvopDHNSE1WA 8F/ucvyF3m9ROy+zTv9Z2zmFmmkcd6cAlH0L1IVsucz/8KucXqkSS/m8rXvLka4AEtD+ NlZDhhBrg6U7Dz2qvuYUvsWPPdTPEtxVrQuqpaOdW0bXY7D/V94iLYpFgQc49CrNY9xH kL9BLC33chThdFBRkJA02wZ2VBrBbGFXnvmp3ZnkhWvNpK8qtRYNWKIaEadOv3TgZnm3 ksZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z9Xr4iF9; 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 y15-20020a1709060a8f00b009930f844671si5903963ejf.963.2023.10.10.15.28.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:28: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=Z9Xr4iF9; 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 89C9638323CF for ; Tue, 10 Oct 2023 22:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89C9638323CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976815; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Z9Xr4iF9vw/CQptExJh4Cwddri0lQEwCcw9Ylh9swrFWH3pJ2jkLH6nn393TQew4Q UOQM29JgqdlnlFbNwoDWQsbUZxHLvtlXMhkKGF6USlibKgD0IFqoYT/vIeV3vTwp9u skFrwGwqUhLVbz3WLwquc8n0SVaEM6xOoNqy31UE= 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 DEFDE3861909; Tue, 10 Oct 2023 22:26:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DEFDE3861909 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 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 39AMMTWY024576; Tue, 10 Oct 2023 22:26:10 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tncaq1t8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:26:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMPs3s013282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:25:54 -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 39AMFOUN024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:25:54 -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 v16 10/39] libstdc++: Optimize is_unbounded_array trait performance Date: Tue, 10 Oct 2023 15:10:01 -0700 Message-ID: <20231010221520.3680267-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: YX9fIrkme--eKNepwKsACcF85fxnbRTP X-Proofpoint-GUID: YX9fIrkme--eKNepwKsACcF85fxnbRTP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 adultscore=0 clxscore=1034 spamscore=0 mlxlogscore=505 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776996817880022434 X-GMAIL-MSGID: 1779409278038725245 This patch optimizes the performance of the is_unbounded_array trait by dispatching to the new __is_unbounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unbounded_array_v): Use __is_unbounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4e8165e5af5..cb3d9e238fa 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3541,11 +3541,16 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Tue Oct 10 22:10:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp172657vqb; Tue, 10 Oct 2023 15:29:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+v+35ch8fpi7LytV+JzyUqauqLwzohrF6fD5674qQDkUWUazGlNOEIVIaa+rgA/L9uGj2 X-Received: by 2002:a17:906:3ca1:b0:9ae:55f5:180a with SMTP id b1-20020a1709063ca100b009ae55f5180amr16624279ejh.9.1696976984597; Tue, 10 Oct 2023 15:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696976984; cv=none; d=google.com; s=arc-20160816; b=c2DOicCuwoT7fePSeM5arpSxSP7Oi9G84xscSAsdE6Jd8GvCe8mG6IBqvMfSK7uMjV n5IWAVt7+yeiuGK2Tp2lUTHUysu+UYNawY6HvcVDqf0R7x48AwehGe5lkux+LiIDDvaq FgTL5p4aOwm6Nf8Kr35u9uILwUztKm/Ku9u9wg3fl9alFU6L5Xk+hIcyQbwsenGE4tg/ uFEwoCXowKJpomCmOLQbhb9r4OgozfFQd3HCA3DJaVhsbshxMEGO8dozJgqI6EgGv5Qc LZjsLaVRD5Jsn0JoZxZHrltPZLj4hoHc5eftwM5Xv78kry/9Tm+JFxYo0pZp/dP4bV2m bkIQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ifkzg5+dDtkicwefhQky90CESuig3kJwXXi4TJScVeY+ApJS81YqhwNdCJdfBgKCo4 d1gVk/PxrjwXNZlaOsNz5xMKe4KL7/oFsrFgwiD2l25Rb7+DfKhmB7Eu1SU3DKiHSzVe G4npuU6s93a3WXFROe3XnjeDMT+GEix41VPyqhWxFgnKPoHRG3Q6LRBag+wIHqCWEEks Om6wOFQd+WSJ6YdAjP/LJFUpOvKvi0B2B+lo6CUeQtGEfsYihCWBJTF4Y63kzvrjrU/t WFbcFGrHEw08iQUUudbxn8Qot/+DquP29CN1nVoSblqxavCt7gj/ShZj636nTcpgwTDY vSWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PajLWweS; 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 g21-20020a1709063b1500b009b2c4c1eb6bsi5845937ejf.754.2023.10.10.15.29.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:29:44 -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=PajLWweS; 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 073493861920 for ; Tue, 10 Oct 2023 22:27:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 073493861920 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976852; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PajLWweSzkxBxRpFG4QPCxP92Pamvdh2FDx3IO9sjK9iyUHw0J8DqvPcVD83oUu6g fYEf2vYjJDulkOZgTuoVmid4uHBcvpKR7GGELpGOheRfDbQ+fnp8MKVN1IsbcDdDKX zszqDqUcIsEWevA3OxPUU9oJu5tTf/fViszlJ898= 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 B9873386EC25; Tue, 10 Oct 2023 22:26:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9873386EC25 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 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 39AMMwWJ013138; Tue, 10 Oct 2023 22:26:44 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3rh3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:26:44 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMQMws030548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:26:22 -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 39AMFOUO024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:26:22 -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 v16 11/39] c++: Implement __is_bounded_array built-in trait Date: Tue, 10 Oct 2023 15:10:02 -0700 Message-ID: <20231010221520.3680267-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: y3QjqjCQv_jgnJh1ZTxdN-ERk-X_vnAz X-Proofpoint-ORIG-GUID: y3QjqjCQv_jgnJh1ZTxdN-ERk-X_vnAz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxlogscore=803 priorityscore=1501 clxscore=1034 lowpriorityscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409338897994876 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 86 +++++++++++---------- 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 +++++++++ 7 files changed, 94 insertions(+), 42 deletions(-) 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 751ac61b25a..d09252a56b6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index a894fc8c74c..90fcdc01de6 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false "__is_class", CPTK_IS_CLASS, 1, false "__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 47060ffbbef..f22a6e93618 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 49, + TOTAL_KEYWORDS = 50, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,54 +125,56 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -181,7 +183,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -191,27 +193,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, @@ -219,9 +221,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -230,12 +232,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, - 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, + 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, + 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 48 + -1, -1, -1, 49 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0a2699be476..32880754020 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Tue Oct 10 22:10:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp173682vqb; Tue, 10 Oct 2023 15:31:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsThq97LxkvKqx/TIC/FJH5H5iBXfDSddBWyvUs1C5aR91oTfqGbExiME8yPvvbrwftUiK X-Received: by 2002:a17:906:57:b0:99c:c50f:7fb4 with SMTP id 23-20020a170906005700b0099cc50f7fb4mr15950684ejg.1.1696977117395; Tue, 10 Oct 2023 15:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977117; cv=none; d=google.com; s=arc-20160816; b=C5y5hfb6Jy0djc9GQ0JN7ZLC20eNgOW5oMEhqWegP1ktrFrkaXD3m7AU2NHoIVtrVk c/d/Cr4pdtVjbiVd94VzX4lWIJGaz4Dpu9E7W5Pd7EEtGEJbkTJ4ep5mjgeZBAnXK0gz aQ/Bkt/f/aO0/TmuOc7yVRuKhuY5DM4dk5BOzKieLSTNRbGd3SC4NSeP8EYARV+PrrzB P8wveNxwTadqm+vRcKPtta24RAoSrWXbwvNJYbRvo0FRPlkoBPkB4StWufg+Rw3qEFni qtQNZKgNtCAQgfocgK4l+Z+f8KWK8PdeHWeao1h4csu87plUP8CE/M0iCi4QNk0Caiaj juLA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=FydoETBFZ4g0G5b5A3w96Olh9rHpAQ01JAtZLUOZ5Uhn4M377od3l1s4BxLdMPSYD8 z3RDyjKmEYnoO1VHGqodsyUpPrS547vPcE8PqOle6nwqv3trWYRySYhCDfpyFOkK5trB XKophj6CzHkcEKImMbr+y8NTq8uaVK6D3lloTpb6veey+NG43jBKmxPv9s7L3jGbRLEr 7G05X6sS9svgIqIWAQgFfm8DKlAzogBDIVO9x2S8jf2eh/WESgPWa2PleO0Y0YVq0qCb SrVYnqwLYLytPxVcGCbleK/LDeww6pnjDUaQsBZqQngo1cMmEyuC8dFrKF7hXOu51vLY HVOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=K3Kpb44T; 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 qq8-20020a17090720c800b009a21af200f7si5914177ejb.993.2023.10.10.15.31.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:31:57 -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=K3Kpb44T; 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 163563865C2B for ; Tue, 10 Oct 2023 22:29:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 163563865C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976942; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=K3Kpb44TN4A1dtbbw+ucXf0iZmZWbwCUA5hWPFg2YS8nfHi+8OgyPOPC+lBEzDNTO rIxWzaZJRuMpe61KM052aX6XAiLdJBKwaFe0P+i2T4e6uDYHjukdp5Jbh3wGANJ7Fb 7jSyMrTbjZdJz5m3rwpKAbGjlA1OZeUdbzr3QAZc= 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 EF8AF3861915; Tue, 10 Oct 2023 22:27:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF8AF3861915 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMP3q8013806; Tue, 10 Oct 2023 22:27:16 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v6n4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:27:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMR7UY021731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:27:07 -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 39AMFOUP024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:27:07 -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 v16 12/39] libstdc++: Optimize is_bounded_array trait performance Date: Tue, 10 Oct 2023 15:10:03 -0700 Message-ID: <20231010221520.3680267-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: YQ7cUmuH4mWjscOz_hHxryvfvzGb7ZVt X-Proofpoint-GUID: YQ7cUmuH4mWjscOz_hHxryvfvzGb7ZVt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=660 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.5 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: 1776996999788880715 X-GMAIL-MSGID: 1779409477648784745 This patch optimizes the performance of the is_bounded_array trait by dispatching to the new __is_bounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_bounded_array_v): Use __is_bounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index cb3d9e238fa..d306073a797 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3532,11 +3532,16 @@ template /// True for a type that is an array of known bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array) + template + inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp); +# else template inline constexpr bool is_bounded_array_v = false; template inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true; +# endif /// True for a type that is an array of unknown bound. /// @ingroup variable_templates From patchwork Tue Oct 10 22:10:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp173305vqb; Tue, 10 Oct 2023 15:31:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGn3VD7lH5MUEqLZFFkn8tKabr72ZE0VJqsJTOn9JKLfuFToT0GrmREOBIqi+gmiN9k/AQ X-Received: by 2002:a17:906:24d:b0:9a5:ca42:f3a9 with SMTP id 13-20020a170906024d00b009a5ca42f3a9mr19156452ejl.2.1696977068006; Tue, 10 Oct 2023 15:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977067; cv=none; d=google.com; s=arc-20160816; b=lu0nljadHKDCiCkf0PBDTzNamlbswUdk6OWuARmDbnWnE8zsVQUjiY4K7UtBbOu8RR EfFcoCLRDfsapqAhzxF9GymlKywqhC2OR0TFOMw8dLuehclroP3TXkaDCPc39JvtU184 /LhxMmRtdfA7EJKNgvf/9vSCnzYE802xOaDaMn6a0Dk0grfUwYYTUIanE64I/5EcvUz5 UJC6zY/aRGlPbyxgDhyAoY8Lxq2UQ+ukitBMZbENhpODh7C/ALmng44RgSBmNbjS/+dX pfjNECQT6qKqOwDxL0lrfoUz7l7NK4KY2TxIHsNUrO/jIB741J4i/nIXCindM+UsMZ6L 64rw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=FXeawr1fGyxI9RL2wkSMOaCwuSctuWYvc0g+TaFtMXGSFwG2NofNSZtTASwquUZPjs yYbBvCG0/7pLAP8pggfrp49VN9SSKaTwXDEF/CcvJV+TFm4krXhiXnB1fC2BcDkLWQSh RuT7gSQSG5k7j7tHp+BFLDLx8SyxhywUGwKjMngsmTLA2EeGHVPLhTmrtffvZv45gBX9 rGVQ5q1+CjALsHbh+C05+Hwrf1YnOTE727zlQUu6/bCEG2rqvGbv0aojZfBJrr4TjZsj 65BkeetRhE+wHV5KTeBsL1kqRBmQZYTm+6HHPLe17lfmcOCqaqKXhwm1wrMJSyP2GFz8 Uhlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rxnm7F4B; 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 qk29-20020a170906d9dd00b0099d977a31fdsi5859198ejb.899.2023.10.10.15.31.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:31:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rxnm7F4B; 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 BC2703882009 for ; Tue, 10 Oct 2023 22:28:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC2703882009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976919; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Rxnm7F4BLCU/aX2yiJMGCnfaqmHPRU8BKz+2uOmiPjm6tOtVrXk9oDyOUOCdM38hh nZanl69DC95j/Y1JnG224iE9PcT7nWJG3V/EpQVwww0NQ2yxQGDO23/JeNoJbrLflf TienWqv8CVW+36nRrxPYTAHGBVM1ukgqXM3sKYcg= 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 C95273861842; Tue, 10 Oct 2023 22:27:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C95273861842 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 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 39AMOSlR013509; Tue, 10 Oct 2023 22:27:51 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn7xkd54g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:27:50 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMRfhL013841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:27:42 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39AMFOUQ024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:27:41 -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 v16 13/39] c++: Implement __is_scoped_enum built-in trait Date: Tue, 10 Oct 2023 15:10:04 -0700 Message-ID: <20231010221520.3680267-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: remHCQSpQ1ArXL4fwgzkBeRYYVt1d1_F X-Proofpoint-GUID: remHCQSpQ1ArXL4fwgzkBeRYYVt1d1_F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1034 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=741 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409425946922957 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 161 +++++++++++----------- 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 +++++++++ 7 files changed, 160 insertions(+), 80 deletions(-) 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 d09252a56b6..1c0b2e0f178 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_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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90fcdc01de6..f3fd82ba549 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -59,6 +59,7 @@ struct cp_trait { "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f22a6e93618..9c18165eb68 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, - 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, - 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, + 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, + 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, + 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,56 +116,60 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 50, + TOTAL_KEYWORDS = 51, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -173,22 +177,18 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" @@ -197,47 +197,48 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, - 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 49 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, + 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, + 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, + -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, + 50 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 32880754020..f56ab031d5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Tue Oct 10 22:10:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp174566vqb; Tue, 10 Oct 2023 15:34:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETDUuIiVK5m36wFimIwh8N8ZEsM0Rl9/w+RXse39lyaiZ2Dc8+lrogptb0pPb2LDR5rSdI X-Received: by 2002:a17:906:539a:b0:9a6:1560:42e8 with SMTP id g26-20020a170906539a00b009a6156042e8mr15702244ejo.55.1696977242410; Tue, 10 Oct 2023 15:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977242; cv=none; d=google.com; s=arc-20160816; b=YzpjKM4SapKAqDY8Qr6PunhOHM2qwggdzRZC5E4NeaQQ3uZn1jN9RWuI+Lqo1tKxG+ ISFyX0PdBat3GwGwxtlT7TMbaBpJcT19OElOTQFOmLxfNuXBj8gNfuqnJDwpY1ua+4TX YeWx9Cw/c3/5lc3t61iQNR66mnt3pKYdU+gmD5jlp6l+RlRMNT416nV+DYP0dvKxltrf PRB495y6cWaRAXDrLunZHz33Bb4tPbSlMwg8Xw7NSv2TDXKPhUm4OWUmWwK2LLrOBPh3 g9aneLzxqgwLOVzsfbpmBjq+xKDTgBSvfKymzqzFga8dMWzT/AQk06anKfGmkdVHMo5L b1Rg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=o/B8bR4FkwFAd6Dx10bcBB9j0V2aMrP2aylwaCv91j+7L3FiQSiL+cvfPXMNMQnU/1 zldV9nFBoabScbKd0/VndXax6JihIyNlSD8fQVYxDVhvckZcSF87UsAp1aaIlSlto+aF bHwitsUaLHKAkLmENt7/73Qtg8+uNuuK8a/A/tZ2pyRnd7QaWOX2o2TWv1ZbCKfJR26Q adDhGmnvcdB3pJzbRRPwqIdpDm6fDOEVqLuC0+gFFDAQl5bXhhhJMDnfeCc/9x1hrP2w SQLfas7yxKG6wVcApTegNrQZLlB18W+6inuP2nK8PAGqVGryviyv/vflMLKCMetAb3qi GYTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="FQ10ZC/Y"; 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 v20-20020a1709063bd400b009b953d3a34esi5439177ejf.543.2023.10.10.15.34.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:34:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="FQ10ZC/Y"; 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 6B8B33858404 for ; Tue, 10 Oct 2023 22:29:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B8B33858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696976999; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FQ10ZC/YCCNBSb/fVy7YQ+ZqnW5TCg8+OcVIjbZRpbLftYDZb0BTa8GOEHzgU2SDc 3ThpNh3wI/hI79YHpPZ+MLllQ6m4TrDPPtfz0sr8ZT+xB2+FrxTGo1rE0C8wI0z6OI 1FNIsvd3KptDrh6qfAzPEjTO7OyUmqT+Be/Cje6k= 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 209D93861876; Tue, 10 Oct 2023 22:28:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 209D93861876 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 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 39AMD1xT013781; Tue, 10 Oct 2023 22:28:29 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnay8u43x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:28:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMS8W6031103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:28: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 39AMFOUR024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:28: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 v16 14/39] libstdc++: Optimize is_scoped_enum trait performance Date: Tue, 10 Oct 2023 15:10:05 -0700 Message-ID: <20231010221520.3680267-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: VHTRaCG2zLEVec10f1ufu1SlKQaIGivt X-Proofpoint-GUID: VHTRaCG2zLEVec10f1ufu1SlKQaIGivt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 clxscore=1034 mlxlogscore=890 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776994899316432234 X-GMAIL-MSGID: 1779409608823109230 This patch optimizes the performance of the is_scoped_enum trait by dispatching to the new __is_scoped_enum built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_scoped_enum): Use __is_scoped_enum built-in trait. (is_scoped_enum_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index d306073a797..7fd29d8d9f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3633,6 +3633,12 @@ template /// True if the type is a scoped enumeration type. /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + struct is_scoped_enum + : bool_constant<__is_scoped_enum(_Tp)> + { }; +# else template struct is_scoped_enum : false_type @@ -3644,11 +3650,17 @@ template struct is_scoped_enum<_Tp> : bool_constant { }; +# endif /// @ingroup variable_templates /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp); +# else template inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value; +# endif #endif #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp From patchwork Tue Oct 10 22:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp174768vqb; Tue, 10 Oct 2023 15:34:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdllMGtJJmL49STU5u0usrhyUwPob7IVMne7o9RnPMO5o4Dmd1Hgh2dIG1s+s329bjgOGD X-Received: by 2002:a05:6402:150f:b0:534:7ae0:9789 with SMTP id f15-20020a056402150f00b005347ae09789mr17958355edw.24.1696977269587; Tue, 10 Oct 2023 15:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977269; cv=none; d=google.com; s=arc-20160816; b=fLvY5F9Azq86HLN1RAeakRUY3jShbPCAYwezAp/E1RwIP3UuwO7qssa8CwAv0bj4Pp aQlEmdkSrsMCpePRiL3Cu6qjT5Ja/8dWbvYXT0o33pJJLAStDw+zAFav1a8jhCD7Wiqd qUrc9zBoS6LQAgVAFU+bS5messwU2Jotp7qOyaThsxplKlqBLazpTZ2+WrlRsYohysfk H7/MUXfffIa8h2bEHd7R/pNUJ0r0JzYHYreBn+B50lTyndqSbVKme0zZBNf3S8TilEVs Bh7X1hTpCj/aFYCxDiWCJChptBd9Vn2DyiJR5X21AJPDS/G595Mo0ij6f4suyA52LdvT ePAQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wHxvdJnSWHkPZPpQeBV+qTvw0DDIsZvFMmZ4usYDxK+vkUJBB7OOtXHB7yL2BKpT6P M1sGUPRgkQ+JVtqDXBwXaIwc1kPbkw2yjp0oerzLRUtdAWVIOoUOfXJmLc9Ro+n/mV4W Kb310sntNBHZ19dR3/2IvjJTbkj65k83XHXlGJOF/jd2hO0Z6S1r8cXDhcG8JbXA8bZl T0HkK7m52zktgeH26KFpQnegvRX+oZo0dh/beM7fogc8z3/BevQmcIi8JqRf3080cSNL jSwKQed8NUGKNX2yjSaFtselhqFWQUcXRoTJSQSaOjcML5PIoeyIAlerA8/a81RZMsed wDYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="X/euLpJp"; 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 n21-20020a05640205d500b0053b3ce47014si4344220edx.125.2023.10.10.15.34.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:34:29 -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="X/euLpJp"; 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 4198C387542B for ; Tue, 10 Oct 2023 22:30:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4198C387542B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977014; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X/euLpJpGUhInih+K4uKybNKukqL042VurnUS5qaoBLvME2tMjoMY34a+UMWdIl9z BZO4N4kwgfKvB04n54FxYtvChoNxhVsjPRTVzOHwRoSvoH9TNBctU4rDCe13rRfXiU zmBryamwRDrQw170Ntxc9CxSosZgKBAuT63JcCKQ= 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 5A5223882015; Tue, 10 Oct 2023 22:28:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A5223882015 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 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 39AMJPbb000705; Tue, 10 Oct 2023 22:28:50 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn7xkd63q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:28:50 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMSQR8020407 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:28:26 -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 39AMFOUS024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:28:26 -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 v16 15/39] c++: Implement __is_member_pointer built-in trait Date: Tue, 10 Oct 2023 15:10:06 -0700 Message-ID: <20231010221520.3680267-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: GMsEptsGK6kuDIeyHsnTU6TzIllwSB0A X-Proofpoint-GUID: GMsEptsGK6kuDIeyHsnTU6TzIllwSB0A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1034 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=952 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409637571056604 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 153 ++++++++++--------- 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 ++++ 7 files changed, 120 insertions(+), 75 deletions(-) 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 1c0b2e0f178..f0d3f89464c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index f3fd82ba549..3775b11283d 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 9c18165eb68..dfd60cec6e6 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 111, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, - 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, - 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, - 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, + 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, + 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, + 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118 }; unsigned int hval = len; @@ -116,69 +116,67 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 51, + TOTAL_KEYWORDS = 52, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 117 }; static const struct cp_trait wordlist[] = { -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -187,58 +185,63 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, - 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, - 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, - -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, - 50 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, + 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, + 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, + 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, + -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, + 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 51 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index f56ab031d5f..6c4880d8a33 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Tue Oct 10 22:10:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp175289vqb; Tue, 10 Oct 2023 15:35:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsrlheBDQnSPzljl6GhR01PmDorIN2AbaMp/dB9AfeUg92phy9RPeKMwid8n4dRZdSHt6b X-Received: by 2002:a17:906:1099:b0:9ae:5fe1:ef00 with SMTP id u25-20020a170906109900b009ae5fe1ef00mr14935611eju.45.1696977337452; Tue, 10 Oct 2023 15:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977337; cv=none; d=google.com; s=arc-20160816; b=TmY50NH3uJZgsG8181LmbCnf7Yg/g0o1EbnHap2NLzQL9bNokpC8cCkG9Yi9lN0mE7 DJHhsD7z1DhLwpN2LxjGO5bhrF53CykJg8dnI79naudXKjV1nF5LATEOdUq3oMR95ulq NNdI/uslmc8DUrj2cX4g1YwYwLUKBP20azQQtAT0HRexEaHt6/cw2gMf5WKENwRZG4HI JvliFLQEygtu1vnPE7Zo6KDjOXv/lBEHuPtw0ey7M2xcUQZFUx1DcwkjSRzv7uA6sXIa 4FI8ipRQz0UtdZ4fxPzmzIfu7DSRiy6+7pfc5ElpQdG2TBCjNjXfUQYV0h9x9ozXCVSs /g9A== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Omdfxx2jPB/SjVVthIQar61mEBSHvEi1zsvifaHUMfc1mpQ29gjxlGvHv9GwJsJUZO UnG3GfFBZnGukPQyUa2Qoh1vCVHOZKzUZBiSmnVhavYLi10Qd8+3fD9ZNalib+Te63Sv tYVKz3kMl/1KHHnp5RI5XwSJrAbj9Ra5eGrZfQf+eeqzID6uNEWUHFLh2zzeQX1M6JR1 A/j1YdG7HGccFQ6N6PNCSs2OhqdOHAMvn1g4XMOLGnasczBJsvfWu4Pv/+SFEIldqAJ9 7BhvcJg2mfVDhP6I88Tk1PTRL4uCrlije6UFYeQ71erK4NzoqlcmgGneBH3te1Mz2MFq UD0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SKaWa0D3; 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 x18-20020a170906135200b0099cbccaed7dsi5614628ejb.905.2023.10.10.15.35.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:35: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=SKaWa0D3; 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 859CA38618B3 for ; Tue, 10 Oct 2023 22:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 859CA38618B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977074; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SKaWa0D3URUsi0MGhRV1Q8ArgXbMyPJ7gtg/wH4V7jKqtjnKusOjI4nN2Cac9sHVh f5fpkDVWYUaW+pSTfrxALaUwyiCCDulTbVF8tZ7fmaSCCJiR7X6BvsNbU2vbJlAzM4 lPgRfeXvfd6W6ak27vRraBdXcwwAS2dT3eClG6PE= 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 738B6388459F; Tue, 10 Oct 2023 22:29:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 738B6388459F 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMIuFN030427; Tue, 10 Oct 2023 22:29:26 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v8h5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:29:26 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMTA5R020670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:29: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 39AMFOUT024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:29: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 v16 16/39] libstdc++: Optimize is_member_pointer trait performance Date: Tue, 10 Oct 2023 15:10:07 -0700 Message-ID: <20231010221520.3680267-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: YTI8tvvdeYpXFyGePoFAarQxXXl0Vhp3 X-Proofpoint-GUID: YTI8tvvdeYpXFyGePoFAarQxXXl0Vhp3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=580 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776996307296308519 X-GMAIL-MSGID: 1779409708749799284 This patch optimizes the performance of the is_member_pointer trait by dispatching to the new __is_member_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_pointer): Use __is_member_pointer built-in trait. (is_member_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7fd29d8d9f2..d7f89cf7c06 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -716,6 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_compound : public __not_>::type { }; + /// is_member_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) + template + struct is_member_pointer + : public __bool_constant<__is_member_pointer(_Tp)> + { }; +#else /// @cond undocumented template struct __is_member_pointer_helper @@ -726,11 +733,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; /// @endcond - /// is_member_pointer template struct is_member_pointer : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif template struct is_same; @@ -3242,8 +3249,14 @@ template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template inline constexpr bool is_compound_v = is_compound<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) +template + inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp); +#else template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) template From patchwork Tue Oct 10 22:10:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp175206vqb; Tue, 10 Oct 2023 15:35:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwHJyenFsblUhszvewVO/tv2iH1ilN+fwwxWkUen/G/2KVX4qRksEjjsHUkQIyWpX/UhLe X-Received: by 2002:a17:907:9492:b0:9ae:793f:2010 with SMTP id dm18-20020a170907949200b009ae793f2010mr20904156ejc.42.1696977321841; Tue, 10 Oct 2023 15:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977321; cv=none; d=google.com; s=arc-20160816; b=ttj+GX7Rvw8/YdFjwc+E36m/MZRUrk33DgJgMJ3GuyEIVeynGOTVmQimHR16WdHldF KP+sxLfrLtkHfEUF9Y/Hy8Q5Ga0JwozqZgSPN+jD9VrPT3Nve7r72DU6gKYZoHJrq9v4 2EwBN2vFcsKCXSV1PZ1yptQLTn4fQYpoVSMlY0cfyvSG6OxeZuHu588cTUnshOmpEsZ8 tPFLVGc6hUMrI1EE1IF9QGTTTvcaKPLTTKl2DgWcA6SdIU6tKdORWKgz6W7mtdtsjbYh 7t7AG9syNPRgEMq2M7SLB5/B+uUjHLEuoI3acnfslawfv2/0fdlGriRO4uEJgrhuncGl ac1Q== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=0ClY+l4BX4LTiRoznijY3897p3wEFpyGnwSnM0VogzoX6ero5NrG8kP5VKf+34nX1c Nb168y77cp4ZKJ6ZTveKBFAx6ptc3iPDAWf5Z3H3HmKjSVpokYPU75rM6sa1PlCZ9vJB 5uSN/e0pnyEDLDhrjHePdeUmbhwbbCsv01CwW77iHf6KUHX7YK9CQYUAWmNGwmKMsJ7F h1yzWN1VmJ7MoeNytqWBlou3xTBGhh6K2zDP87iwpRz/ijH67GLhilaslndIy1DFV4jj wGTzryUt4pq6TN2AHwMIMYK5/ZKInUq3LfvcI+44Y1eboGie9SvkRFKq0FKwPm0/kioH gvTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tYaisyG9; 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 n7-20020a170906b30700b009b2849aebcfsi5965137ejz.752.2023.10.10.15.35.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:35:21 -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=tYaisyG9; 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 56A0E3830B74 for ; Tue, 10 Oct 2023 22:31:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56A0E3830B74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977061; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tYaisyG9Zl47744vEcUkhiQH9nK8HfrF9LM4CEJDkFII9lqXxCdChXTafdLT6pAzn 4+Fqtww3iVDc+paAQqef13xR1CETp0tWs2c82PoW0+zFW4nc+bJlHzJcQy68oU0gYr TKcE3wos45u9J3LKYRyoG4cEr59dLPA+O/SSVXl0= 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 148D53875441; Tue, 10 Oct 2023 22:30:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 148D53875441 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 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 39AMNVlI007067; Tue, 10 Oct 2023 22:30:12 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnay8u5qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:30:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMTf6v014410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:29:41 -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 39AMFOUU024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:29:41 -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 v16 17/39] c++: Implement __is_member_function_pointer built-in trait Date: Tue, 10 Oct 2023 15:10:08 -0700 Message-ID: <20231010221520.3680267-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: wNkChiLn_uLs4ddHAwAZXEhU5LeO-WKU X-Proofpoint-GUID: wNkChiLn_uLs4ddHAwAZXEhU5LeO-WKU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 clxscore=1034 mlxlogscore=777 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779409691968289421 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 176 +++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_function_pointer.C | 31 +++ 7 files changed, 131 insertions(+), 88 deletions(-) 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 f0d3f89464c..d0464dd4f6a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 3775b11283d..b28efbab322 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index dfd60cec6e6..d3d4bdf9799 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 111, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, - 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, - 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, - 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, + 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, + 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, + 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -116,132 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 52, + TOTAL_KEYWORDS = 53, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 117 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 75 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false} +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, - 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, - 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, - 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, - -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, - 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 51 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, + -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, + -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c4880d8a33..4d521f87bbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Tue Oct 10 22:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp176363vqb; Tue, 10 Oct 2023 15:38:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEN9Kdnba6sdoIxeV4ghXLqlWYcwTXAUiI7Bgam3HSuWTXOGTTBB8HGh/D0h/8bTvRjsNHu X-Received: by 2002:a17:906:748d:b0:9ae:5513:e475 with SMTP id e13-20020a170906748d00b009ae5513e475mr14971308ejl.9.1696977482210; Tue, 10 Oct 2023 15:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977482; cv=none; d=google.com; s=arc-20160816; b=msEGRE0ucZjvAClcEM5lWfcPbxckLtPJUW2OXL/OjoJW0gf5Gq8hpdOw+1OV+efaPe ozkY7P2TIY8A5fnyWWXadInrScMnERr8J4JflFh061O76LRne2nRWr15KSdhWlepuuHt N/7OiCuwiAMPLVQvrQDPEoxer1HBEziflSwX7IieHz9G7a9QPVDE6292ye0zg3/xj6+R WK6b7tKbaIgJsjsmGZUBGvgl/ynXZh/NEmzxTuQg7qvzjJ9bRa1uIGobTA9/oFU11AQf h8qvf9w7InSwI2Zx9vzKSVGxbTTPImDib8YBt7mGQJdI579V8xmXhfXCU2y1sIxa96JF 98gA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qvcUSKVMagxQWyfLglInz+ylfJjWOXgIX1ifloPnZJ3v/M0gcpjhen9qvnAXxSxDwc os6HvNfX3b3Ajk4t0rrbXftP9aqkEwZG5xqkHXDD6KOE0iGrJk6Zb7ncdJek9A4DX3Qx H9cea5Yjbs1/fIzanybB8qeOl1DxzH1Rn8nDoZMwVgZqssKkWyhAchP6YRmEwaQqu/y1 VUbqn8+5O/HJwIvZUQqMZUHnINOnKS/IWC16wCVsTvbKkxlyThr+izIdyIY6WUo/RPd0 aAE42PbzIqzfoEn+9bso+hb6wkhHtuq3NNpa+HGdNT4+3jmGPlNeGXi62tor61IpA3YP Hdsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h9yqnj6U; 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 lw27-20020a170906bcdb00b009b91a4f2299si5672230ejb.971.2023.10.10.15.38.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:38: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=h9yqnj6U; 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 8FA82389839F for ; Tue, 10 Oct 2023 22:33:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FA82389839F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977180; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=h9yqnj6UHYfqYAjc5bdARPUqGvTexr/33fVNx8MpnT+ArDDxP/IVbg7vUro2QtI2n wJ0mFTj/VPGD8zNDLcTSA++YZXDHg86B+hE7+X5i/ai6KcLBAYz1t6Lj32N+qWDM5h WaVGc1m7NfRrqjr51EWC+sPg3CHz1bE48uQk/Y1E= 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 12627388E823; Tue, 10 Oct 2023 22:30:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12627388E823 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 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 39AMMalC014398; Tue, 10 Oct 2023 22:30:40 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxq8j0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:30:40 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMUBPI031699 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:30:12 -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 39AMFOUV024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:30: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 v16 18/39] libstdc++: Optimize is_member_function_pointer trait performance Date: Tue, 10 Oct 2023 15:10:09 -0700 Message-ID: <20231010221520.3680267-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: KkJ6bnvhDVdLInSkAgBWcu5DNnTbHk4u X-Proofpoint-ORIG-GUID: KkJ6bnvhDVdLInSkAgBWcu5DNnTbHk4u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=666 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776995423218726551 X-GMAIL-MSGID: 1779409860067854224 This patch optimizes the performance of the is_member_function_pointer trait by dispatching to the new __is_member_function_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_function_pointer): Use __is_member_function_pointer built-in trait. (is_member_function_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index d7f89cf7c06..e1b10240dc2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -588,6 +588,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) + /// is_member_function_pointer + template + struct is_member_function_pointer + : public __bool_constant<__is_member_function_pointer(_Tp)> + { }; +#else template struct __is_member_function_pointer_helper : public false_type { }; @@ -601,6 +608,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_function_pointer : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// is_enum template @@ -3222,9 +3230,17 @@ template template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) +template + inline constexpr bool is_member_function_pointer_v = + __is_member_function_pointer(_Tp); +#else template inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; +#endif + template inline constexpr bool is_enum_v = __is_enum(_Tp); template From patchwork Tue Oct 10 22:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp175829vqb; Tue, 10 Oct 2023 15:36:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfpXu0XnRAZqe8HwZfgRLb4D+OKjnwVRSnk1++rJ5xVrLDeO1yebWMXmFHKS0etc8o8qGx X-Received: by 2002:a05:6402:2031:b0:52b:d169:b37a with SMTP id ay17-20020a056402203100b0052bd169b37amr17860470edb.28.1696977404766; Tue, 10 Oct 2023 15:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977404; cv=none; d=google.com; s=arc-20160816; b=qh2dBGG+qrptKIo14VJsJgl3aIiEKHuxRU2dgtdmeQ922bZTzaCUFIc63PQI9k9mg5 Z8ZW/U8WtjFbqNzoB9ChKotd7fcjhMTNmO8jUZXsYYhKZKI0ALHhrI5jSgCj/SAm5QUG 9FtF72ETfk8w4C2nuvKzzjej/2E7AgDbmB3DTKxOWiqP14fq9EI1ZL7YyJqt6xEwNCuJ v+CqpRrPOzKyHhn/ssZJTdw07BjVAR8nBCmWpp+gGeeBRS0MNjsFgsNFELJ7pILzWoRv nJu5sQIJBaAyEjHnQ3dIA11rHYRXKpzKrqL17e4GuhyoM2Ao6gwwZCjHbqJJjDR8FVqQ YjaQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PImz5ZCVYw/IxltC9mKM7FWxh9UAbYs41q49F0YeOCKp2Qm5ZSGWfqn1RhCr1nMnmt bbz6FYCj3ImJVI6XOTpi1n/NIz8T0mtdKW6HYXdULTNtP4851J4kuXs5y2WWNsh8FSob n0ehCP3C73VZBgHKD/nzL3X6S2/ddJRqpPBWx819DV032UdXH8aMdntwhQ6phHEvopwe Y7H/jr/3wsUdVDzNBous7HU/+OsQHNtXODCGLaRCrNriTxlFgyvloxYJM75afWt+b07y W33LytvgVVO8fP2y7jbhyWYS8VsgtSwwvdY+9uTSZDRXeLx/TTaIJSJ3fImYmwbUpPip Da9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wGr35S1s; 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 m3-20020a056402050300b00537b067e459si6011602edv.477.2023.10.10.15.36.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:36:44 -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=wGr35S1s; 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 480093894C12 for ; Tue, 10 Oct 2023 22:32:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 480093894C12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977124; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wGr35S1smiyWNPGlqui8WKjTfwFENR3YAOQ//kfivXT5Q1PKAK+0tJIepaH52KlE0 sc52Azek9KUUq2ROk5HHSdUDd2XWIvEGFl/3sei0c15on+MJCWAJc/IxvbFrdbBzLv cczRk1jwT2WK70zw1RgPjaQ/TCigQ6scSmHjxIqo= 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 CDDFD3830B75; Tue, 10 Oct 2023 22:31:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDDFD3830B75 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 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 39AMOt9U031525; Tue, 10 Oct 2023 22:31:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tncaq1vrs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:31:14 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMUd42031789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:30:39 -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 39AMFOUW024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:30:39 -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 v16 19/39] c++: Implement __is_member_object_pointer built-in trait Date: Tue, 10 Oct 2023 15:10:10 -0700 Message-ID: <20231010221520.3680267-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dtPxFUl1goeNMbRbBv7-KxAfrk3Dvfle X-Proofpoint-GUID: dtPxFUl1goeNMbRbBv7-KxAfrk3Dvfle X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_18,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 adultscore=0 clxscore=1034 spamscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, 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: 1779409778855593933 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 62 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++ 7 files changed, 74 insertions(+), 30 deletions(-) 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 d0464dd4f6a..98b1f004a68 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3759,6 +3759,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index b28efbab322..32199a1fe9a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false +"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index d3d4bdf9799..799fe2b792f 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 53, + TOTAL_KEYWORDS = 54, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,57 +125,57 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 76 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,25 +185,25 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, @@ -211,12 +211,14 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" @@ -229,7 +231,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -240,8 +242,8 @@ cp_trait_lookup::find (const char *str, size_t len) 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, - -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 + 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4d521f87bbb..9cbb434d4c2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Tue Oct 10 22:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp177960vqb; Tue, 10 Oct 2023 15:42:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwmkUdoeb5pc5t9QWxpIbDFcXHnyNf1rzkfYr1zLKyJlSbqa48ToGF0NnZBMcZ6FW4aGiv X-Received: by 2002:a05:6402:50b:b0:51e:2e39:9003 with SMTP id m11-20020a056402050b00b0051e2e399003mr14972222edv.40.1696977744394; Tue, 10 Oct 2023 15:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977744; cv=none; d=google.com; s=arc-20160816; b=zZYmhnuUY13fPSlKD5ZoZAelxMNR8UP5s5BlX6qx3T8rrLsuf+L8mqQwiffqO63SNi 6TPCrwmIPEBrjZC/Kp5c26lkSucDGFdZIp3TpQInanCD9OtKFzLjE3u3fG+olli0cUxa ir51VwTvv6Fdyu2L3UBfMB3I7+3tVFtvjjotKARV3KDTSKRGQewgYc58kmRQL9IoC+th 8oZ8HgJQ89WM1JqkNRL9IYN8K8FKsjwOJeymS1nAXWxcWHi9LV3PkSukBc+RAKrkROj0 sQPzbhAnsyyfQehQSZLHVSAHtOvkwG3cdm2Ohn2FPv2IpMzjEPsrVUX7PofKsJUbSF6T mJcQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=sqAI+HjtoRCSj8u/OW93RvCVW9KCvPdp598RkkRpna4mWTkaudv/QNT3hluWNe5ozi jGELLv9H6UQuqh5x6gxaRglULVs3Id7M4Kb8Pqvu1nTTRzG48qGUV2SRnCDRlbY1M/4O bZ3UuzSTHluRb6waJmsUebbYxW8Kgs1KhFcmBHyDZoOL3J+GLMxvtWG6dHUUj+Srd8fy V7APaGYIqyEt2QVNvI25fmd+TB4rYUr7J34yvQ1++mEIunALwQz36dQp9G9g1oeUr5rI VZkoq5W5s8sl4nxJFeRSkNIvZxY3idMbc/zKtTffOAyZ1PJtsy0H8WH17tto5mVJXblx zZXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JfT38XxE; 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 d11-20020a056402516b00b00532ac8fe704si5518506ede.601.2023.10.10.15.42.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:42:24 -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=JfT38XxE; 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 D3F7A3952484 for ; Tue, 10 Oct 2023 22:35:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3F7A3952484 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977313; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JfT38XxE/IprGjZ26+jgvUTDDlu55zcmzzK47KupQVogMHJxUL9tBG7rrtNIp/fXw KQoddG/Os1Mp6eMJA/WXvjt8rsYPyGO6pwUifrUlcsEGqr6/t+eIs5NVmedHq9hxDi EigmliYDSjpe6lm+CSLEcuJLnOugKJu9KdXWRsSc= 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 993AA388202F; Tue, 10 Oct 2023 22:31:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 993AA388202F 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 Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMSSRv000727; Tue, 10 Oct 2023 22:31:17 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnamp377v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:31:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMVAcJ017343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:31: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 39AMFOUX024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:31: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 v16 20/39] libstdc++: Optimize is_member_object_pointer trait performance Date: Tue, 10 Oct 2023 15:10:11 -0700 Message-ID: <20231010221520.3680267-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: KuZhUdTOv-amq4oB86Ba821ebTSAZBP0 X-Proofpoint-GUID: KuZhUdTOv-amq4oB86Ba821ebTSAZBP0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=594 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100173 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776996522370919550 X-GMAIL-MSGID: 1779410134813498661 This patch optimizes the performance of the is_member_object_pointer trait by dispatching to the new __is_member_object_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_object_pointer): Use __is_member_object_pointer built-in trait. (is_member_object_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e1b10240dc2..792213ebfe8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -574,6 +574,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_rvalue_reference<_Tp&&> : public true_type { }; + /// is_member_object_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) + template + struct is_member_object_pointer + : public __bool_constant<__is_member_object_pointer(_Tp)> + { }; +#else template struct __is_member_object_pointer_helper : public false_type { }; @@ -582,11 +589,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_member_object_pointer_helper<_Tp _Cp::*> : public __not_>::type { }; - /// is_member_object_pointer + template struct is_member_object_pointer : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) /// is_member_function_pointer @@ -3227,9 +3235,16 @@ template inline constexpr bool is_rvalue_reference_v = false; template inline constexpr bool is_rvalue_reference_v<_Tp&&> = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) +template + inline constexpr bool is_member_object_pointer_v = + __is_member_object_pointer(_Tp); +#else template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) template From patchwork Tue Oct 10 22:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp178858vqb; Tue, 10 Oct 2023 15:44:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjPrhM1Y8EmTiLjvGJy3ez8f4SiHa6e2a/xZIBhKr7LkCr+2z0wqDTmZzOMXCvVFdjDEMH X-Received: by 2002:a05:6402:1357:b0:530:8801:47aa with SMTP id y23-20020a056402135700b00530880147aamr17528668edw.19.1696977893741; Tue, 10 Oct 2023 15:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977893; cv=none; d=google.com; s=arc-20160816; b=LKq/V4jpBmjedrZkeCkJEXeT9GfnxUI8JtG7HwGd/39xBfHg7rwxwQ3HBc/znf2lnz pEIE4kva3r6eoW/2fSEwTiI7vsafiReO/NNVRYqXvQxS8QaOHP0LKpYw6f0trKldOke8 y0kxUUjBiOAR3mEmum/6ZrbEHgPV2kb7Ap4QhznadVq2j24bWMzB3I6yViiDqK568ueJ yyNG1vZdhILKYX+ZTlNezx+Pu4cHfjmVkxhhuypwakHDNXW6hM9n6F3nAlyqgwzk5r9M YjK1PG6YxkatNYU2Upw40priPlpddwiD3ZVbHWx4ftJYEr2VIuZMunTf4i+wVQxuzMIJ C2rg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=NTS9EIyOb3hXZffYTnNWcilZk9nDJ94aRxhM2oKuSJOZPJy/VGYFooAxTgiORghE7w ESzCOQBcOG6n4PaK+mF3UC8I6t/Ql+fq3B2FvJl53mIBpGHbrU2bHUrvSgz/FRcOz8r8 cw9AU84koaxduxs+19nlHQzlv8+WZyJt/tXTJC98Cqv/5RtPSvZS8QJo+hgTX1ZgJylR yts72qgVKFUVzG7X9bFJMhaHJKPNjgUgbYi71DJMjFA2BvAEv9ZLFPgEhwbf+MeasPGT /SZaOkFD8NNszD0RA16j4sqyt2+E9P/j1L7yFZdmVKjq+T/moS0XUxhmcKaSJyfgScri rKKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vsftqIc7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v6-20020aa7d806000000b0052364eb020fsi5919462edq.239.2023.10.10.15.44.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:44:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vsftqIc7; 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 A02413959E72 for ; Tue, 10 Oct 2023 22:36:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A02413959E72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977378; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vsftqIc7xvHT5uY8TSOgeFTe/hx4ruwYnD9v4d/20LYHWfZg0xmW/5+sNOLyY6IhW NwO6lQ1vsOOtdCj7rRtuMsAWAl80jOXRPV5QlcMI3OcdA2jT0G7ZTG93ANbFqS++// GqDNbSRhlgowm0+gy/JgDqhtMnQaZG0DyS7i+6DI= 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 D611B3894C3D; Tue, 10 Oct 2023 22:32:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D611B3894C3D 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 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 39AMTIm0027678; Tue, 10 Oct 2023 22:32:21 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn7xkd76k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:32:19 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMVePK026446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:31:40 -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 39AMFOUY024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:31:40 -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 v16 21/39] c++: Implement __is_reference built-in trait Date: Tue, 10 Oct 2023 15:10:12 -0700 Message-ID: <20231010221520.3680267-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: wqnrvPsujpMMPYKx1EtKIgZ14P_pZXpR X-Proofpoint-GUID: wqnrvPsujpMMPYKx1EtKIgZ14P_pZXpR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1034 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=915 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779410291653141999 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 113 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_reference.C | 34 +++++++ 7 files changed, 104 insertions(+), 55 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 98b1f004a68..5cdb59d174e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 32199a1fe9a..5989b84727f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 799fe2b792f..f0b4f96d4a9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 94, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, - 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, - 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, - 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, + 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, + 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, + 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101 }; unsigned int hval = len; @@ -116,58 +116,58 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 54, + TOTAL_KEYWORDS = 55, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 100 }; static const struct cp_trait wordlist[] = { -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 77 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -175,7 +175,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,7 +185,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -207,15 +207,13 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, @@ -223,6 +221,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,8 +231,10 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 82 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false} }; static const signed char lookup[] = @@ -241,9 +243,10 @@ cp_trait_lookup::find (const char *str, size_t len) 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 + -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, + 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + -1, -1, 54 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9cbb434d4c2..df720459458 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Tue Oct 10 22:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp180439vqb; Tue, 10 Oct 2023 15:48:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVQ5rkAW9ufoe3baHZa6G1GQr56NoLVsIF53EVOSjC3C1Osu6wh9GIgASKabv+RJBqS/xm X-Received: by 2002:a17:907:1b11:b0:9ae:6ffd:bdf7 with SMTP id mp17-20020a1709071b1100b009ae6ffdbdf7mr20853031ejc.39.1696978133669; Tue, 10 Oct 2023 15:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978133; cv=none; d=google.com; s=arc-20160816; b=fDyH+d+soM/OrdUgsRpelacEZvjBqSj3/1qaO4br/hXCeOQd7dmQZ54f1nKMG4JwCl uTSkRg0zS2Yt9vXOMZcc3zi5LaJ0W+dvw/n+WBYB78EsT4fdpvr9QIw6ik063hQs7qZm ZS869X4xXt5vMZXMhjH5Rf7KDLZy1s+nQvDy7eeV9YvPuHICHmQZ8TcIA7y/M/KRTLxa 6X6fpdvNVhiIAixBSUC+xqgEmJi6p0Q8k/jOptRwRjTukd7w96Gc7UH0mL/ns5FhxOCJ gzXn0fInX+3JAKAEA8Kw0Zje3CMDRjhchYNTru38B0bPr2jSvfGLNXfeErfCtDyZmBBH gz6Q== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=VTgo663A4Udh6iIvOqdQE9ALsqYxjt+VcuiXYmcJkfZZDJIJwRw8m8Eqfz7CunY0b6 mrSH93eE9JxKVkjNcOeLHdZmGufGk0t/O27+We+K1sYilOnz+PsWFl94g6er8EkuuQaT fDHCnExfsMBOgSgm0NZ2rHKGDuVwwXVamtenQv7eDRUVnbysARyXskNR4NgTTKm/p/4d HnwBRFgNSUWMPjVfIKma3RpEJ315XtazeYtNiPNPuNtckgBoKnK7PqHO/klY42qRrUcx awf+FA3hCGqRPruU68CNobN63isd87iZ5ybDsDnT58BUCjnW7u8/qFc3q+ujI5MN1Bhy zjsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bnDmE1vo; 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 k19-20020a1709065fd300b009b274ce51e2si5513132ejv.280.2023.10.10.15.48.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:48:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bnDmE1vo; 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 E3A95385559E for ; Tue, 10 Oct 2023 22:37:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3A95385559E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977476; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bnDmE1vo3qeuhItiJBX3l7DUQaEmWTdxqFbx3/+Cbe1R8tbuogKcV8tNat6pW/xMp s7Yjzq7LKwQp8BTlqPzENlozPjVK5vh1MHWU+dg2xGWUC1tge3rPmGEDukVLBJmeOM Ic9vu2Fz9i2fmehoxIc0W61o4iJ/JLvp2u/zTkzE= 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 93196382D820; Tue, 10 Oct 2023 22:32:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93196382D820 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 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 39AMRw8e026558; Tue, 10 Oct 2023 22:32: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 3tmtf3rkad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:32:51 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMWCFx015182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:32:12 -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 39AMFOUZ024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:32:12 -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 v16 22/39] libstdc++: Optimize is_reference trait performance Date: Tue, 10 Oct 2023 15:10:13 -0700 Message-ID: <20231010221520.3680267-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: K7dnJwfGoQum654JfiHRGGvypnJ-zcQb X-Proofpoint-ORIG-GUID: K7dnJwfGoQum654JfiHRGGvypnJ-zcQb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxlogscore=659 priorityscore=1501 clxscore=1034 lowpriorityscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100172 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776997499735714658 X-GMAIL-MSGID: 1779410543378789794 This patch optimizes the performance of the is_reference trait by dispatching to the new __is_reference built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_reference): Use __is_reference built-in trait. (is_reference_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 792213ebfe8..36ad9814047 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,6 +682,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -696,6 +702,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template @@ -3264,12 +3271,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Tue Oct 10 22:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp177330vqb; Tue, 10 Oct 2023 15:40:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIc+Om0Io1fV37ff1O0QQVsnETDAQBOg20PQ7vB0vCOtgCRj8EVLryz/2Hj7oUUQfDrsYY X-Received: by 2002:aa7:d501:0:b0:52f:2bd3:6f4d with SMTP id y1-20020aa7d501000000b0052f2bd36f4dmr18388467edq.0.1696977637779; Tue, 10 Oct 2023 15:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977637; cv=none; d=google.com; s=arc-20160816; b=YQKZRkGvkznHzQ2cDftgOPXq/vWQdLA0xFAZxz3RUyrfWGBIrLxJeBquXW5WKjhCBW K4bvD9AQVwhwZEVZLP5bDUC9mbdgrlQEzsQWuAI4OL7gZViqjjPqMFeHO4S3ZT6JVUl+ Fl3yz30hAzFz4DSg+XM2tuq/arvdn7GA0KEtr0GIhICO2KOCDcmNleaW0oriQu0GDpTQ bnM/hg0gPx1GQecVUFLsrOgOwg3WKmFAPfXqfIkvV1fhoGN6eVj2p3JpLElHAx0ODf8E m/Af1R+dUonjcgaWRDU1WQglHbClCXzFELkoq0Iqg3GLuWGUwmDdEHE++Ez477L685uv KH2w== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=0st4M3JrJSeFydEJ1GpjbGCc5dlnMo6S/X03IsNSABQof1UDAw5xPMGD5UWwtEYLIk HP+OSVQKVATIR2QgRQjeofG/jV3IB1Wo8UTsWyx2KTrmYLJ3x6kKcqOsnBuFc7NdjdBU 5a2XMKzhFsD6ae9gAyY1Ugzu76ehWt1wzmnULh4Rty39Hi0bFWlSSlgQ5Dkhy2mch3Z5 8Jr8oy9bsT0Zt4DzO4jf/Gh8wIaOGaoMfgSJOaz5euO85wYSnjNLplzv4pN+5NKZev/b fennWanB9yAKlbs0IVKA3JSJLv8jNN0rtvA0Z9AluZTI8jjjPDMFo6Wj9Zhro3CYNdsi 1rWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CjqQftW0; 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 b10-20020aa7df8a000000b00537f329fec6si5677251edy.349.2023.10.10.15.40.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:40: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=CjqQftW0; 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 DEB953948802 for ; Tue, 10 Oct 2023 22:34:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEB953948802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977256; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CjqQftW0dBARsksEWtrc5AWxrNs5pIY+5Z+rlt9A6JXKW3RtUPcQ8rtEKYMl6mAL8 UglINRfz3awKL7XhbhfOggdKSbI8V/Snm5ZXELspcQpnQpc+7ew6S9sE/0i7CjjRuh 7DcdaMylCZrpAr0WylWYSEoOv5KqQK5096mV+B5M= 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 3626638618E4; Tue, 10 Oct 2023 22:32:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3626638618E4 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMPH1K014100; Tue, 10 Oct 2023 22:32:52 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957v9ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:32:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMWemo032346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:32:40 -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 39AMFOUa024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:32:39 -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 v16 23/39] c++: Implement __is_function built-in trait Date: Tue, 10 Oct 2023 15:10:14 -0700 Message-ID: <20231010221520.3680267-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: fpFj1ok6HRrYz0QV7dHVbtQ77tkVsNHP X-Proofpoint-GUID: fpFj1ok6HRrYz0QV7dHVbtQ77tkVsNHP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=936 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776995319714743541 X-GMAIL-MSGID: 1779410023547067319 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 143 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_function.C | 58 +++++++++ 7 files changed, 143 insertions(+), 70 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5cdb59d174e..99a7e7247ce 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3750,6 +3750,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5989b84727f..771242a7f45 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -50,6 +50,7 @@ struct cp_trait { "__is_empty", CPTK_IS_EMPTY, 1, false "__is_enum", CPTK_IS_ENUM, 1, false "__is_final", CPTK_IS_FINAL, 1, false +"__is_function", CPTK_IS_FUNCTION, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f0b4f96d4a9..b6db58e93c9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 94, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, - 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, - 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, - 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, + 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, + 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, + 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,113 +116,113 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 55, + TOTAL_KEYWORDS = 56, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 100 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 78 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,10 +231,12 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false} + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = @@ -242,11 +244,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, - 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - -1, -1, 54 + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, + -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 55 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index df720459458..4b8e80f3e62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Tue Oct 10 22:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp177243vqb; Tue, 10 Oct 2023 15:40:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvQrSF3m4SVYaY3dWTMlcyLO/HDujeRAqNgLx/JOxAyTbGitxiXR351p0Hauj2imWTcjWY X-Received: by 2002:a17:906:76d4:b0:9a1:e994:3440 with SMTP id q20-20020a17090676d400b009a1e9943440mr17473951ejn.4.1696977624673; Tue, 10 Oct 2023 15:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977624; cv=none; d=google.com; s=arc-20160816; b=yZRNYKpIyQhbovUA4Tluu34umJ22mCK1+X4LGVzUJt26tjfmNchNra/O6W1W1a6iPn ZqRpdFvQLSdlKp3LAaBZQBLBuFm2gID/1qxFr9Fvv0SNgHjcvOSPb68ueZurWYftcNte zJ6+QhoVsW35mGZeDkzebLCmB7ny9ASzV3XVNkLm1q75LKTwu1aZqZl+YNLWA3e58sek zL3HkDYtKFdFdsNb57QLxuHiN9N7s+AsgpBcvhAUjSifAFobIXi91hTBXiMRjFiYnfSS t8mSCNLZ+LxAPfW+pSsLqcUlMEmkjkzvJifzGe7mA8nzkwU/mgu8JLjpsY+bDKQcXAMX cIbw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=orDMc8xG2zQ7QNjJXh/5ECn8heU+MmGvisqZyfbv4DGm1r2Zb6tG9brfrBUANO5yn2 0+iXfjhsAbLadnYG89bywohhnF52du27cqb5nkCMQGZH0gbuB0f6zmZVNKR3lygvmBYA Z4EbY5itmUx69TpGu5qeNuz1jhEjkZrKqFkq91QxfJRs3FPzqYCQIi4xynwmE+nrl33M QBqR2Ledls5O5ChNua+ijADCKtjlRXYBoyUe6lQTeev0+z5HceOVDZFSKYwmSnzVswyY kngYrIA8+WriV49bI8WTdwcM9Dkv7sGDs994tuI3kkr+NC0GoMwHBDNRIvekXz9n2UOc XWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jwuoYbKz; 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 l15-20020a1709066b8f00b0099cd371dd90si5520655ejr.928.2023.10.10.15.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:40:24 -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=jwuoYbKz; 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 E83D6388A02F for ; Tue, 10 Oct 2023 22:34:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E83D6388A02F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977249; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jwuoYbKzQTi2ddaBi0kRLmhK60H48iwUsHOSEAsDby9A+O8K7CIzOe0/f3spguB/H 6PUF0n8FnFCp9mAKaPq+S7q3SDmjL0o4U/gFrR1LH8FfMoth9GqEnRokgDZKxdU7Yv vAGyBF6BVaLXb1HWxIyr+eoHfweVrv8AQL7LlpBA= 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 F3B6D3888C4A; Tue, 10 Oct 2023 22:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3B6D3888C4A 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 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 39AMJTAE030629; Tue, 10 Oct 2023 22:33:24 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnay8u6u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:33:23 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMXAuE023205 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:33: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 39AMFOUb024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:33: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 v16 24/39] libstdc++: Optimize is_function trait performance Date: Tue, 10 Oct 2023 15:10:15 -0700 Message-ID: <20231010221520.3680267-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: x-NCrzkJcl8nP8dVkYOHxkreJr5u3C1W X-Proofpoint-GUID: x-NCrzkJcl8nP8dVkYOHxkreJr5u3C1W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 clxscore=1034 mlxlogscore=583 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776997392552534413 X-GMAIL-MSGID: 1779410009866787403 This patch optimizes the performance of the is_function trait by dispatching to the new __is_function built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..bd57488824b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3269,8 +3276,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template From patchwork Tue Oct 10 22:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp178391vqb; Tue, 10 Oct 2023 15:43:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK7/YeDhvy5A7dEqk+S+9mTiln4PJJWTrnBwRBSdCb9PrDZdfopRNiuKi6VqcA+/L4nNS0 X-Received: by 2002:a17:906:73d8:b0:9ae:53af:c57f with SMTP id n24-20020a17090673d800b009ae53afc57fmr19611437ejl.65.1696977810247; Tue, 10 Oct 2023 15:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977810; cv=none; d=google.com; s=arc-20160816; b=Y6WbodFn/mc+xtnJja4IovaVF5Qb9CEcNM614ju2JPQ2dJ5JlcXW7tGCSILga6Ej8w 2bE0tJ8lA4Utrq/J24//ObC1xVPM5y6D+0UkXxx/ZbQkobbTxLeomy/j9TqgXlNqy+Eg nMesbBepnSYgtnpUhejgA3OuirHcBcJK740FVJf2WDr1Ion028gpYh1OiWangRrbjjqY UDwUIcLKofJVVrsZHGYxs2aqpOq0aSk1RI6KEuqdzFG83fQBA8T17caS9/iRLkW1PHxV YYP4o/H0iYAy9i0uAoeA7WbWmFug7Cq0IX2ohDz0CoQFMAg5wd5WTypW45nHd31khI2A LX8w== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=w1kUEmyAGRegqRlwaLvD6qLKgLDFqNJKrm/gTQRZihcVk4BPykGGWyftCTNOOql3Mr uztIau+vZDj17QJ6dmLaRwTtD16uKaXFeGUKOpDy8IqVgr711jckIntNAQGIoZn1ROoz nT/eOj5a+VHR/32yA/paJkRstuxGzT2bc6HgQnUa7D0PUUemtn48U8qbn6fw+gykgoA5 ImNdJ9Tqb2Ef68xxdfrXYvaIKYuvASDHeKr8O0tzP2FtFZODcS6ZrNOM3yF7EXpA2XWa Bzq/dHtkTRYYvuibICvLXhScQ2X/2kgkzNvIO2oul2hOe9n6zPdzC5d4/k2dsKWwUO7A pl1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=se3SHiKB; 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 o12-20020a1709061b0c00b009a5f1a8c94fsi5590888ejg.361.2023.10.10.15.43.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:43:30 -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=se3SHiKB; 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 1FACD385CC8A for ; Tue, 10 Oct 2023 22:35:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FACD385CC8A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977351; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=se3SHiKB3Jgsg2c0p5lWXtAP+5KPdibWmVVIlY2l+6Z7RF4H7NuMPdns9LjJHKUjJ 7Ecn0JlKR35jRz6jGhd16HRr39MKBTiGY1NFecoPOxfh6rNEEUEUUClOZVrRhbXLON xR7Ieqgyvjx9AkBs6En/IroNxOlI/2HxtEr785P0= 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 B47CB3949085; Tue, 10 Oct 2023 22:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B47CB3949085 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 Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMUCe4007484; Tue, 10 Oct 2023 22:34:43 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnamp3880-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:34:43 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMXd1Y032635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:33:39 -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 39AMFOUc024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:33:39 -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 v16 25/39] libstdc++: Optimize is_object trait performance Date: Tue, 10 Oct 2023 15:10:16 -0700 Message-ID: <20231010221520.3680267-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Bojofc9YbfMxDn35r2-OgC6TK7_MDJIg X-Proofpoint-GUID: Bojofc9YbfMxDn35r2-OgC6TK7_MDJIg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=794 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776995944979792207 X-GMAIL-MSGID: 1779410204331468530 This patch optimizes the performance of the is_object trait by dispatching to the new __is_function and __is_reference built-in traits. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use __is_function and __is_reference built-in traits. (is_object_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index bd57488824b..674d398c075 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -725,11 +725,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ + && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_object + : public __bool_constant::value)> + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer; @@ -3305,8 +3314,17 @@ 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_function) \ + && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_object_v + = !(__is_function(_Tp) || __is_reference(_Tp) || is_void<_Tp>::value); +#else template inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template From patchwork Tue Oct 10 22:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp178281vqb; Tue, 10 Oct 2023 15:43:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2mO13tq8uUJA3ceJM1aPwgyDkLJKMq7UrYFCLzKWxRHBYxV5L1HuWsMIxNCUlGW9hPsrW X-Received: by 2002:a17:907:78c7:b0:9ae:7548:742 with SMTP id kv7-20020a17090778c700b009ae75480742mr16769436ejc.3.1696977791836; Tue, 10 Oct 2023 15:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977791; cv=none; d=google.com; s=arc-20160816; b=oOYZ7uGurXI4OaEj4iPbw+MkrjfEBgp32PidIUuMnxn4ngYvaLjMd3TmmaF8icl5Qz NgXK3bRVeM/1l+OpW3QFmLCRDfo2+O5urxUlK6q1LCvO6958Pe7ih0tqpWjrGKqcVl/e dTivlAvIo2/ucUN7ICMKOaDqKdrteFE2IQA/gW0y2JuXveZ2rORkIFXSTKyMTpEeu9Sd bigqSkPAYHYq0PAPQQauquTAsvH9j266jvBt+PxYE5OHV8QnejnEipp7Z6Eg1hAxKFOc nGTJbOwRRCbTzYBUBmlMq/Jt5xQmTtIavrU8yiu/FGXoR9fkIZBrqrv4zlfQvlfCZ4Rz T4yQ== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=itQ9IX9EhUAthI1x8locXinKYz+MZqNZmWe5019Oy0SuGV87oGhgcLQ4L0rWSzepRA 06oycNm+5NlmEjmmX18stbwshbqigqReuJ0uWPAy8hcpOtQaY1ksnK5DIfZJng3wfO+3 JynypdMGz31pCCHuYBNmCMeoPNLz/oKntDz3qB234x5DCzfQgRHGU98RHnhnk/KLmTA/ nJpwPG7waLe3lslvDOauFQJl84HB/I2efF3hHeQnKG4JXA0+ltg+zYqAs1isInQSNbf7 vI9Im2tGnKp/AB2siPRVoMPII/c+Mgt6VW74cw9BLrITxW5YAN7TZm72UC750dlDcTLM ee2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yJsr0bXH; 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 g11-20020a1709064e4b00b009ade72a8e5dsi5724895ejw.585.2023.10.10.15.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:43:11 -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=yJsr0bXH; 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 D12D33881D35 for ; Tue, 10 Oct 2023 22:35:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12D33881D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977339; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yJsr0bXHXIKQzeBnQ6zAEDex5LSIiKZuW2rxoMeLzQmXzei5CEcBjQAPeJJV95Pre bF2teW2+KJw9HsV53VE9Hjo9g8q2xQWGR8ki01PAThEkzlVbiPDpc+axhqrkFDAAJF cyohQynlFHl5Ban07+MIhkaIl8zm1x3e+svtTa6s= 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 0E9A039484A4; Tue, 10 Oct 2023 22:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E9A039484A4 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 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 39AMOxm8008953; Tue, 10 Oct 2023 22:34:43 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnakfkbb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:34:43 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMYBwT023456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:34: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 39AMFOUd024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:34: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 v16 26/39] c++: Implement __remove_pointer built-in trait Date: Tue, 10 Oct 2023 15:10:17 -0700 Message-ID: <20231010221520.3680267-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: WpZXg3ZUWLA72nZ2wkMPzg0HAQ4K0hS8 X-Proofpoint-GUID: WpZXg3ZUWLA72nZ2wkMPzg0HAQ4K0hS8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxlogscore=585 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1779410185109744285 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 32 +++++++------- gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 6 files changed, 78 insertions(+), 15 deletions(-) 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 fa79bc0c68c..2add97ae749 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -97,6 +97,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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 771242a7f45..8fbd67788d5 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -77,6 +77,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true "__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_pointer", CPTK_REMOVE_POINTER, 1, true "__remove_reference", CPTK_REMOVE_REFERENCE, 1, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true "__underlying_type", CPTK_UNDERLYING_TYPE, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b6db58e93c9..ad2c2a2d250 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 56, + TOTAL_KEYWORDS = 57, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,7 +125,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, @@ -137,17 +137,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, @@ -235,21 +237,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, - -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 + 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, + 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, + -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, + 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 56 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,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 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Tue Oct 10 22:10:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp179257vqb; Tue, 10 Oct 2023 15:45:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6IwI6PWlmgEjsiotHEX7kbug44kWhy6SyasfGUW2a4jY/tCrWI3v/zMhR7yKsNTMfN2Sl X-Received: by 2002:a05:6402:1250:b0:533:e314:20dd with SMTP id l16-20020a056402125000b00533e31420ddmr16554788edw.13.1696977949277; Tue, 10 Oct 2023 15:45:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977949; cv=none; d=google.com; s=arc-20160816; b=j/kX3IND9BvZvHNR57Xkfe8E+Qe63q/fGRw2v22THBwULsTOoQjV8N/qBvBrhNPWMH SUrLgl3IZATGuEvnbBrvfmNM6UYD46dJvfZA9yfaz1UPevgmx7mAzIa4rw2j83W3dVti fiVGqk4LktskVOlP782SMmZzteT5kWjUDqyiE7FbGTNduaoT4udTjq9NH7h5Wetuf5zS GsFdQc7N5fNE/+7DqH+zQ5JkGF67ZMPfFBurTnXwjNIsUZ8XP629a+Xx1y57+tvZMqK2 5GOAF0bItjD1/Vsz8w9jkfPWe2gwg34hII52vDQLPcng6h/pY3Gficyxqz/44ds35o8L tV0w== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Z+FIWdeJj7XzqvYAYhjiaQFIUU8Ky3fUKbX61g+ucfxTWkyq2P/+4IFDnglwRmTI9Y w0qo+VutlWIZpi/HTYixzuQOwhBvgBpZWEjk1pU0xizOK7ZgVVjIVwrwpGHfIKzPrReS /uwL0DO1JJvedEHhPFloWyvEEQi/Hj1hm8QzxBohwbfx4c9w2UUxFYd0u9KO/U5P6fxr XriXVg7RH4n6BN1mLtOxfMxJckmiwO4vknuwk1xCNwuXK0HasG+tkwMzz+oxtfhJ3UpX ED/L9C+7G89jOJJxSED+R565itc/VnYfP3FCIiNkCBDBL76EnYj6fFtEKmZDW7aCfPDv gqAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ql8yNEYO; 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 j17-20020a50ed11000000b005347a0620bcsi5915379eds.34.2023.10.10.15.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:45:49 -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=Ql8yNEYO; 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 A6D01395BC2B for ; Tue, 10 Oct 2023 22:36:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6D01395BC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977399; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ql8yNEYOCfeOq1jpwji+posjJPNToymqtkBQp+sAURLSyR1HopOuaSh4Man3jRC3a E6fLkHFUyeUgJAbguw2jaHoh/IVzWJwq1SdsS7P+0C6GJ+9ezht2rk8HITPNEKMq1k JFq44IO+k2777AvPekFKcG6B+4efs/RVIdUwCDSE= 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 3527C388B6BD; Tue, 10 Oct 2023 22:34:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3527C388B6BD 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 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 39AMYHlI031604; Tue, 10 Oct 2023 22:34:43 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmu6qrgvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:34:43 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMYecE000447 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:34:40 -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 39AMFOUe024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:34:40 -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 v16 27/39] libstdc++: Optimize remove_pointer trait performance Date: Tue, 10 Oct 2023 15:10:18 -0700 Message-ID: <20231010221520.3680267-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: nZoGO9sPcGoMs9y3-_k816Zbm5BAXBkL X-Proofpoint-GUID: nZoGO9sPcGoMs9y3-_k816Zbm5BAXBkL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 spamscore=0 clxscore=1034 phishscore=0 suspectscore=0 mlxlogscore=666 impostorscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776997286578618893 X-GMAIL-MSGID: 1779410350479246582 This patch optimizes the performance of the remove_pointer trait 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 674d398c075..9c56d15c0b7 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2105,6 +2105,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; }; @@ -2113,11 +2119,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __remove_pointer_helper<_Tp, _Up*> { using type = _Up; }; - /// remove_pointer template struct remove_pointer : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>> { }; +#endif template struct __add_pointer_helper From patchwork Tue Oct 10 22:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp180243vqb; Tue, 10 Oct 2023 15:48:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKxDaVLPmLgHmKd+UMHd3FVzZYocbyYtk+f682KoRXv/DJA5LGLoyHIeubmBklhB04ROGQ X-Received: by 2002:a17:906:7389:b0:9ae:406c:3420 with SMTP id f9-20020a170906738900b009ae406c3420mr16412375ejl.30.1696978098609; Tue, 10 Oct 2023 15:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978098; cv=none; d=google.com; s=arc-20160816; b=GK/N5fQal9PXa9HMQ9tmFv9G9sOK3zKq6ojXkLcBZyeu63FH5scIZTRNCFS/NThwM9 37+HV4oc43aTorOdh+HE7SSUx3WiDl1F+LCLGcPzaD3EQmyEb6+r9ZMQdL3Z+cpEn+OM NJX0ZyAoQg/ejCgJNoMcELp87kxs1SsWi3x0tju9L3oM29dA3DjHrAwHVvxTVvykANii XDMtHeR2G2EV0JsTimqp9BuEkB68FodO+ZZUYU2QxKqBs2Gn0OKKeespbfiY7hwJBiJA D687y5F7z6pW0K1jlAxq2iioV2GHFAVmaI7cipBEaW1JGT8s00p01lcY5jKBk7ALLe7w p1Og== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Zw7FcACt6fwTyEV8BsBIJpmWN8IBoXWy5KwvLOECg9s=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EDRbx4r7vnU2ec5NcdkAd/nn3t6NJQ8pXlORH3fH5BdOOZrYv3LcdDdQtmmnoktnvS cla4oXCh0lLIT0esORV5XnpaN5QGzkDijSQDaJGkEKWcL6TSWbNfC1E5eXiNsu2GJpNw rgB739YDGrLNvGLvcLXwqoG8hpLhI9DMMk0T8kbdblnNLFZOz+5lX8cjxLAi/pLOdlRB /aHdHxFlyt3UxhfvKsjk6npcuAtHU0dbMjaN5UtOJ4nSdVksQ8eByUHBLLR2unChDLVf Yaw092UMOV/xQmwouceL7biU3jcEsVMSerqIXY0jdxxQaBDtPUjIW8/yO2I9vk6EnP9K mztw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DlpPHGbg; 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 m22-20020a1709066d1600b00992e91cacc3si5665582ejr.44.2023.10.10.15.48.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:48:18 -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=DlpPHGbg; 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 9C7B639960EC for ; Tue, 10 Oct 2023 22:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C7B639960EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977461; bh=Zw7FcACt6fwTyEV8BsBIJpmWN8IBoXWy5KwvLOECg9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DlpPHGbgjhgiwXoiZNRVjJS+h0IVdJFBW9VePC6a9Pcrp53WP61X3vFn6VV7g8ufr nsmTm97SBlrjeT05l7ag7caT+seFDICt8zTA5EPzu0wHwTEApU2OJHGCXUl9jR1i8w xQ0dR4trqc4MRaQoo1AyKmFWXSGxwoq1yyOX0eJk= 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 BAD65395249E; Tue, 10 Oct 2023 22:35:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAD65395249E 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 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 39AMInOM026068; Tue, 10 Oct 2023 22:35:15 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnakfkbed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:35:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMZAYf022353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:35: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 39AMFOUf024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:35: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 v16 28/39] c++, libstdc++: Implement __is_pointer built-in trait Date: Tue, 10 Oct 2023 15:10:19 -0700 Message-ID: <20231010221520.3680267-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: xw3wbxoUK0cKUVTjxK7bkpCGGmErEKBT X-Proofpoint-GUID: xw3wbxoUK0cKUVTjxK7bkpCGGmErEKBT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776995712601902354 X-GMAIL-MSGID: 1779410506777860828 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * 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. * g++.dg/tm/pr46567.C (__is_pointer): Rename to ... (__is_ptr): ... this. * g++.dg/torture/20070621-1.C: Likewise. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Rename to ... (__is_ptr): ... this. * include/bits/deque.tcc: Use __is_ptr instead. * include/bits/stl_algobase.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 155 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_pointer.C | 51 +++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 22 +-- gcc/testsuite/g++.dg/torture/20070621-1.C | 4 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 6 +- libstdc++-v3/include/bits/deque.tcc | 6 +- libstdc++-v3/include/bits/stl_algobase.h | 6 +- 13 files changed, 165 insertions(+), 101 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 99a7e7247ce..c9d627fa782 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,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 2add97ae749..c60724e869e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) 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_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/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 8fbd67788d5..5d40e04f91c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false +"__is_pointer", CPTK_IS_POINTER, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ad2c2a2d250..ab783b161c7 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, - 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, - 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, - 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, + 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, + 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, + 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,78 +116,78 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 57, + TOTAL_KEYWORDS = 58, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -205,23 +205,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_array", CPTK_IS_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, @@ -236,22 +240,19 @@ cp_trait_lookup::find (const char *str, size_t len) #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, - 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, - -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, - 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 56 + -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, + 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, + -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, + 57 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 168411f6700..83ed674b9d4 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_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); @@ -12412,6 +12415,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_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 bcab0599d1a..efce04fd09d 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_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))); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..f08bbf6fd7b 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -192,13 +192,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -226,7 +226,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char @@ -1202,8 +1202,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; const bool __simple = (__is_pod(_ValueTypeI) - && __is_pointer<_II>::__value - && __is_pointer<_OI>::__value + && __is_ptr<_II>::__value + && __is_ptr<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); return std::__copy_move<_IsMove, __simple, _Category>::__copy_m(__first, __last, __result); @@ -1294,8 +1294,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; const bool __simple = (__is_pod(_ValueType1) - && __is_pointer<_BI1>::__value - && __is_pointer<_BI2>::__value + && __is_ptr<_BI1>::__value + && __is_ptr<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__copy_move_backward<_IsMove, __simple, _Category>::__copy_move_b(__first, @@ -1426,8 +1426,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_integer<_ValueType1>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1515,8 +1515,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value); + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, __first2, __last2); } diff --git a/gcc/testsuite/g++.dg/torture/20070621-1.C b/gcc/testsuite/g++.dg/torture/20070621-1.C index d8a6a76b6b0..b05136163e8 100644 --- a/gcc/testsuite/g++.dg/torture/20070621-1.C +++ b/gcc/testsuite/g++.dg/torture/20070621-1.C @@ -18,7 +18,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -49,7 +49,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { template inline bool __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); + const bool __simple = (__is_integer<_ValueType1>::__value && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } template inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..be0689096fb 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -17,7 +17,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { + template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..3711e4be526 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -364,14 +364,14 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // Pointer types // template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -390,7 +390,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index a212b8a6940..08d888ee8af 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1273,7 +1273,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr>::__value + && __is_ptr<_Ptr>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with @@ -1329,8 +1329,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr1>::__value - && __is_pointer<_Ptr2>::__value + && __is_ptr<_Ptr1>::__value + && __is_ptr<_Ptr2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 2f5a4bd4fd4..d1438429487 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1217,7 +1217,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple = ((__is_integer<_ValueType1>::__value - || __is_pointer<_ValueType1>::__value) + || __is_ptr<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1380,8 +1380,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with From patchwork Tue Oct 10 22:10: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: 151025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp179134vqb; Tue, 10 Oct 2023 15:45:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoyee1aWGv3F2YNmznBCXFysjDEnozmjxdDTRxe4wcrz934DMR3gGAtViCfJqBUcjzVMSd X-Received: by 2002:a17:906:1089:b0:9ae:3772:10c3 with SMTP id u9-20020a170906108900b009ae377210c3mr15611454eju.22.1696977935200; Tue, 10 Oct 2023 15:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696977935; cv=none; d=google.com; s=arc-20160816; b=DfLi2tLxUPLBLIllQnh4McbkT010V9ouMPT+8nWNHK1BQmMuuItCKHdDFMpaFZqJCM TmvHdzV3+sgKfK0Xv2spppCb0GddEWPpHNbi6T9LUz7mSlgALcbvK5QFa44qY5dBiY63 e/rsORI8Nwa4Tyjls+R4jFER3yGvF1mHxSBUU1Aoyf9eYe9M09Oboad6bNVSwfE/0msb G4xt8soPvo6l6zpMIWn7XN54I2rvLlqLkNSdN1nF+HioqC7nsBVWqYjSjWwX3XCeSXXa 9h/wP0Q/JhA5oNg1Ibx2FobnSvhc4ZbDIAhPE+l8MM/wkWghHpCvxBPEhduuE8MGf0yx XSHw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=FoeJT/GBzRpBhP33uv2zqEq3rfNbz2Mqiw6U7yfAxs+ySNgZPkiUOOtZ7j96dpleJI GIpzf7CR/zbREBE8wULS9lT75+9bGleyHde1dk6fvUwWERixC0/Ii/PE0KIGUxYQM/+b OYJOcInaNF9YV+UoOxYU9W58EyhWvL3CyOR1NsSZ+SJopno5CRTSrcvTZrIav7RI8o/+ 3Cwo4n3KK/70lTzbbxCQdphvIHQFIqPa+XlIE8gWwLPqVBdnfWMk8x3ZoSNJnnbxvFnc QQXKWOMIvimh/GXYLJSwgz6nFFqutqmBbqP558I0WT9nkg61zIDUl9Shd46hvw/53IBa 2E8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fgp0vb5c; 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 n10-20020a170906840a00b00994936a6f11si5847487ejx.957.2023.10.10.15.45.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:45:35 -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=fgp0vb5c; 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 189AF395B466 for ; Tue, 10 Oct 2023 22:36:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 189AF395B466 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977393; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fgp0vb5cT/WoJeDRCWCMNib6maiz1Td8PcqK9VMMqxhRFmlu+wGW+WvjP+9WIcbV0 bSOhijLYEB1wuG+VWeSvndpiJHKpJoNuy8Roqy4ZPRY0nUFMRO1h7cdhCzm3RVtQWg CnGP/QH2QcyoPaqkpfIeN+UPxvhmjVKibT93VJHk= 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 6EC093875450; Tue, 10 Oct 2023 22:35:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EC093875450 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 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 39AMYQnh008143; Tue, 10 Oct 2023 22:35:47 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn7xkd8ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:35:47 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMZeoq022450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:35:40 -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 39AMFOUg024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:35:40 -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 v16 29/39] libstdc++: Optimize is_pointer trait performance Date: Tue, 10 Oct 2023 15:10:20 -0700 Message-ID: <20231010221520.3680267-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: sHEJTH3TgWM2Y3FCxa9zovv3g1rpr0DL X-Proofpoint-GUID: sHEJTH3TgWM2Y3FCxa9zovv3g1rpr0DL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1034 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=487 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776997371839653001 X-GMAIL-MSGID: 1779410335331483801 This patch optimizes the performance of the is_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_ptr): 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 3711e4be526..4da1e7c407c 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 __has_builtin(__is_pointer) + template + struct __is_ptr : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_ptr { @@ -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 9c56d15c0b7..3acd843f2f2 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 @@ -3254,8 +3268,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 Tue Oct 10 22:10: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: 151028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp180100vqb; Tue, 10 Oct 2023 15:47:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6gOqViLWn77M2M6zrfIyz66dgYmm0Zj8ndec3NeylnlHLX95zjtHKmZt0BREidyclU1q9 X-Received: by 2002:a17:906:3012:b0:9ae:4054:5d2a with SMTP id 18-20020a170906301200b009ae40545d2amr16966873ejz.16.1696978079070; Tue, 10 Oct 2023 15:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978079; cv=none; d=google.com; s=arc-20160816; b=gz/K4gMhMmjOf2OSe7al/YHOUT5W/aDoof/7iZZYczrMswh75FsEh/0solwWQoTJGo fQoI4eSXMIZptMeQw90SEqCfYs7ZH3wMvslBPY2Q/YcN8pPfCeEVJALQ5l1hqDyI81WG x9UK4sMvUnEarVtoX80/UffXLdFsSvmScEhWzCTByHeOpa/ZJ3NVgKs1N/litpCUu0M2 ew6aBASzYngQI/GtomHJfkGkE1yGtcT41dLd8CYKTmkgYv16HDoA75CyOwWXFogUeVGi XNiI+sJXh8HekVGDXC6QHOaMPAjrnnbrk2PR6vwOBhUZom5t59s/1cM1/HyMhQHbhPoM lJ5Q== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=baVu198/1psUePyf/ZegfP+yD8pWyaMpK+a0owe1Fcs=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lH0fmaQBR2dJcz9tIt7ToFQZUlOuWRO/tAgqluoGRx3+3ayY+fkFyBUCxJZGD9cbNg 6jW62iKL8AU/JzaLkkNC/DvV9wosrGFzbyt0K/gHKDDI+DHZgiWK5fQNZpCF7CN/CPRk qxFDddLRvYZOvw9cUVAJYZI2QG7EB8tBX8HJDOw/vhJUIsHvTcuTEUkf7WqYals/o1RB zW071ADSC1XT/tfmEang76f4rQM/WGwC/5zIcqnvnpetmsmybWNjhS/fxIS3NXvAeqAu GwL1G0hGc92ekW6yr+NTC3/4tyirfx6BG1b8V2oP/qVPKsT5BCXCWTVQLkGrRKKRw85r G8Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="t/dXpLJs"; 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 y25-20020a170906471900b009a190ce8502si5744467ejq.120.2023.10.10.15.47.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:47: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="t/dXpLJs"; 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 8A7CC398243F for ; Tue, 10 Oct 2023 22:37:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A7CC398243F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977453; bh=baVu198/1psUePyf/ZegfP+yD8pWyaMpK+a0owe1Fcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=t/dXpLJs3UwC+3WencnhFEpO4qd+cWnyCs7xNQuOhhLvx+vG+NOrY1gZ7f7e0PmL7 qMfJ4FmX7x66geidKx3jYmu7iF0OY+yq1hOGKZpRqWH9Bn0hGrcUhWrpk9EDIfCNtB nu+YUOL7i+EL+ESkPOTLil33QRr2niRXeL6wMwU0= 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 22F30395B81A; Tue, 10 Oct 2023 22:36:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22F30395B81A 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 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 39AMM3Xb027610; Tue, 10 Oct 2023 22:36:41 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnc8nt2ub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:36:40 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMa9CX027874 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:36: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 39AMFOUh024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:36: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 v16 30/39] c++, libstdc++: Implement __is_arithmetic built-in trait Date: Tue, 10 Oct 2023 15:10:21 -0700 Message-ID: <20231010221520.3680267-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bEyq8DVjj3oN_VXVL4aAECCL1IddGyJ8 X-Proofpoint-ORIG-GUID: bEyq8DVjj3oN_VXVL4aAECCL1IddGyJ8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 clxscore=1034 phishscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776995829201979099 X-GMAIL-MSGID: 1779410485931049077 This patch implements built-in trait for std::is_arithmetic. gcc/cp/ChangeLog: * cp-trait.def: Define __is_arithmetic. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. * g++.dg/ext/is_arithmetic.C: New test. * g++.dg/tm/pr46567.C (__is_arithmetic): Rename to ... (__is_arith): ... this. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_arithmetic): Rename to ... (__is_arith): ... this. * include/c_global/cmath: Use __is_arith instead. * include/c_std/cmath: Likewise. * include/tr1/cmath: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 184 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_arithmetic.C | 33 ++++ gcc/testsuite/g++.dg/tm/pr46567.C | 6 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 4 +- libstdc++-v3/include/c_global/cmath | 48 ++--- libstdc++-v3/include/c_std/cmath | 24 +-- libstdc++-v3/include/tr1/cmath | 24 +-- 13 files changed, 193 insertions(+), 146 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9d627fa782..3a7f968eae8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c60724e869e..b2be7b7bbd7 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_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5d40e04f91c..9050c36f105 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ab783b161c7..31fd5075f2d 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 97, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, - 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, - 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, - 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, + 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, + 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, + 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104 }; unsigned int hval = len; @@ -116,130 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 58, + TOTAL_KEYWORDS = 59, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 103 }; static const struct cp_trait wordlist[] = { -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false} }; @@ -247,12 +249,12 @@ cp_trait_lookup::find (const char *str, size_t len) { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, - 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, - -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, - 57 + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, + 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, + 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, + -1, -1, 57, -1, -1, 58 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 83ed674b9d4..deab0134509 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_ARITHMETIC: + return ARITHMETIC_TYPE_P (type1); + case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 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_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { 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_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index f08bbf6fd7b..79d304e0309 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -217,16 +217,16 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; template struct __is_fundamental - : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > + : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index be0689096fb..da592b9fd23 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -25,9 +25,9 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { + template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4da1e7c407c..51ed5b07716 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // An arithmetic type is an integer type or a floating point type // template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; @@ -398,7 +398,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index 6461c92ebfe..a0ddc1dbbeb 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -1259,8 +1259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1285,8 +1285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreaterequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1311,8 +1311,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isless(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1337,8 +1337,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1363,8 +1363,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1389,8 +1389,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isunordered(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1401,7 +1401,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -1411,7 +1411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -1420,7 +1420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -1429,7 +1429,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -1438,7 +1438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -1447,7 +1447,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -1456,7 +1456,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -1465,7 +1465,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -1474,7 +1474,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -1483,7 +1483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -1492,7 +1492,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -1501,7 +1501,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/c_std/cmath b/libstdc++-v3/include/c_std/cmath index 588ee1e6dc4..c1db699ecdb 100644 --- a/libstdc++-v3/include/c_std/cmath +++ b/libstdc++-v3/include/c_std/cmath @@ -467,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #undef isunordered template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -477,7 +477,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -486,7 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -495,7 +495,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -504,7 +504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -513,7 +513,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -522,7 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -531,7 +531,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -549,7 +549,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -558,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -567,7 +567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/tr1/cmath b/libstdc++-v3/include/tr1/cmath index ba1b60cc945..2e80f1d0d00 100644 --- a/libstdc++-v3/include/tr1/cmath +++ b/libstdc++-v3/include/tr1/cmath @@ -307,7 +307,7 @@ namespace tr1 /// Function template definitions [8.16.3]. template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -317,7 +317,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -326,7 +326,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -335,7 +335,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -344,7 +344,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -353,7 +353,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -362,7 +362,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -371,7 +371,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -380,7 +380,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -389,7 +389,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -398,7 +398,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -407,7 +407,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { From patchwork Tue Oct 10 22:10: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: 151033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp181109vqb; Tue, 10 Oct 2023 15:50:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPee4FIfiNyqMOKjBLdKdr5tPy3bhVp02f5nZTEsul+la4xM+txttYP6pz5/ma3Iy72Dvk X-Received: by 2002:a17:906:c106:b0:9b8:df8e:cbd0 with SMTP id do6-20020a170906c10600b009b8df8ecbd0mr11903391ejc.37.1696978244439; Tue, 10 Oct 2023 15:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978244; cv=none; d=google.com; s=arc-20160816; b=JsrdA3mxO7ANXV+b3T3VDMVgCiSDC3/vt0rWXaqWf9WYNrWx5ptU+o5KkIUNKUg51r gJvzDQqTAqPyJHozpQho1c3XZBL320z0UBwDE6VXIsQe1lcT9VS4p8D8aU6n8rVyxXpc TH1FN6q6vSH5OvgaDLjix8ndnE53yk8a5QtpFrT85/m+2CENPHSQ7ynRoBYYxYSok5Yq a1YW4pRDq1yuewuTx6y5eCPdHh1Lsw+sFrovIbXTeLFKiNu2k64aUqXwSOasVPy6sajT eJmcTYCZuv01d77DXbjbPyAUwqjmbPHaRlGQv24yVu/EOGbqHGDXpVg/erFx2cXwt9J6 L+gA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=K4Dbgg5fmQFC2ZeUQY7zRC0twAuAxW6m8471x/jURMlxHPuXiMrb9RwFiWQ2Rk4hBJ eDBbAGW5mq8AeWXlrsmeESbqp2Ny3gcT/rkcEGB8SKM07D2fxQVQcfXBl1DzZkncNw0/ lk6H0xRgrBVxKZ1brlQU5T/pOtr03heyY3JrHv2W40Cfqbd3gyxLUbS3fUkk52oZAHv9 eNLLSuAAl1J8ahkT4PcHXSa2IRngG48DNcaiMtGXlmF2fPpa46z2U/kEiUT6TraUAl6z l/UnUtseGWSq/Eoxi8SVVrS5v4GMQPVl5wADZr8xhxodORQUx65KOf3NWu4aeMyKYmIN eMQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IxU55Cnu; 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 a6-20020a170906468600b009b291699dcbsi5687939ejr.237.2023.10.10.15.50.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:50:44 -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=IxU55Cnu; 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 B82493912385 for ; Tue, 10 Oct 2023 22:38:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B82493912385 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977526; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IxU55CnukXrwqOU4GRY5ProJl3dgPeHXMv+RslS10RVWI9IfNis4UN1WHp036ih2Z FmpuQ9JqfHGiF7kBuAQyi8bcmnubpt/UYzuTBz+3/xKNEqT3cOfREDjcWkFWq0E4Uy ju0YF9GbNaHGSd0bMO1kkiGjfRQIIzfiGrMDZqeE= 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 347A33894C2D; Tue, 10 Oct 2023 22:36:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 347A33894C2D 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 Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMXHkV015654; Tue, 10 Oct 2023 22:36: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 3tnamp38rh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:36:54 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMaman022802 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:36:48 -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 39AMFOUi024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:36:48 -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 v16 31/39] libstdc++: Optimize is_arithmetic trait performance Date: Tue, 10 Oct 2023 15:10:22 -0700 Message-ID: <20231010221520.3680267-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mXEMrsXXKgvdvVwR3dbY3QRc7j4r0Up4 X-Proofpoint-GUID: mXEMrsXXKgvdvVwR3dbY3QRc7j4r0Up4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=667 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776996488688417878 X-GMAIL-MSGID: 1779410659580954120 This patch optimizes the performance of the is_arithmetic trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_arithmetic): Use __is_arithmetic built-in trait. (is_arithmetic_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 3acd843f2f2..cc466e0f606 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -726,10 +726,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_arithmetic +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template + struct is_arithmetic + : public __bool_constant<__is_arithmetic(_Tp)> + { }; +#else template struct is_arithmetic : public __or_, is_floating_point<_Tp>>::type { }; +#endif /// is_fundamental template @@ -3344,8 +3351,14 @@ template inline constexpr bool is_reference_v<_Tp&&> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) +template + inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +#else template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; +#endif + template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; From patchwork Tue Oct 10 22:10: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: 151032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp180645vqb; Tue, 10 Oct 2023 15:49:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHO6ArZ/eXZ/5QSkcQzhf5i27zI3MqCAeVl3MIiVdgc2n3Sx+SRzHrHWvfAlwGSgn7LqdgA X-Received: by 2002:a17:906:5381:b0:9ba:321b:80e1 with SMTP id g1-20020a170906538100b009ba321b80e1mr4326903ejo.0.1696978169978; Tue, 10 Oct 2023 15:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978169; cv=none; d=google.com; s=arc-20160816; b=ojAV0pzsW2uoCTwBeavqRIvYcn3YxMDh0NEsDZ+c3r+b1HSEQsGZuzJREluVBiuwa4 FG2ydD3e+I8aF7PXoITov1F0XfZI5V5QAvK7H5MtVB6u/I1XJmqLBiGpnasQuD5s40ro 88JelKqCY0U3EbDwS8PgaRlZWwUN3LgHYgm8x101nxxVzkzLy4m0mnUKw12S/dcgHfaK PzehRn1jQAd1xoiLgjF8uFQq30oncYzqMzhSwH2PEDPSH1T9hg+9c7ucYVI6fCtmmS0l iTG1hDGr8HLDf3PeoKfKVBVxPem16Jlzq4MMPGx5tqt0D3beD5f3NdziL8Uy+rR2gqIl n4dA== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=I/onhuqz4up9nf0hKmNCINmV4UryOt1IOK3EUpzxXoBCIUCCyeTh0jKxLiKtmsfNfw SH+HYhG+9NnZqrjB6FAU05rd1nsUSZDQxA084xSScdlNooKeSdZp2jmGJV/TELBbaOpr 85T49N5JomIeRh9A/G/6F30knlS9dokERGMBT8bZ+TwbTN5YGiz8aEgvNYT76dBBSUJn HeXaenxspqLfBMFSF0Z/FuJvNNcc+fvJNKjcwNvgF43/PbfHawuhdL9DfgSIa9g2P7Vu /9ly0RnUAMhQr/EkQtIHE4YgBwpwVEEEi4GHs+RDgMCUiZycIQNYrIfvw1zT9UtW0ej3 ykNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eg029tGj; 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 cb22-20020a170906a45600b009a63cbd4b02si5883904ejb.932.2023.10.10.15.49.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:49:29 -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=eg029tGj; 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 50E6738319E6 for ; Tue, 10 Oct 2023 22:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50E6738319E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977496; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eg029tGjQPrycdZUV9qzbrBRDTwb99VTr0Xc5OjVju8z43CBpA3ptK452OwpRbvTM fKZ+fT+NkMJogFYPAaXuh7YuMXjvTdx0rnJw0kqjxI9Liw3uPo6NdKRP+MVac/b1fb 1oJreI++0gY5AB5GrANHnly6AyQt+tHS84GK6XV4= 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 4FC4B396E87F; Tue, 10 Oct 2023 22:37:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FC4B396E87F 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 Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMZhuh013845; Tue, 10 Oct 2023 22:37:26 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tn957vasn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:37:26 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMbASN028146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:37: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 39AMFOUj024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:37: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 v16 32/39] libstdc++: Optimize is_fundamental trait performance Date: Tue, 10 Oct 2023 15:10:23 -0700 Message-ID: <20231010221520.3680267-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dxnEO_Bw60yRL-t7i_EXtuHzPrVKVYNv X-Proofpoint-GUID: dxnEO_Bw60yRL-t7i_EXtuHzPrVKVYNv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=657 clxscore=1034 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP 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: 1776996476757191546 X-GMAIL-MSGID: 1779410581663145899 This patch optimizes the performance of the is_fundamental trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_fundamental_v): Use __is_arithmetic built-in trait. (is_fundamental): Likewise. Optimize the original implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index cc466e0f606..88171e1a672 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -739,11 +739,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_fundamental +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template + struct is_fundamental + : public __bool_constant<__is_arithmetic(_Tp) + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> + { }; +#else template struct is_fundamental - : public __or_, is_void<_Tp>, - is_null_pointer<_Tp>>::type + : public __bool_constant::value + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> { }; +#endif /// is_object #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ @@ -3354,13 +3364,15 @@ template #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) template inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +template + inline constexpr bool is_fundamental_v + = __is_arithmetic(_Tp) || is_void_v<_Tp> || is_null_pointer_v<_Tp>; #else template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; -#endif - template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) From patchwork Tue Oct 10 22:10: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: 151038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp183413vqb; Tue, 10 Oct 2023 15:57:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFK5/AorJ4tASpT/LJwe3yLuOo8IRBm19fKCxA1yrWJ9MZ2Rpe6bJUAGYVLkatvSKTayLBC X-Received: by 2002:a17:906:14e:b0:9ba:13f1:5a7d with SMTP id 14-20020a170906014e00b009ba13f15a7dmr7499699ejh.31.1696978643588; Tue, 10 Oct 2023 15:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978643; cv=none; d=google.com; s=arc-20160816; b=JGY7GM8w0fXcDjyu30xe/oNwkf0kgjBKmTKkJZRmDXd3HfL5uLn6UJcTTRgljC47/2 2jArg2+2qCFSZhVQEHuoIixerzBm7CBbxir2yK0gxqG5phUBSiB/S3WBSi18lrn4QqtH 3/LHFVI01Oqs5vPLZynpS8KroXcLezgxxTYm4x3ZBGp+qoIens+79E4+Fgn/UdQYJ39c YCbdwEksFJ8Z0ANJBzROi/BDSt5gtr6TLGenP79n3QzhT7d5Py219gk31Z1aqYxtCGgf aMKNj/hkCmeloqmOVCv4IyZA8E96U2z3mq+Gnap12fo/O90quSPYbzqbvcf3jX3ZHjdw XnWw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=KRIMZHhVurduUavwaOKNIzfCse9PRaGLAmf1kp8Xdbi4EtAo95AYaYOCLhoZCYQl3H DeDhlZvd0j5rchW7q9LtjpYQpFFrhtpkeIbONzS7RF0/quAzv5kLTYtIe9YcGZSFeIcD aSgCLksCk1IhHf2YDspshU4pKAjERJWHy/BWHvxOG3off9iNs5PEMQZVI+SZYMVK/NaI oc4S5AE8b3fnsJ0miI4doiF2aXHr2uIWpOZ6KLv/k0MAeq/hJ0cMkijCQijjrIw1SGoN /C69DY9PrroZ1YrWt95IjQAunlcyBO4LQZoRX2UmBaG3JpG7bGcUrI36OapmGUuTYyzW aOdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ftTjHrhs; 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 p16-20020a17090628d000b009b93c77d2f6si5872684ejd.489.2023.10.10.15.57.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:57:23 -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=ftTjHrhs; 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 C3E703895FE4 for ; Tue, 10 Oct 2023 22:41:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3E703895FE4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977702; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ftTjHrhs6Raf+gb2kAR4PWjVFkaWotK6DoG927XTRrUlP1HGR/q+O5kjze/oNldWQ PQ+tZivR4Mr8OqJVx68uGYQ1MosFiEqcxLxigH44XT8l/0a/ROD11/+IrFoQNqwEVJ dcHBbffNefFXqhTsG5jBeIv3NUkR7D4eJKD/7qP0= 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 BE2E13AA8CAE; Tue, 10 Oct 2023 22:38:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE2E13AA8CAE 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 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 39AM7Fha022788; Tue, 10 Oct 2023 22:38:10 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnc8nt353-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:38:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMbifQ001332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:37:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39AMFOUk024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:37:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v16 33/39] libstdc++: Optimize is_compound trait performance Date: Tue, 10 Oct 2023 15:10:24 -0700 Message-ID: <20231010221520.3680267-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yrJXHnB0WTpw-ZNHwEvb8p7ZYh4tpuj6 X-Proofpoint-ORIG-GUID: yrJXHnB0WTpw-ZNHwEvb8p7ZYh4tpuj6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 mlxlogscore=597 clxscore=1034 phishscore=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100174 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776996293852351903 X-GMAIL-MSGID: 1779411078417798843 This patch optimizes the performance of the is_compound trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_compound): Do not use __not_. (is_compound_v): Use is_fundamental_v instead. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 88171e1a672..48d630a1478 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_compound template struct is_compound - : public __not_>::type { }; + : public __bool_constant::value> { }; /// is_member_pointer #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) @@ -3387,7 +3387,7 @@ template template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template - inline constexpr bool is_compound_v = is_compound<_Tp>::value; + inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>; #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) template From patchwork Tue Oct 10 22:10: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: 151035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp182405vqb; Tue, 10 Oct 2023 15:54:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw13hX/xCrafggf9lV9g/SLw5wuAK1ceAmOem/BkYsDJl/zPtalAy53vBQVLIKIkBLsLbH X-Received: by 2002:a05:6402:2750:b0:53d:9f84:3882 with SMTP id z16-20020a056402275000b0053d9f843882mr2853891edd.1.1696978475009; Tue, 10 Oct 2023 15:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978474; cv=none; d=google.com; s=arc-20160816; b=i+oIrrDxj3cgykpYpxE8Un2oMnI4m3pmrtV8iVMDWzW6x/c8kQCXdPRVPBX7gvTwrn +yIf60ZBGI14AzcekGaeWNYPnnA0NJxVXL9TdBVwfHYwctvPVmMkM/F/jc2aan2ma2DL RV+pLsRdSG2WtvbaVpOxzT6z0WgHKpDvLQwgouSwi1I54lWFdUlx77K9R5wexAPj+86j 5yXOyVyx2VfY4B1llsjM/Oi7TBc+aoP+QGHCV3frjN+W9av+8J0zAc8s670UnYRy8xq7 HxFP14sY1wYTj7Zw+WlmuvNnR6Fm3K4msoC4OzBiLRMAAuFf71C2ygQKWJA8wWG+hrFP 2VJw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=hTTti/XJyYuVdWIyRONnYGN94lAoM+QnHzvEGTrqWPEhDNudwlXlVHCCbLto6efKFx vQjwRFjrrKQFXERt3gm9SpOjuyoEdiPdL+XXHDRi0Va7UvNGdBmUWpwRiIRXnBAEajW3 g9xXxmEz/8VcDC0JeQ4e6GGm8WmYn3vQql5DOSAIYj9W5mx4IoX3Nwi2LyYwKwMGN5VR L7+14aaYn1IHw9riDxYS5Yd/XXoEb0EwuCHKVFs3hLIhnfDTIZy9kgqVL4kSnCvr03IT ALMWIigS8u2teQ3gXNBrJvW63ypz7vJBRMCn/2Ef7dFruhdR8rl/l4xIPu5LztYQYn6z 1izA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="gcwbgA/k"; 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 j1-20020aa7c401000000b00530e9bf1e9csi5889131edq.215.2023.10.10.15.54.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:54: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="gcwbgA/k"; 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 99AD3394849B for ; Tue, 10 Oct 2023 22:40:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99AD3394849B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977633; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gcwbgA/kbJDcSNwNw4IEkHmiTjf9OLkcG2Gz44hlTnKGoMvLlkBiqaJtJuFBcRcQh Mxzu3SOWYTGBjdsh3X/wiOXekohb/ygIXEasTBbI75LSePu1/eZ59p54xrPSbPAO8N RNkZUkEYffPr3fUEDpMJ5sTnv2ITspSZoTGBMaX4= 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 D550B38293B6; Tue, 10 Oct 2023 22:39:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D550B38293B6 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 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 39AMXkbb009756; Tue, 10 Oct 2023 22:39:00 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3rmta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:39:00 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMc9GC001526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:38: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 39AMFOUl024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:38: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 v16 34/39] c++: Implement __is_unsigned built-in trait Date: Tue, 10 Oct 2023 15:10:25 -0700 Message-ID: <20231010221520.3680267-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: L7YvamXsZ08quvQFud6vAuSsobVaKTbs X-Proofpoint-ORIG-GUID: L7YvamXsZ08quvQFud6vAuSsobVaKTbs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 mlxlogscore=860 priorityscore=1501 clxscore=1034 lowpriorityscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776996278564175547 X-GMAIL-MSGID: 1779410901302463063 This patch implements built-in trait for std::is_unsigned. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unsigned. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNSIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unsigned. * g++.dg/ext/is_unsigned.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 118 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_unsigned.C | 47 +++++++++ 7 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unsigned.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 3a7f968eae8..c28dad702c3 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_UNSIGNED: + inform (loc, " %qT is not an unsigned type", t1); + break; case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b2be7b7bbd7..0603b4a230f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -94,6 +94,7 @@ 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_UNSIGNED, "__is_unsigned", 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) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 9050c36f105..90d05bca5c1 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -74,6 +74,7 @@ struct cp_trait { "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_unsigned", CPTK_IS_UNSIGNED, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 31fd5075f2d..75ab2b5edfa 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 97, duplicates = 0 */ +/* maximum key range = 129, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, - 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, - 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, - 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104 + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, + 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, + 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, + 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136 }; unsigned int hval = len; @@ -116,46 +116,44 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 59, + TOTAL_KEYWORDS = 60, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 103 + MAX_HASH_VALUE = 135 }; static const struct cp_trait wordlist[] = { -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 86 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, @@ -165,11 +163,11 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -180,7 +178,7 @@ cp_trait_lookup::find (const char *str, size_t len) #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, #line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -207,6 +205,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" @@ -223,8 +223,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 70 "../../gcc/cp/cp-trait.gperf" @@ -242,19 +242,23 @@ cp_trait_lookup::find (const char *str, size_t len) #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, - 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, - 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, + 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, + 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58 + -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index deab0134509..14387821b85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12250,6 +12250,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_IS_VOLATILE: return CP_TYPE_VOLATILE_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: 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 4bc85f4babb..3d380f94b06 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..2bb45d209a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,47 @@ +// { 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_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Tue Oct 10 22:10: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: 151034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp181649vqb; Tue, 10 Oct 2023 15:52:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJsrRAYcG1kddZaagNVMmjXI7gUiSU90i1n5x2FcVynRsndmCz8sMbhULg5kheNcaJDVev X-Received: by 2002:a05:6402:530f:b0:53d:a3ff:460a with SMTP id eo15-20020a056402530f00b0053da3ff460amr2132769edb.27.1696978342044; Tue, 10 Oct 2023 15:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978342; cv=none; d=google.com; s=arc-20160816; b=HaoqZfo1KvxIY19Y2fjPJtUCbDpDpH4kVoFWDIgke1T35TU+8FlCdhdPBBglfR7AJZ X/bp0BRKs7qHMQVW+lPKR3yYuicrifeuZu5UHZSa7myo1xSmmsqJWJSMCw3m0yXeq2Qh T2DB1f5Kp4VT2/PBMTkbVDragSSL4PBk0ylv+BzejLV0NHJQUsJ0lOF+DlyRK0I78o25 WBWAp10JuVRArptOzHRSBboCdiedyVVtBF2Qh8OhwpgPX49Vs+g8YkEV/0EXMrbB6tNu C+YI+O397t9NoYXnoxClB+7HNF59vETezCwt2vrDKlW74reVGaiCcFUT6M9qEdQLAH3h /AGg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TPIbzBfBmly5Fhti3PiHPu3xjo3DMSid3rjTaRnhd3Rd3QtTd8rjPhqRv9eRxJrm2B g6d8Ifjc2B7FA/SNxjBdEolJ9eR39KXnbZ+Aqy1MCi6U7JjJ3+BS/+NHORbG6tlot9jF vlPo5kDmq7UyLPoeocJobevqXfznEEBnXASAcRNipSy5g7HfEbDM5Snda55vF34qJ8qV N2E+3r8ESC9zBdcMC/UpR2bK9wA6lcoHLKSqIx3l2Qo1xMhy/DThapYU0jZ9PkvlqiFi P13JQSkrmx+UVovfo0o8v50m3zSnU6NX6AA8XE1FyoPYJSvXnJeNsEJQbLYMnlwh3dwR 3jJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kKsJ4nkp; 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 o18-20020aa7c512000000b00530a16025efsi5695214edq.689.2023.10.10.15.52.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:52:22 -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=kKsJ4nkp; 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 5FAEF383095F for ; Tue, 10 Oct 2023 22:39:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FAEF383095F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977572; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=kKsJ4nkppYEeUEk1ZXL04MOXvNmC/mkMX4vqhFkN184B4c1zEpDMCFMWfPWfZsF4+ mch+aITvR8jt9jSlonFciw/K64tSuuYVLqdjfJV1SXKHpXejpt+2AWXgLw4tBGqdZd cR/IO7WT+vhusUQueOjgO3BwBe/pem8fs+w7w408= 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 A224A39123A9; Tue, 10 Oct 2023 22:38:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A224A39123A9 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 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 39AMbe1U007257; Tue, 10 Oct 2023 22:38:46 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxqaga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:38:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMcfN6001579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:38:41 -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 39AMFOUm024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:38:40 -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 v16 35/39] libstdc++: Optimize is_unsigned trait performance Date: Tue, 10 Oct 2023 15:10:26 -0700 Message-ID: <20231010221520.3680267-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: iTVr74XaNL9BsSkLA_ASEQvccj_giV8i X-Proofpoint-ORIG-GUID: iTVr74XaNL9BsSkLA_ASEQvccj_giV8i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 mlxlogscore=751 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776995061376064333 X-GMAIL-MSGID: 1779410762068243793 This patch optimizes the performance of the is_unsigned trait by dispatching to the new __is_unsigned built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unsigned): Use __is_unsigned built-in trait. (is_unsigned_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 48d630a1478..f7d3815f332 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1001,10 +1001,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_unsigned +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) + template + struct is_unsigned + : public __bool_constant<__is_unsigned(_Tp)> + { }; +#else template struct is_unsigned : public __and_, __not_>>::type { }; +#endif /// @cond undocumented template @@ -3440,8 +3447,14 @@ template template inline constexpr bool is_signed_v = is_signed<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) +template + inline constexpr bool is_unsigned_v = __is_unsigned(_Tp); +#else template inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; +#endif template inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); From patchwork Tue Oct 10 22:10: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: 151036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp182669vqb; Tue, 10 Oct 2023 15:55:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnoPnfgm0Bv74K/pNyiQgIzZuaujHuUlvWnLjyDcdqdkKi9NaCqXYI3/3d+oB6dY/hsXIO X-Received: by 2002:a5d:6e8e:0:b0:321:68fa:70aa with SMTP id k14-20020a5d6e8e000000b0032168fa70aamr16350011wrz.9.1696978515121; Tue, 10 Oct 2023 15:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978515; cv=none; d=google.com; s=arc-20160816; b=ZlPskc1ATjLEjIkNmj9Qs2es5t5exkcwzixD+otA9NxOBPXeZJXtIP1hH6KyQhSS4/ 3N/I1hGNnh+afqcEU1ZGDVxfmawWuGIAZM2FFMbTsr/tzo+0hm3Y4mqx0H+HgB0Jucar PdskqnPE/y+IsBB5iTaj+aROOPwtznII+dds/k1b3W0iw0suyViFnlkwraCq03+rlSat SsUJ4fO/WamLsWTG0beeEWKSlCurSLZGeKutXfuafD/7YFVG9wsye4DOsNFLqpmX+yEQ 49sEddVK9V9Hf44g+ABphpQXlpy49eUrfTAxLz6Xm/vb09MDgCDaVSgNbMikEShTbtVM ZRIg== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MvxE1C8WtX6t/vNlmycNSpOrQHQJhLjVX0DErHPzoac=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=r64NuwWlAmVvrW89vy+xOrKX7s+auw1zVBSexpflt581afCpzVmFbg4jBrrKzm7z9J I1p6vMICchNBr3cTQVejd3CGWGkhA+wJITtEd1lyd3cDGWaU9cefiwcMNCEvAbz2Lh1x btx3xUp+gS74+v3wVqB5zqWoqcHzOSP3WvFGXd1uIIg3IfahZlRKHajoyNPbfB9g9gam 9ukkeU5tlDEIQAxxbo0v4LyIkRoMGPoJ4pGqJPJYGpFcoGrEs8GxhknxUQ9AEfeUF/xa JYhS/Txw1/NA0Nfg0zX46Cj5ViFTSSgNAgp7a78gnFOgsttV3JnYrZKKy1+Givyz9POw bjbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R1IHMhXc; 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 v17-20020a1709064e9100b0098d2f716c75si5901594eju.597.2023.10.10.15.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:55:15 -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=R1IHMhXc; 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 2E3DA39D8A2D for ; Tue, 10 Oct 2023 22:40:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E3DA39D8A2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977651; bh=MvxE1C8WtX6t/vNlmycNSpOrQHQJhLjVX0DErHPzoac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=R1IHMhXccG5C5ZqKxSraoxs3z5RTT2wa+rh4/Zr3h/7K/Ra04bB5v3KXbzXEPQD4e 92LNQwdaIPe8E58m+4MHFpOiAD9AjJ7Nculz5YpyqK7XsjA+viDm1nZ/uqJo59wsJg KFRv6IkgyPmdzQqgM1T8XKCQLGfv0rpv/09ZibLc= 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 062D738319D5; Tue, 10 Oct 2023 22:39:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 062D738319D5 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 Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39AMcBqW028641; Tue, 10 Oct 2023 22:39:59 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnamp39bt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:39:58 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMdfoE028860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:39:41 -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 39AMFOUn024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:39:40 -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 v16 36/39] c++, libstdc++: Implement __is_signed built-in trait Date: Tue, 10 Oct 2023 15:10:27 -0700 Message-ID: <20231010221520.3680267-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: DVD0Ih_f8896k8B4PJzU8wymuhkKwxQt X-Proofpoint-GUID: DVD0Ih_f8896k8B4PJzU8wymuhkKwxQt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776995210539754822 X-GMAIL-MSGID: 1779410943325739972 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. * g++.dg/tm/pr46567.C (__is_signed): Rename to ... (__is_signed_type): ... this. libstdc++-v3/ChangeLog: * include/ext/numeric_traits.h (__is_signed): Rename to ... (__is_signed_type): ... this. * include/bits/charconv.h: Use __is_signed_type instead. * include/bits/locale_facets.tcc: Likewise. * include/bits/uniform_int_dist.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 211 ++++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_signed.C | 47 +++++ gcc/testsuite/g++.dg/tm/pr46567.C | 12 +- libstdc++-v3/include/bits/charconv.h | 2 +- libstdc++-v3/include/bits/locale_facets.tcc | 6 +- libstdc++-v3/include/bits/uniform_int_dist.h | 4 +- libstdc++-v3/include/ext/numeric_traits.h | 18 +- 12 files changed, 186 insertions(+), 126 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28dad702c3..b161c9b2c9e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,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_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0603b4a230f..b0faa4c8937 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ 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) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) 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) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90d05bca5c1..de0ba162e7a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 75ab2b5edfa..6d1078de2fe 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 129, duplicates = 0 */ +/* maximum key range = 119, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, - 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, - 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, - 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136 + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, + 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, + 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, + 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126 }; unsigned int hval = len; @@ -116,149 +116,150 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 60, + TOTAL_KEYWORDS = 61, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 135 + MAX_HASH_VALUE = 125 }; static const struct cp_trait wordlist[] = { -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 83 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_signed", CPTK_IS_SIGNED, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 36 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 37 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, - 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, - -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 + 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, + 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, + -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, + -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, + -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, + -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 14387821b85..5e6b2ca37ac 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,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_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: 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 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { 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_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 79d304e0309..c891aff20f4 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -403,7 +403,7 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { { static const _Value __min = (((_Value)(-1) < 0) ? (_Value)1 << (sizeof(_Value) * 8 - ((_Value)(-1) < 0)) : (_Value)0); static const _Value __max = (((_Value)(-1) < 0) ? (((((_Value)1 << ((sizeof(_Value) * 8 - ((_Value)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(_Value)0); - static const bool __is_signed = ((_Value)(-1) < 0); + static const bool __is_signed_type = ((_Value)(-1) < 0); static const int __digits = (sizeof(_Value) * 8 - ((_Value)(-1) < 0)); }; template @@ -411,21 +411,21 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { template const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; template struct __numeric_traits_floating { static const int __max_digits10 = (2 + (std::__are_same<_Value, float>::__value ? 24 : std::__are_same<_Value, double>::__value ? 53 : 64) * 3010 / 10000); - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = (std::__are_same<_Value, float>::__value ? 6 : std::__are_same<_Value, double>::__value ? 15 : 18); static const int __max_exponent10 = (std::__are_same<_Value, float>::__value ? 38 : std::__are_same<_Value, double>::__value ? 308 : 4932); }; template const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; template @@ -1513,8 +1513,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value - && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed - && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed_type + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed_type && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index 20da8303f7a..1acf1e46e4c 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -46,7 +46,7 @@ namespace __detail // This accepts 128-bit integers even in strict mode. template constexpr bool __integer_to_chars_is_unsigned - = ! __gnu_cxx::__int_traits<_Tp>::__is_signed; + = ! __gnu_cxx::__int_traits<_Tp>::__is_signed_type; #endif // Generic implementation for arbitrary bases. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6bfff7d6289..38a6920abe9 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -470,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL bool __testfail = false; bool __testoverflow = false; const __unsigned_type __max = - (__negative && __num_traits::__is_signed) + (__negative && __num_traits::__is_signed_type) ? -static_cast<__unsigned_type>(__num_traits::__min) : __num_traits::__max; const __unsigned_type __smax = __max / __base; @@ -573,7 +573,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL } else if (__testoverflow) { - if (__negative && __num_traits::__is_signed) + if (__negative && __num_traits::__is_signed_type) __v = __num_traits::__min; else __v = __num_traits::__max; @@ -914,7 +914,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL if (__v >= 0) { if (bool(__flags & ios_base::showpos) - && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) + && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed_type) *--__cs = __lit[__num_base::_S_oplus], ++__len; } else diff --git a/libstdc++-v3/include/bits/uniform_int_dist.h b/libstdc++-v3/include/bits/uniform_int_dist.h index 7ccf930a6d4..73b808e57f3 100644 --- a/libstdc++-v3/include/bits/uniform_int_dist.h +++ b/libstdc++-v3/include/bits/uniform_int_dist.h @@ -258,8 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using _Up_traits = __gnu_cxx::__int_traits<_Up>; using _Wp_traits = __gnu_cxx::__int_traits<_Wp>; - static_assert(!_Up_traits::__is_signed, "U must be unsigned"); - static_assert(!_Wp_traits::__is_signed, "W must be unsigned"); + static_assert(!_Up_traits::__is_signed_type, "U must be unsigned"); + static_assert(!_Wp_traits::__is_signed_type, "W must be unsigned"); static_assert(_Wp_traits::__digits == (2 * _Up_traits::__digits), "W must be twice as wide as U"); diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index dcbc2d12927..c618f211775 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -67,15 +67,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: these two are also available in std::numeric_limits as compile // time constants, but is big and we can avoid including it. - static const bool __is_signed = (_Value)(-1) < 0; + static const bool __is_signed_type = (_Value)(-1) < 0; static const int __digits - = __is_integer_nonstrict<_Value>::__width - __is_signed; + = __is_integer_nonstrict<_Value>::__width - __is_signed_type; // The initializers must be constants so that __max and __min are too. - static const _Value __max = __is_signed + static const _Value __max = __is_signed_type ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1) : ~(_Value)0; - static const _Value __min = __is_signed ? -__max - 1 : (_Value)0; + static const _Value __min = __is_signed_type ? -__max - 1 : (_Value)0; }; template @@ -85,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; @@ -161,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -170,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; @@ -210,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ibm128> { static const int __max_digits10 = 33; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 31; static const int __max_exponent10 = 308; }; @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ieee128> { static const int __max_digits10 = 36; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 33; static const int __max_exponent10 = 4932; }; From patchwork Tue Oct 10 22:10: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: 151037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp183358vqb; Tue, 10 Oct 2023 15:57:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJaW5NuX8+plYQbFtic23WJNjEW0l8Tp8pOlCZC9EQ3d7ulVA7sIfniZ5PQA7zLO7vhfxf X-Received: by 2002:a17:906:538a:b0:9b2:b269:d563 with SMTP id g10-20020a170906538a00b009b2b269d563mr17599793ejo.63.1696978633402; Tue, 10 Oct 2023 15:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978633; cv=none; d=google.com; s=arc-20160816; b=GXT/JPoR+rwLn+XOG8bcoSZu0ZYQhKOznclF2IIC6EvilCDWZKCjktfkxMy50pw8PS +o9DBX+GOSnRsb6GY7iL04xlAm/19a/qXPfv/hIHgtR803b06chnJ2THbD/wgpHC9edm 8WsUJUmPihjwjDnzSE3Dqi4K8jhPkuUm/fprLQmSloqAPXhvn72dAMlvTltY7fX7t/VU vyHM+94JgpT8reBpW10WnMR05JweHOKR/TP7J/kS8daKPwgiQGu5TweBMZbHdzVrCid0 J768vs9AQM/phHxmY5KvxMIdbffZfzRoRyVHoqBAg3z1sMZpXBSzr9uyYEdfW22YX6Nb bxcw== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=n3mHymCCUtFosbojpMsfzdUvoziYsUr/ZdqfBPlA1zJneHeQNaOOpZJ8DNbvO2mVLh nvvGUKDnpOg+RHQ6Bv3AM6T+R3A2Ub+EVuLuizOFChiGAuBU02RXldhrU0aVJOP3pE1/ b/ddHPvL3NLhLCZPvASrT9RAN+cOzTIalyIOFfq3lpv2W8aeM2gXiLoDN3sI5C4oAUSd sCbVsVZRuC/f7LqjyCukn60LjN2MKLr85lS0pMctavYXLt13h4yWk8+5WiPUt6hIuNac 9n9o4mTAyXaFqqBPxKszMuqW6yeiM7ARUty9h+PY+xHliMdkv73FnHiBZqsuNJxO0q8Y Dl/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=W61cUYIn; 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 lr17-20020a170906fb9100b009a1687cbf96si5752545ejb.706.2023.10.10.15.57.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:57:13 -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=W61cUYIn; 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 358D5394D883 for ; Tue, 10 Oct 2023 22:41:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 358D5394D883 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977700; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=W61cUYIn0vqG0Q+TWPYxAWZCZHlR5DQTNlaPLiActgU49UYH/tYBGRwqmH9isFxeC iMg0fcJ6CSYLqm2a3uSsF/W8GdaCU/VViIEg1LMFu5/m5tiK/3bxdG1asmf3bI+7Zr nvRR4oo0j0/ttguGYS6s/xZ3fTVe5pvD26C9VeXk= 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 ED87E3828635; Tue, 10 Oct 2023 22:40:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED87E3828635 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 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 39AMcB6M027216; Tue, 10 Oct 2023 22:40:35 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnay8u8s4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:40:34 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMe9P5023793 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:40: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 39AMFOUo024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:40: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 v16 37/39] libstdc++: Optimize is_signed trait performance Date: Tue, 10 Oct 2023 15:10:28 -0700 Message-ID: <20231010221520.3680267-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: pwcwU1paEnv2m8thNV_1tr5QR_Rx1YG5 X-Proofpoint-GUID: pwcwU1paEnv2m8thNV_1tr5QR_Rx1YG5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 impostorscore=0 clxscore=1034 mlxlogscore=732 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776995527999111836 X-GMAIL-MSGID: 1779411067579591739 This patch optimizes the performance of the is_signed trait by dispatching to the new __is_signed built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_signed): Use __is_signed built-in trait. (is_signed_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index f7d3815f332..7e93923f44b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -982,6 +982,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __bool_constant<__is_abstract(_Tp)> { }; + /// is_signed +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) + template + struct is_signed + : public __bool_constant<__is_signed(_Tp)> + { }; +#else /// @cond undocumented template::value> @@ -994,11 +1001,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// @endcond - /// is_signed template struct is_signed : public __is_signed_helper<_Tp>::type { }; +#endif /// is_unsigned #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) @@ -3445,8 +3452,13 @@ template template inline constexpr bool is_final_v = __is_final(_Tp); +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) +template + inline constexpr bool is_signed_v = __is_signed(_Tp); +#else template inline constexpr bool is_signed_v = is_signed<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) template From patchwork Tue Oct 10 22:10: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: 151039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp183623vqb; Tue, 10 Oct 2023 15:58:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoDQOjeQ6eTy/3HNSjUkL/mG0cNUspayshujfUpi1PYPZj9ST8tzZoBH5c0MbsYdPbvTnA X-Received: by 2002:a17:906:191:b0:9b2:b7f2:bc7a with SMTP id 17-20020a170906019100b009b2b7f2bc7amr19718955ejb.34.1696978684680; Tue, 10 Oct 2023 15:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978684; cv=none; d=google.com; s=arc-20160816; b=YIEBfsSPzo8WyyjTG09amWDzD2+S26kX29ivhbu2Tkxg8fzexVOlhNDHvWXTj5hWv5 Zk55kNHWQCNN2Mdqz5cOIq9sRDzzn8mkdF+8e41CxeX2JlbrzBEYM9AiVaGnyeIACdYz WwKEIa193Hwa3qvRYQCZPrdiit6FUB9qLy9Runkvvlc8kKlrdSInoEufyGlgZ9RcKTVg XNBr5zcF6BQh7629mNZ0w3Rp0DY5LOrw8l8IhRPeYcnK4JVcoV25QQ5SD7OGw/Qkp5Wk rJkTSVUsp1Ho9JcUReibGR8T/52LNfcWtex9hejcGFrb3x07TCTF+TGi+n/W6VL3bHwj fu4Q== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=u3IHJP5wQ7IBv9sRa6bDnOneo4iJ+Ipa3EdItoNbops=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vecHWbaYpNt0MDnZnkVpA6cxSAPt4MF1B21miUELuGLPqNgqJREvf8a6XoHNWS72uo 1a5IHZVmhIUh7oWrPFuTuaZgk/KGtc5oJRkqHsgvvLNEQKuCuXZNKD8jgqzAwc+EIgU5 dLty+eH6f1y6Cg0z8ygcSPKlJYNMHflmcx/fTTx2Pqf8la8062qjGFUMEhYa2hHgLFK8 1785mMzLUtvpgooRcPhT8a6UNjz56y+l6NFGBdvFlc0Vv5V9foreN8ks0cMvhdzWxqTh SGdBwQMCEXK1y7Mq1FY7RBoCfUJrKv7zdWTaXegMCDUNVU5RJgVxLXHyba9oTPNoyKow Ztww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PVw+u2cF; 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 l15-20020a1709066b8f00b00992d0de875dsi5955512ejr.912.2023.10.10.15.58.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:58: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=PVw+u2cF; 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 ACB2038C77EC for ; Tue, 10 Oct 2023 22:41:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACB2038C77EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977718; bh=u3IHJP5wQ7IBv9sRa6bDnOneo4iJ+Ipa3EdItoNbops=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PVw+u2cFA9el987PFvXDVn/yAA0unM9R73Q5J3ta2XXdO239h/Bjrt41ePr2UJQJs dlYJjAx999uDUg3DRI0U6LCu2raw4AWxxq7ntJ5+ne38Zc5Ns56l4FrUaNZXSqWNuD XlsphaRwUaxbYGUt/VvNbuSNOWtLk9xlmPqFgIFk= 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 8A4DF389443B; Tue, 10 Oct 2023 22:41:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A4DF389443B 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 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 39AMbeZA009737; Tue, 10 Oct 2023 22:41: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 3tnakfkd2u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:41:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMeekT029298 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:40:40 -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 39AMFOUp024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:40:40 -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 v16 38/39] c++, libstdc++: Implement __is_scalar built-in trait Date: Tue, 10 Oct 2023 15:10:29 -0700 Message-ID: <20231010221520.3680267-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mk2irsk75QXMvB7qX4EolmE63Utbxd7a X-Proofpoint-GUID: mk2irsk75QXMvB7qX4EolmE63Utbxd7a X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, 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: 1776995829165627138 X-GMAIL-MSGID: 1779411121227375257 This patch implements built-in trait for std::is_scalar. The existent __is_scalar codes were replaced with __is_scalar_type to avoid unintentional macro replacement by the new built-in. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scalar. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar. * g++.dg/ext/is_scalar.C: New test. * g++.dg/tm/pr46567.C: Use __is_scalar_type instead. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_scalar): Rename to ... (__is_scalar_type): ... this. * include/bits/stl_algobase.h: Use __is_scalar_type instead. * include/bits/valarray_array.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 186 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scalar.C | 31 ++++ gcc/testsuite/g++.dg/tm/pr46567.C | 10 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 2 +- libstdc++-v3/include/bits/stl_algobase.h | 8 +- libstdc++-v3/include/bits/valarray_array.h | 2 +- 12 files changed, 150 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b161c9b2c9e..78f100d2745 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,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_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SIGNED: inform (loc, " %qT is not a signed type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b0faa4c8937..08a2780c929 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ 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) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index de0ba162e7a..ef51c713c58 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scalar", CPTK_IS_SCALAR, 1, false "__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 6d1078de2fe..8c68af420f9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -78,10 +78,10 @@ cp_trait_lookup::hash (const char *str, size_t len) 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, - 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, - 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, - 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 40, 126, 25, 21, 50, + 0, 0, 30, 10, 126, 0, 126, 126, 25, 5, + 50, 0, 61, 126, 10, 10, 5, 0, 15, 126, + 126, 5, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 61, + TOTAL_KEYWORDS = 62, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,141 +125,143 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 84 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 89 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 68 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_signed", CPTK_IS_SIGNED, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 33 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 32 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_scalar", CPTK_IS_SCALAR, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, - 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, - -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, - -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, - -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, - -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, 6, 7, 8, 9, -1, -1, -1, 10, 11, -1, 12, 13, + 14, 15, 16, 17, -1, 18, -1, 19, 20, 21, 22, 23, 24, 25, + 26, 27, -1, 28, 29, 30, 31, 32, 33, -1, 34, 35, 36, 37, + -1, -1, 38, -1, 39, -1, -1, -1, 40, 41, -1, -1, 42, 43, + 44, 45, -1, 46, 47, 48, -1, -1, 49, 50, 51, 52, -1, -1, + -1, 53, -1, -1, -1, -1, 54, -1, -1, 55, -1, -1, -1, -1, + 56, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, 58, -1, + -1, -1, -1, -1, 59, -1, 60, -1, -1, -1, -1, -1, -1, 61 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5e6b2ca37ac..be345f9aa47 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,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_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_SIGNED: return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; @@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: 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 aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#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) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index c891aff20f4..393f936ea72 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, ++__first) @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index da592b9fd23..4d2ef002e08 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template inline typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) { } - template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { + template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (__decltype(__n + 0) __niter = __n; __niter > 0; --__niter, ++__first) *__first = __value; diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 51ed5b07716..16980f5b356 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -397,7 +397,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // A scalar type is an arithmetic type or a pointer type // template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index d1438429487..4e334da0832 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -914,7 +914,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -925,7 +925,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1063,7 +1063,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, (void) ++__first) @@ -1074,7 +1074,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 222fd5fd900..558817329ce 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void __valarray_default_construct(_Tp* __b, _Tp* __e) { - _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e); + _Array_default_ctor<_Tp, __is_scalar_type<_Tp>::__value>::_S_do_it(__b, __e); } // Turn a raw-memory into an array of _Tp filled with __t From patchwork Tue Oct 10 22:10: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: 151040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp184067vqb; Tue, 10 Oct 2023 15:59:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG35Gpi8hn/CBrjuYyCio7R2m7qkSLdzBShJUaBSaTMNWLSd2yZZpYTocmuf16tigrlx+2N X-Received: by 2002:a05:6402:b35:b0:530:7ceb:334 with SMTP id bo21-20020a0564020b3500b005307ceb0334mr16816178edb.3.1696978756931; Tue, 10 Oct 2023 15:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696978756; cv=none; d=google.com; s=arc-20160816; b=ZU7soA2f9cs7Nl16wzFziaxtFQR6jPUD+bwui6lDTWlME6azhXIGlZSOeceAUEnKS/ j7XUs+L/yypNKFk0PxLEmUqFoVj0ZMq17dZ7e8k8ojAeeSJe3qXDZ1bOAiHu3JQ882yA 9NV9wJUzuiA/dIN4Y2INFeRmqUWohvhU6Q6BE/vTanUbwWI/AAYVCpqIz1k/bbBtEvrE HHaSBh4meWYfMLlQfPn2h1YiYU3eUkWAWf+IIh0yLU0fZf7OpxDQVFzHnQmF76XfS4Qp XY34KYPY2I2z5sFvVpJf+2rERIbThnCWFXxX77rBWP4GBICbSpgIas6zX/voM7jlH1dm b12Q== ARC-Message-Signature: i=1; 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:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=fSai/cghzDJKpSRK6EfXj5GoRmNsB1Egdsm9HFpLY0H3H1NSVXyXHEtGN4hUlbSM5/ 6wb+0CumV7mu6/IvEOzZ0cMruIi5JnptLbSQlmMEMmtetfEEwoiz34cu5T5/11HTeE01 9hqKLtxAuuPI/P3doz/sNPP4h0XpJYN76QQ5ZqdZTv+XWJR3F4rixJHv5BslBQ7M65Zu gJaeetmGHfq4D0Gfv4qFhfAr8CuNY11Zlas6pm2x08rthitobdA+orQe4N6vnCRXKpC1 2Ph9+wSss+NKKmEBTOmbahQ2BP2YXt3N0Pr3tCBcHtFWO2P1bpHUuPmBLnCOE8Bw3ejJ A7Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s3ze8lPl; 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 bc17-20020a056402205100b0053daf602198si485443edb.398.2023.10.10.15.59.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 15:59:16 -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=s3ze8lPl; 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 A76063952509 for ; Tue, 10 Oct 2023 22:42:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A76063952509 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696977758; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=s3ze8lPlXYbg17meGVrwhUF3nJRZ8OiHAr596SZjSgRH60wFnXwdon3zQ6ZgjzfYG EYdUwlzBxpzhcbQc6GCHnxBJ0gmnqkCkNb14kozK2pA/3T3KTVgwbI1Uh52Y0YeU+P jDvvs/CCKou7ZTNEBwpBE/+G/krDeKasgro/KF84= 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 BEB50396E853; Tue, 10 Oct 2023 22:41:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB50396E853 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 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 39AMfNIG019284; Tue, 10 Oct 2023 22:41:31 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnam9ukma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 22:41:30 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AMfB0c019908 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 15:41:11 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39AMFOUq024596 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 15:41:11 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v16 39/39] libstdc++: Optimize is_scalar trait performance Date: Tue, 10 Oct 2023 15:10:30 -0700 Message-ID: <20231010221520.3680267-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> References: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> <20231010221520.3680267-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: _g0RxOpFEUoCoEb0UoQGJ8T6m39SEQJA X-Proofpoint-ORIG-GUID: _g0RxOpFEUoCoEb0UoQGJ8T6m39SEQJA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=548 phishscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100175 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: 1776997480812710190 X-GMAIL-MSGID: 1779411196752415604 This patch optimizes the performance of the is_scalar trait by dispatching to the new __is_scalar built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_scalar): Use __is_scalar built-in trait. (is_scalar_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7e93923f44b..eb16a642575 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -775,11 +775,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_pointer; /// is_scalar +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar) + template + struct is_scalar + : public __bool_constant<__is_scalar(_Tp)> + { }; +#else template struct is_scalar : public __or_, is_enum<_Tp>, is_pointer<_Tp>, is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type { }; +#endif /// is_compound template @@ -3398,8 +3405,14 @@ template inline constexpr bool is_object_v = is_object<_Tp>::value; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scalar) +template + inline constexpr bool is_scalar_v = __is_scalar(_Tp); +#else template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; +#endif + template inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>;