From patchwork Tue Oct 10 09:46: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: 1845776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=s0uaueaA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WSw6nXcz1yq7 for ; Tue, 10 Oct 2023 20:54:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2967385696B for ; Tue, 10 Oct 2023 09:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2967385696B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931646; 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=s0uaueaAw40Cw6fHIHyjzaszUALHs1bp0P/hRDBoFd++HvSnsamyLMsjw6mPcqxeS Yz6LlbKav8gdFaiWThBLlQq3M0Jy51LymtKzEcgLG2IYq/zqVoEPN+6JPJ9ywvaPFE GAobVfb/AcSkdRf8x4WnOCvn57yOeZxIb4ub1RCM= 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 109123856DD5; Tue, 10 Oct 2023 09:53:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 109123856DD5 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 39A9cglR031051; Tue, 10 Oct 2023 09:53:39 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmscbb1hp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:53:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9rXjQ002012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:53: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 39A9qhT7014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:53: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 v15 01/39] c++: Sort built-in identifiers alphabetically Date: Tue, 10 Oct 2023 02:46:15 -0700 Message-ID: <20231010095229.3364786-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: YPcn9-ZBKQ9IUeF6bR24Nw1sCI7hCAXQ X-Proofpoint-ORIG-GUID: YPcn9-ZBKQ9IUeF6bR24Nw1sCI7hCAXQ 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100074 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=I9oCBLIp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WVg00sWz1ypX for ; Tue, 10 Oct 2023 20:55:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C11C63875462 for ; Tue, 10 Oct 2023 09:55:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C11C63875462 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931736; bh=E51VHNvIjo85oElkKVxOgPis9XqRCCmfkpQkxqzRBlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I9oCBLIpfxYLwuvJSDbRFx1ovlO8SuxhcAGOQJSSgQ8+FMOFd9Soprh5ECm/sbPnD Qrs5eSkmagbxZEQ+DRAbQuSQNo9ApKuVgo0jHIP7oE9fR7Ta1nkDTvyRh6u6iHzArd tKOk7vuzIfh6yx9JgBoFweQWz8EBJwcB3G11QQx4= 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 DC87D385CCAF; Tue, 10 Oct 2023 09:54:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC87D385CCAF 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 39A9kXpm022726; Tue, 10 Oct 2023 09:54:22 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhhqu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:54:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9rrPO021378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:53:53 -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 39A9qhT8014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:53:53 -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 v15 02/39] c-family, c++: Look up traits through gperf instead of enum rid. Date: Tue, 10 Oct 2023 02:46:16 -0700 Message-ID: <20231010095229.3364786-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ifr5-Bk38hz8EBAkDx-wEzyGziQMpOxh X-Proofpoint-ORIG-GUID: ifr5-Bk38hz8EBAkDx-wEzyGziQMpOxh 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_04,2023-10-09_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=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100072 X-Spam-Status: No, score=-11.7 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 | 26 ++++ gcc/cp/cp-objcp-common.cc | 6 +- gcc/cp/cp-trait-head.in | 31 +++++ gcc/cp/cp-trait.gperf | 75 ++++++++++++ gcc/cp/cp-trait.h | 249 ++++++++++++++++++++++++++++++++++++++ gcc/cp/parser.cc | 72 ++++------- 8 files changed, 418 insertions(+), 60 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..d27a6744cb9 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,30 @@ 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 -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 + 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); \ + binary = ($$3 == 2 ? "true" : "false"); \ + variadic = ($$3 == -1 ? "true" : "false"); \ + print $$2", CPTK_" $$1", "binary", "variadic", "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..efd2393e7a0 --- /dev/null +++ b/gcc/cp/cp-trait-head.in @@ -0,0 +1,31 @@ +%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; + bool binary; + bool variadic; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, true, false, false diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf new file mode 100644 index 00000000000..c3feb78d3c4 --- /dev/null +++ b/gcc/cp/cp-trait.gperf @@ -0,0 +1,75 @@ +%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; + bool binary; + bool variadic; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, true, false, false +"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false +"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false +"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false +"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false +"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false +"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false +"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false +"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false +"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false +"__is_abstract", CPTK_IS_ABSTRACT, false, false, false +"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false +"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false +"__is_base_of", CPTK_IS_BASE_OF, true, false, false +"__is_class", CPTK_IS_CLASS, false, false, false +"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false +"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false +"__is_empty", CPTK_IS_EMPTY, false, false, false +"__is_enum", CPTK_IS_ENUM, false, false, false +"__is_final", CPTK_IS_FINAL, false, false, false +"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false +"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false +"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false +"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false +"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false +"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false +"__is_pod", CPTK_IS_POD, false, false, false +"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false +"__is_same", CPTK_IS_SAME, true, false, false +"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false +"__is_trivial", CPTK_IS_TRIVIAL, false, false, false +"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false +"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false +"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false +"__is_union", CPTK_IS_UNION, false, false, false +"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false +"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false +"__remove_cv", CPTK_REMOVE_CV, false, false, true +"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true +"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true +"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true +"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true +"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false +"__bases", CPTK_BASES, false, false, true +"__direct_bases", CPTK_DIRECT_BASES, false, false, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h new file mode 100644 index 00000000000..db9476a8ac1 --- /dev/null +++ b/gcc/cp/cp-trait.h @@ -0,0 +1,249 @@ +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf -o -C -E -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ +/* Computed positions: -k'8' */ + +#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; + bool binary; + bool variadic; + 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 74 "../../gcc/cp/cp-trait.gperf" + {"__bases", CPTK_BASES, false, false, true}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, false, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, false, false, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, false, false, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, 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..555a0bf90bb 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,13 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, 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; /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11042,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 +11058,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 +11073,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); @@ -11110,7 +11089,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) } type2 = trailing; } - else if (binary) + else if (trait->binary) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); @@ -11122,7 +11101,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type2 == error_mark_node) return error_mark_node; } - else if (variadic) + else if (trait->variadic) { auto_vec trailing; while (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) @@ -11144,7 +11123,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 +11137,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 +20060,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 09:46: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: 1845777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=M0PmSOZC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WVC3pkwz1ypX for ; Tue, 10 Oct 2023 20:55:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 772C03856962 for ; Tue, 10 Oct 2023 09:55:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 772C03856962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931712; bh=vdCBSwYGY02/Rqjhj31V9NX5TVKYvM9rD9Hpnc1RJFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=M0PmSOZC3+M6+dYTXqLUC6BIXXCs04GsB1T1yehtywvZGGsQy0bVP8hP+Dz5jQYq7 MploPfNxrLlWdOgH21qc3TwOpF9GmWa4QnClUqAgKXSPh/dY8dnHLPic1nrRZsqRUu 46M7r1Trmx+iJQ/B20yWcaUi0oKgfo/FTEeazd34= 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 8F79E385E00F; Tue, 10 Oct 2023 09:54:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F79E385E00F 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 (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A9jPJB023422; Tue, 10 Oct 2023 09:54:48 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqrmbwht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:54:47 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9sexS029707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:54: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 39A9qhT9014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:54: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 v15 03/39] c++: Implement __is_const built-in trait Date: Tue, 10 Oct 2023 02:46:17 -0700 Message-ID: <20231010095229.3364786-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: rMdmaHwvkL8OpCovQm4QhahacXK0NL3_ X-Proofpoint-GUID: rMdmaHwvkL8OpCovQm4QhahacXK0NL3_ 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 bulkscore=0 impostorscore=0 malwarescore=0 clxscore=1034 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100074 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * 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/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 +++ 7 files changed, 134 insertions(+), 99 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C 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 c3feb78d3c4..ad720832ccb 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -43,6 +43,7 @@ struct cp_trait { "__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false "__is_base_of", CPTK_IS_BASE_OF, true, false, false "__is_class", CPTK_IS_CLASS, false, false, false +"__is_const", CPTK_IS_CONST, false, false, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false "__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false "__is_empty", CPTK_IS_EMPTY, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index db9476a8ac1..4a2100779cf 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -1,6 +1,6 @@ /* C++ code produced by gperf version 3.1 */ /* Command-line: gperf -o -C -E -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ -/* Computed positions: -k'8' */ +/* Computed positions: -k'6,8' */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 79, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -106,6 +106,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; @@ -116,116 +118,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 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, #line 73 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, + {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, true, false, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, #line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, 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, true, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false} + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46: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: 1845779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=otTomWun; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WWQ2W5yz1ypX for ; Tue, 10 Oct 2023 20:56:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D68538323F6 for ; Tue, 10 Oct 2023 09:56:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D68538323F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931776; 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=otTomWun52wEynJSdy/RbEjSSYh76iY8YEBcppszBncX0ST1h7ACofBtUZi256NG4 31V9jPcyqRO7o9mQznTJ/nu6mdpe+WPxGMQ+xDD54X3ksCColQWbrDpGvqJvvDguzz TMs6idU2nk2XW0IerbFDMfYXfnZgv/QKT82IIEkc= 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 DFB7D3875DEF; Tue, 10 Oct 2023 09:55:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFB7D3875DEF 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 39A9X06n031962; Tue, 10 Oct 2023 09:55: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 3tmtf3jdtm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:55:49 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9tkAs029869 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:55:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTA014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:55:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 04/39] libstdc++: Optimize is_const trait performance Date: Tue, 10 Oct 2023 02:46:18 -0700 Message-ID: <20231010095229.3364786-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pfzdYHVSO6SBQ2Y_HfyAWoiRDF9m7TTf X-Proofpoint-ORIG-GUID: pfzdYHVSO6SBQ2Y_HfyAWoiRDF9m7TTf 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_05,2023-10-09_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=837 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-2310100074 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=pwaeVIJX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WXz6TtKz1ypX for ; Tue, 10 Oct 2023 20:57:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3AB538845A0 for ; Tue, 10 Oct 2023 09:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3AB538845A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931857; bh=YDtEiuu7hlqxQBmf5IArr9gL3ERNVdzRjrbHoPmmEOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pwaeVIJXsRfera7lQd/d4NXV/xYNoVmrf+qgNe6FlviC5cJ/okKzoa1NvyBcySGe8 QhWOB66MDslWpmhFPB3eZ7tPDOk151jsewrXxnfcKSbO396Y72lKt1ri74i5yGUHhf rTOwWoLlwbdB3/z6OnNOk+8QZHqwV674S1SvWOKI= 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 98D983861898; Tue, 10 Oct 2023 09:56:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98D983861898 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 39A9qZ5t008675; Tue, 10 Oct 2023 09:56:59 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqb549dk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:56:58 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9uVl6022727 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:56:31 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTB014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:56:31 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 05/39] c++: Implement __is_volatile built-in trait Date: Tue, 10 Oct 2023 02:46:19 -0700 Message-ID: <20231010095229.3364786-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jcjC_QU2QV99FKHzVfxui48OvbYrgOVv X-Proofpoint-GUID: jcjC_QU2QV99FKHzVfxui48OvbYrgOVv 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=846 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100074 X-Spam-Status: No, score=-12.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 ad720832ccb..ead136495fd 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -64,6 +64,7 @@ struct cp_trait { "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false "__is_union", CPTK_IS_UNION, false, false, false +"__is_volatile", CPTK_IS_VOLATILE, false, false, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false "__remove_cv", CPTK_REMOVE_CV, false, false, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 4a2100779cf..0fa702f1441 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -82,7 +82,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, @@ -118,7 +118,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, @@ -127,27 +127,29 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, @@ -161,9 +163,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, @@ -217,19 +219,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46: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: 1845781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=PiQ2zUId; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WYR5DjCz1ypX for ; Tue, 10 Oct 2023 20:58:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F3D1385C420 for ; Tue, 10 Oct 2023 09:58:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F3D1385C420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931881; 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=PiQ2zUIdP7jDp0qWvNtdPXlLKYT2n7i+nHmCgo5qLWh1qHom9lJRuL5MzHJ1GZkNH P5FjYXxH2gEkqTciH9Cy1aE2qEFF79N9hx03g6m4pSGY0KYzfkm0zJjsGLzULU5ron PlHNvzXPBEZ9qv66CzoNNJRurPzxMfBDs1JTvH1I= 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 74631386186D; Tue, 10 Oct 2023 09:57:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74631386186D 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 39A9oeOu025124; Tue, 10 Oct 2023 09:57:41 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843mch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:57:40 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9vWMO028701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:57:32 -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 39A9qhTC014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:57:32 -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 v15 06/39] libstdc++: Optimize is_volatile trait performance Date: Tue, 10 Oct 2023 02:46:20 -0700 Message-ID: <20231010095229.3364786-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OIYE5X8zwDYgAduRUX3FP2k34WtSBrER X-Proofpoint-GUID: OIYE5X8zwDYgAduRUX3FP2k34WtSBrER 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=884 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100074 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=lUqERqmQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WZc4BcCz1ypX for ; Tue, 10 Oct 2023 20:59:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 69942385B528 for ; Tue, 10 Oct 2023 09:59:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69942385B528 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696931942; bh=TS762ar6VWU8MuTJetz8HA5e3mFjJbTkIUXypKN8zso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lUqERqmQDCib7WgTfrYuvwyrrOhFt4O0B2BhU+Gjb1rk63skO+mrv2l91EpJyF3Vl AMParhDvMXfA6cLq3GSR1Xak3RA2VgWALzKJPtHvAjhWxcpZ52H1EtYYeJx221kfLp LemE5ETsrwWZ+4t14wsJkvm0a9QwShP9GdFUF744= 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 6912338323EA; Tue, 10 Oct 2023 09:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6912338323EA 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 39A9o1sd023289; Tue, 10 Oct 2023 09:58:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmu6qj2f9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:58:29 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9w6Fq021920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:58:06 -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 39A9qhTD014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:58:06 -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 v15 07/39] c++: Implement __is_array built-in trait Date: Tue, 10 Oct 2023 02:46:21 -0700 Message-ID: <20231010095229.3364786-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: baslZlFRvs6M_pTdsyM9W6bBzdRUm5Np X-Proofpoint-GUID: baslZlFRvs6M_pTdsyM9W6bBzdRUm5Np 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_05,2023-10-09_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=848 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-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 ead136495fd..a0c313af253 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -40,6 +40,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false "__is_abstract", CPTK_IS_ABSTRACT, false, false, false "__is_aggregate", CPTK_IS_AGGREGATE, false, false, false +"__is_array", CPTK_IS_ARRAY, false, false, false "__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false "__is_base_of", CPTK_IS_BASE_OF, true, false, false "__is_class", CPTK_IS_CLASS, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 0fa702f1441..5796810aa81 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,108 +118,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 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, 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, true, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, false, false, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} }; @@ -228,10 +230,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 09:46: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: 1845783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=W+XmKw/y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wbm0wrXz1ypX for ; Tue, 10 Oct 2023 21:00:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A566388206C for ; Tue, 10 Oct 2023 10:00:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A566388206C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932002; 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=W+XmKw/yqScZHnE02yxRsQqFW9BE2iIZDzkR7wDpM6Si4L9+1LP0xs+eUynHsdOjb F/ZqaTS4pJHYvs9PXRLEAzdAvelMj3pg9WAfOkYj97zDEo9FT4HsUKfkyLZYJ+xrvZ pNdO/jMWIKMx3qsEqL4TuJKECzxCmqlGKzszrgh0= 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 9E41D38618B1; Tue, 10 Oct 2023 09:59:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E41D38618B1 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 39A9ffKh032765; Tue, 10 Oct 2023 09:59:02 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktknu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:59:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9wkxC021930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:58:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTE014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:58:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 08/39] libstdc++: Optimize is_array trait performance Date: Tue, 10 Oct 2023 02:46:22 -0700 Message-ID: <20231010095229.3364786-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iDnAUbQtzbpUJcFzfH9CFBpjTKgsz1Gg X-Proofpoint-GUID: iDnAUbQtzbpUJcFzfH9CFBpjTKgsz1Gg 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=474 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Abj9LMbI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wbs5q8Jz1yq7 for ; Tue, 10 Oct 2023 21:00:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B35EB386EC25 for ; Tue, 10 Oct 2023 10:00:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B35EB386EC25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932007; bh=8gSCqitQVDe9UPE/tYPhYEVIcJvJDP+fQA5gMalbqcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Abj9LMbIF0SjxydSvF+HLa4VO9d6HFEDTlxHNDlyQNoZzFurVTbdvQ6iSYcwv+y4z FOkHH9R+lO1DizHFaWaus/DYgfGG181QtKoE5l7DPr3oSwI5SYpAuc5QrOIyTIJOfX GcK3ckOHEJa/VrHX5JjVDP7YVX8nqhPg66qKRnLY= 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 75A9D3881D23; Tue, 10 Oct 2023 09:59:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75A9D3881D23 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 39A9xT5P028839; Tue, 10 Oct 2023 09:59:44 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmnkwnjb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 09:59:44 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39A9xLNL028918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 02:59:21 -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 39A9qhTF014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 02:59:21 -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 v15 09/39] c++: Implement __is_unbounded_array built-in trait Date: Tue, 10 Oct 2023 02:46:23 -0700 Message-ID: <20231010095229.3364786-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: eoh8-Eb_ialEcWMWEsg8e_CJjtUlYfe2 X-Proofpoint-GUID: eoh8-Eb_ialEcWMWEsg8e_CJjtUlYfe2 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 spamscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=774 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-12.1 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_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+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * 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 a0c313af253..8059e1e8d9e 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -64,6 +64,7 @@ struct cp_trait { "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false +"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false "__is_union", CPTK_IS_UNION, false, false, false "__is_volatile", CPTK_IS_VOLATILE, false, false, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 5796810aa81..b52f2985a66 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -118,7 +118,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, @@ -127,30 +127,32 @@ 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, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 72 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" @@ -163,9 +165,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, @@ -221,21 +223,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46: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: 1845786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=V2XswWbB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WfD5wdsz1yq7 for ; Tue, 10 Oct 2023 21:02:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4B363836E85 for ; Tue, 10 Oct 2023 10:02:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4B363836E85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932130; 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=V2XswWbBYPKgX5Y8wYtXEy8dpCPGeYdyPXuq1H80haN+EWWpikN6LOQMjXhYWyobo ihgqwQPdCA6DWpHVWSPH5VI0/fqu8FPSAklWkQrXNNf1Mq4RiRNJTuJdDINHw/YZ/B hENtwwdtFfVS4CKBOxzXpIHYgc1r8kxKnQgheWPE= 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 26D323861833; Tue, 10 Oct 2023 10:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26D323861833 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 (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A9jPJM023422; Tue, 10 Oct 2023 10:00:35 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqrmbx14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:00:35 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA0MSM008057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:00: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 39A9qhTG014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:00:21 -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 v15 10/39] libstdc++: Optimize is_unbounded_array trait performance Date: Tue, 10 Oct 2023 02:46:24 -0700 Message-ID: <20231010095229.3364786-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: f1_cvmkBOD-PUY_KsNI604c9fYSzERe- X-Proofpoint-GUID: f1_cvmkBOD-PUY_KsNI604c9fYSzERe- 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 bulkscore=0 impostorscore=0 malwarescore=0 clxscore=1034 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxlogscore=629 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=e8tQTdBc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wf959y1z1yq7 for ; Tue, 10 Oct 2023 21:02:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 326D338AA260 for ; Tue, 10 Oct 2023 10:02:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 326D338AA260 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932126; bh=3tSrlYZ32ywfAvRppvR3NnYmOkRzeSJp96/0MqfTM1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=e8tQTdBchGsMefJkB9jnv8UWl0Dlrw205PfUM5da57mDSNBBZ2fpPzq505ydXoHuo txdqckPimuxW2Svcs/+24rNQ0MelT8/KUZJw+lhhrJeQy/uf+tDchBPr6AN1fyra1Y 1kPEKN6MrEaCTV1qDOhUZ+ROgA89bZ+2Xm+Tk0og= 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 D37FA3883016; Tue, 10 Oct 2023 10:01:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D37FA3883016 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 39A9YbfJ021511; Tue, 10 Oct 2023 10:01:06 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktkwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:01:06 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA0l6e023388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:00: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 39A9qhTH014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:00:47 -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 v15 11/39] c++: Implement __is_bounded_array built-in trait Date: Tue, 10 Oct 2023 02:46:25 -0700 Message-ID: <20231010095229.3364786-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: nbja0atCX2gyYXtM9SZNU-7urofL18Gc X-Proofpoint-GUID: nbja0atCX2gyYXtM9SZNU-7urofL18Gc 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=679 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-12.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 8059e1e8d9e..86d7453c9f8 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -43,6 +43,7 @@ struct cp_trait { "__is_array", CPTK_IS_ARRAY, false, false, false "__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false "__is_base_of", CPTK_IS_BASE_OF, true, false, false +"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false "__is_class", CPTK_IS_CLASS, false, false, false "__is_const", CPTK_IS_CONST, false, false, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b52f2985a66..a44498b4b90 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -82,7 +82,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, @@ -118,7 +118,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, @@ -127,54 +127,56 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 73 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" @@ -183,7 +185,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, @@ -193,27 +195,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, false, false, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, false, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, @@ -221,9 +223,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} }; @@ -232,12 +234,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 09:46: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: 1845787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=HwewkU+m; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WgL3wx3z1yq7 for ; Tue, 10 Oct 2023 21:03:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81BAB385276D for ; Tue, 10 Oct 2023 10:03:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81BAB385276D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932188; 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=HwewkU+mVIRH7IDr5yG2bGS8jCBx6EuPUSW4Lid/6kYbtbmvavKCLotMUZOM0s3XX pIQv8iZsPTmw2VtuFoojkq32ZR6/MQ6Q4S5CjpOdR3Y2jhg3450Hx0qpaS42mwgx5l GdcLE6xLDUKPdkm+z9EcPWxcpyd4Ez0itJqt8Nok= 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 9EC1338983BA; Tue, 10 Oct 2023 10:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EC1338983BA 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 39A9kiGW010922; Tue, 10 Oct 2023 10:01:30 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmscbb247-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:01:30 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA1KaB030892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:01:20 -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 39A9qhTI014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:01:20 -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 v15 12/39] libstdc++: Optimize is_bounded_array trait performance Date: Tue, 10 Oct 2023 02:46:26 -0700 Message-ID: <20231010095229.3364786-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 52SHC3UPU3pLc77KypfDw8FA8WzdxCjQ X-Proofpoint-ORIG-GUID: 52SHC3UPU3pLc77KypfDw8FA8WzdxCjQ 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=660 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 mlxscore=0 malwarescore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Utfo1zvu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WgR30LVz1yq7 for ; Tue, 10 Oct 2023 21:03:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B6F23952493 for ; Tue, 10 Oct 2023 10:03:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B6F23952493 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932193; bh=HSdO0OOLf1PWgCvOvulrMfkB6X2z/lR3MuHXF9yAXZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Utfo1zvuPyu2lyA0Cgo7CzrHuaBg7estiW5aVoN4GZMoWKvwS42hV3qVa0DTI3t3U yOEJkNhZb/1Eeey6kB7v1fC2EnmlSHG2FxWMUYfrVP02Sd8surR696xscGdo9T+f8c Ei/tdt2RK68G40iCynXZG6x/lNLDKPuPVhiDWe54= 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 20A66389EC4A; Tue, 10 Oct 2023 10:01:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20A66389EC4A 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 39A9mm43011410; Tue, 10 Oct 2023 10:01:49 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktm1w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:01:49 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA1lW3003458 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:01:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTJ014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:01:47 -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 v15 13/39] c++: Implement __is_scoped_enum built-in trait Date: Tue, 10 Oct 2023 02:46:27 -0700 Message-ID: <20231010095229.3364786-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mrVP1y7WiASHcl0ltyBWxgoynRR_bLxq X-Proofpoint-GUID: mrVP1y7WiASHcl0ltyBWxgoynRR_bLxq 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=865 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 86d7453c9f8..705bf377b87 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -60,6 +60,7 @@ struct cp_trait { "__is_pod", CPTK_IS_POD, false, false, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false "__is_same", CPTK_IS_SAME, true, false, false +"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false "__is_trivial", CPTK_IS_TRIVIAL, false, false, false "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index a44498b4b90..8c5f0985f00 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,56 +118,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 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 74 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, @@ -175,22 +179,18 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" @@ -199,47 +199,48 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, 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 09:46: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: 1845790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qCbUBC7L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WgY5ZgCz1yq7 for ; Tue, 10 Oct 2023 21:03:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE061385276D for ; Tue, 10 Oct 2023 10:03:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE061385276D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932199; 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=qCbUBC7LH/oVaWoncx19J3ud9v4FSudSh9TV1AAsWc5gKgDhpKMNAdrTgECuBYcxd 1TwwM263G9rOPff8pNjGMwF6xB7BD47E4Sgl7gRT0kUittg74+h49drqhP5rnuqvZi G3cCAoBH0bzfCR23DZE9pCp9+Ief2crn8/jj4pIk= 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 E6CDB3887F4E; Tue, 10 Oct 2023 10:02:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6CDB3887F4E 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 39A9wh9q018346; Tue, 10 Oct 2023 10:02:20 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqb549xn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:02:20 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA24AH029377 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:02:04 -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 39A9qhTK014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:02:04 -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 v15 14/39] libstdc++: Optimize is_scoped_enum trait performance Date: Tue, 10 Oct 2023 02:46:28 -0700 Message-ID: <20231010095229.3364786-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: oTb7kcE-L1CgGHs_RsNf83ZFj_W3EJF_ X-Proofpoint-GUID: oTb7kcE-L1CgGHs_RsNf83ZFj_W3EJF_ 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=890 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Vz+eHPFY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WgV5150z1yq7 for ; Tue, 10 Oct 2023 21:03:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE522395203F for ; Tue, 10 Oct 2023 10:03:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE522395203F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932196; bh=KgF6ty/X55jDRsWMSVXE9V2xWliMhNJann0MqimPgQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Vz+eHPFYM/c977rEOMXqnOe2lhXq+0tJ0hvX6BYYuJk229DZ1V2aWTf+4e/owb6Fq k+NnRUIri8otXIFA40TUUkIObWSt/UUlrc654caRdq3mBoU00rtO6ZN6gK64riy56L TPVBQh+ObUxe9wc8hdBrDNfe3iM1WRVsI4gUCuiA= 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 AB96A382798F; Tue, 10 Oct 2023 10:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB96A382798F 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 39AA2aGi012722; Tue, 10 Oct 2023 10:02:52 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843mxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:02:52 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA2i7l029414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:02: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 39A9qhTL014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:02: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 v15 15/39] c++: Implement __is_member_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:29 -0700 Message-ID: <20231010095229.3364786-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: APVUk79-EuPBXElcPGEq_ndDFWW-leAU X-Proofpoint-GUID: APVUk79-EuPBXElcPGEq_ndDFWW-leAU 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=972 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 705bf377b87..d3f1343448b 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, false, false, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false +"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 8c5f0985f00..3de93349f77 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 111, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,69 +118,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 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 75 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, #line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" @@ -189,58 +187,63 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, #line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, #line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false} + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, 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 09:46: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: 1845791 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=N4X3bh4q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Whg0FZyz1yq7 for ; Tue, 10 Oct 2023 21:04:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E8A0395ACE9 for ; Tue, 10 Oct 2023 10:04:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E8A0395ACE9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932257; 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=N4X3bh4qNUowR5dkHKIpmXgjM94fC+CA+giaZsnU1MK+5Qbph7ohjshcMor0IyC0P vxc+fyZdaPEzfdQ9PUfpmKk85NS8zqWcW9PeP1M0eofEOcefIT2NDEFBNimzQ71Y+B 8QsKXWbZ0mnXKUkdYZAt0P2Q/vSRs+2ofGk7iRMw= 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 4EBA23959C54; Tue, 10 Oct 2023 10:03:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EBA23959C54 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 39A9nkg2002323; Tue, 10 Oct 2023 10:03:43 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhjhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:03:43 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA3GIw022660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:03:16 -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 39A9qhTM014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:03:16 -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 v15 16/39] libstdc++: Optimize is_member_pointer trait performance Date: Tue, 10 Oct 2023 02:46:30 -0700 Message-ID: <20231010095229.3364786-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: XLgztR_4zCabHhlNPLjlCCJlAWr3odwd X-Proofpoint-ORIG-GUID: XLgztR_4zCabHhlNPLjlCCJlAWr3odwd 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_05,2023-10-09_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=452 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845792 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TAMWJrNd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Whv2yWVz1yq7 for ; Tue, 10 Oct 2023 21:04:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C62538313B1 for ; Tue, 10 Oct 2023 10:04:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C62538313B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932269; bh=81VLhs9usj384UdYQJr1ZU4BK90tnSVHyltMJ88T/7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TAMWJrNdPCV22Oumbe1c4opMUkq7XdaUPUUUf7ukIbDgz6uDbmGXOk8H+UD0/+n6f 6WG0JHueVPkIOMMn2/29tEoKTEWQEELWQr4tpUE3A7hiv3N8e0a+URPXscVqQZ51Mt QoeGpAAZ43DMvLgEXrt3YOHeGhPOALSXRoPToBVQ= 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 782A43959C94; Tue, 10 Oct 2023 10:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 782A43959C94 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 39AA38c0014431; Tue, 10 Oct 2023 10:04:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3jepb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:04:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA3tmh031271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:03:55 -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 39A9qhTN014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:03:55 -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 v15 17/39] c++: Implement __is_member_function_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:31 -0700 Message-ID: <20231010095229.3364786-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: m-EZRG7Ep1k40NBOFzvt6tWR26IgXCpQ X-Proofpoint-ORIG-GUID: m-EZRG7Ep1k40NBOFzvt6tWR26IgXCpQ 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_05,2023-10-09_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=921 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-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 d3f1343448b..505f49bca07 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, false, false, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false +"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 3de93349f77..0dcb08cc601 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 111, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,132 +118,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 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 76 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, 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, true, false, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false} +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, false, false, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TfHncO5E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wk34MJWz1ypX for ; Tue, 10 Oct 2023 21:05:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EB473882107 for ; Tue, 10 Oct 2023 10:05:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EB473882107 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932329; 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=TfHncO5EteF1q7yn01SwROAR+2lPROU0Maa0qm9Kv/FbCq4W7//pkkAGbH1NfkkIQ uwB5x3vcssocTMfoscuVSMY87Bwixt9Z1zAGJEfAkYwtxZyfm9LVlKb8MQZzBo7EIV kCJIVETY8iZCjvS3r/1URhzUWJlhUnSZs279eeNE= 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 7CEDD383139B; Tue, 10 Oct 2023 10:05:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CEDD383139B 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 39AA2KNp001781; Tue, 10 Oct 2023 10:05:08 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktmg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:05:07 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA4bBe031451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:04:37 -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 39A9qhTO014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:04:37 -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 v15 18/39] libstdc++: Optimize is_member_function_pointer trait performance Date: Tue, 10 Oct 2023 02:46:32 -0700 Message-ID: <20231010095229.3364786-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: hKeNqR4ggzvmAIdcrTebPVhOM09-szww X-Proofpoint-GUID: hKeNqR4ggzvmAIdcrTebPVhOM09-szww 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=666 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845794 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qPg1U5O/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wkv0Yvxz1ypX for ; Tue, 10 Oct 2023 21:06:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11A473860778 for ; Tue, 10 Oct 2023 10:06:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11A473860778 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932373; bh=ZxicclcEtXuk3UC5lvqeoPwiuYE+a2txDbXocIlIZ3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qPg1U5O/b20a8HA2S/RS4mxnWaLedt3CtAnhjPXJ5dU8WTMBeAeJPFPAnlS5vRTMt iFCugTSwZcNs8cWEKC7/Zwvy69IjeT2co1TziNChbUpOgVaYH0IOibFw6elUugQ1Wf blVaykN0UMJMIfD35yDRo4eIpHjm5tkoYt7uEsPQ= 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 2767E395BC11; Tue, 10 Oct 2023 10:05:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2767E395BC11 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 39A9db6F025597; Tue, 10 Oct 2023 10:05:49 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmnkwnk3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:05:49 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA5c94024297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:05:38 -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 39A9qhTP014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:05:37 -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 v15 19/39] c++: Implement __is_member_object_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:33 -0700 Message-ID: <20231010095229.3364786-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: --qyQGrFBwJuepc3M5S_jPEWa6nCBpad X-Proofpoint-GUID: --qyQGrFBwJuepc3M5S_jPEWa6nCBpad 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 spamscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=921 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 505f49bca07..4a099120512 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -54,6 +54,7 @@ struct cp_trait { "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false +"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 0dcb08cc601..f1fce9914b0 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -118,7 +118,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, @@ -127,57 +127,57 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 77 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, 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, true, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, @@ -187,25 +187,25 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, @@ -213,12 +213,14 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" @@ -231,7 +233,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} }; @@ -242,8 +244,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 09:46:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845795 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Lj/Zr7SW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WlR3mY2z1ypX for ; Tue, 10 Oct 2023 21:06:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C380E396E413 for ; Tue, 10 Oct 2023 10:06:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C380E396E413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932400; 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=Lj/Zr7SWmdqO07J4lhGDotmi12z85BaCV9IscEIwx5pncq7kc9sGKdWyBzSHisliZ EGB0Qvn5qtDfUouGKnqX518we6zHBAbwtVtO/J9MPX4lzqPodkZvHtwN+m4ojuUBae gX3X7ZLDWKD1bfhRBQKE3BzE6a3KFjBkItEc9Isw= 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 43AE6385800A; Tue, 10 Oct 2023 10:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43AE6385800A 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 39AA1jrL000585; Tue, 10 Oct 2023 10:06:19 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktmn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:06:19 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA673t023076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:06: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 39A9qhTQ014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:06:06 -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 v15 20/39] libstdc++: Optimize is_member_object_pointer trait performance Date: Tue, 10 Oct 2023 02:46:34 -0700 Message-ID: <20231010095229.3364786-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: VFkZXOwLJQ2lc_LrfsRhVK_Xdy4dU9S9 X-Proofpoint-GUID: VFkZXOwLJQ2lc_LrfsRhVK_Xdy4dU9S9 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=594 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tG6Q9jlY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wmg4PzMz1ypX for ; Tue, 10 Oct 2023 21:07:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 711EC386186F for ; Tue, 10 Oct 2023 10:07:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 711EC386186F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932465; bh=IhN187CmjxAGfqkgmtGzY73IBOFklLGmqDlK64gYrwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tG6Q9jlYZJIUJhS2XKKiqg4tWiZQKyPyFKlAFLpjB69dcIBK5h1mJq3C8B/YJvZUy dpS/5xmO7ouLZpigXlnBmmTydvVtUuLGYtfsxfH3X72sYOvwyctv7CVcqAs5zC4jxK uOz9dB081C5vTZrORFMNYqVYZToRe4b87EgjAw9s= 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 25D34396E870; Tue, 10 Oct 2023 10:06:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25D34396E870 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 39A9PlUH006791; Tue, 10 Oct 2023 10:06:53 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmkta6w6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:06:53 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA6oWe009233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:06:50 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTR014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:06:50 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 21/39] c++: Implement __is_reference built-in trait Date: Tue, 10 Oct 2023 02:46:35 -0700 Message-ID: <20231010095229.3364786-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kSJKlfaTxbX-OZwFegrOXnCTbASJYUS1 X-Proofpoint-GUID: kSJKlfaTxbX-OZwFegrOXnCTbASJYUS1 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxscore=0 mlxlogscore=935 clxscore=1034 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 4a099120512..1d902612f5a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -62,6 +62,7 @@ struct cp_trait { "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false "__is_pod", CPTK_IS_POD, false, false, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false +"__is_reference", CPTK_IS_REFERENCE, false, false, false "__is_same", CPTK_IS_SAME, true, false, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f1fce9914b0..7aa695210ce 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 94, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,58 +118,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 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 78 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, @@ -177,7 +177,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, @@ -187,7 +187,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, @@ -209,15 +209,13 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, @@ -225,6 +223,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" @@ -233,8 +233,10 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false} }; static const signed char lookup[] = @@ -243,9 +245,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 09:46:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=noeXD3r6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wmm2SzLz1ypX for ; Tue, 10 Oct 2023 21:07:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52DD53817750 for ; Tue, 10 Oct 2023 10:07:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52DD53817750 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932469; 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=noeXD3r6Tnrgrh8fseD0DOvBtNUKA37ruhhWQzjziKUuS+Vi4fllHxHWhha+7j0WT r+ntW/ImKOw1rtcY/6OZx4S2xb5s2gzrwh3l9MyHg47q2G0JT7REkMIqtEC3miYswx m5gKE1LugSG1stscuCWHIEwavoL4WJ1XuBChskRM= 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 7030439960F6; Tue, 10 Oct 2023 10:07:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7030439960F6 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 39AA6bnk025105; Tue, 10 Oct 2023 10:07:27 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvg39jc7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:07:27 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA7Iak009331 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:07:18 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTS014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:07:18 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 22/39] libstdc++: Optimize is_reference trait performance Date: Tue, 10 Oct 2023 02:46:36 -0700 Message-ID: <20231010095229.3364786-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 9B7PGiT0XlFhQw1Y2EuOh6F2t3vaHf_- X-Proofpoint-ORIG-GUID: 9B7PGiT0XlFhQw1Y2EuOh6F2t3vaHf_- 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=783 mlxscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Cv8fpXin; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WpL49wvz1ypX for ; Tue, 10 Oct 2023 21:09:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 911D03856DD0 for ; Tue, 10 Oct 2023 10:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 911D03856DD0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932552; bh=/c2z88SLVeUvXRYf60HVB1ej0JeTjWr4np/brO00RTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Cv8fpXinNPOKbnCY0JP01d18WZxBxfGhEwZ0irPI00MzaNEkgi3isiExYMlnUiMVf X1k+qJX9AvwpayzG2ai15szOItaNRBg9HjTsPFabq00eZRvgHkfMW82IXZShwNH1i+ fxuaqRYgJXVMZEhWNEPMrTHlZACW9moUIeXzoRNA= 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 F40873AA800E; Tue, 10 Oct 2023 10:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F40873AA800E 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 39AA7aqj029559; Tue, 10 Oct 2023 10:08:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhk19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:08:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA7fsO030267 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:07: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 39A9qhTT014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:07: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 v15 23/39] c++: Implement __is_function built-in trait Date: Tue, 10 Oct 2023 02:46:37 -0700 Message-ID: <20231010095229.3364786-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: PE721TmJtqfet6lYrRJC8ub34U7cu5MC X-Proofpoint-ORIG-GUID: PE721TmJtqfet6lYrRJC8ub34U7cu5MC 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_05,2023-10-09_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=956 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 1d902612f5a..4fa14de3e90 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -51,6 +51,7 @@ struct cp_trait { "__is_empty", CPTK_IS_EMPTY, false, false, false "__is_enum", CPTK_IS_ENUM, false, false, false "__is_final", CPTK_IS_FINAL, false, false, false +"__is_function", CPTK_IS_FUNCTION, false, false, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 7aa695210ce..c53e234f631 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 94, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,113 +118,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 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 79 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, 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, true, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" @@ -233,10 +233,12 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, #line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false} + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, false, false, false}, +#line 84 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} }; static const signed char lookup[] = @@ -244,11 +246,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 09:46:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=pq6EW2By; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wp56lKTz1ypX for ; Tue, 10 Oct 2023 21:09:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C7F4385DC10 for ; Tue, 10 Oct 2023 10:08:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C7F4385DC10 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932539; 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=pq6EW2ByN2V9VGF0+0Tpyt+vS0N48ufjEx8p4EjnINT+5bGTMywGKcpIRi9tvbhT2 reFzrn0BvU+vEHXvd1G5vCWSXm7dmGRvLTEMki8awKSCYtwjiSWjVgRZHcgEGYBwaT cIS58Rh0chPbvNmeaDr+kHhVj4kdHgZfS0INZ6kQ= 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 CAECA3888839; Tue, 10 Oct 2023 10:08:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAECA3888839 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 39A9Ys4N014102; Tue, 10 Oct 2023 10:08:32 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhk2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:08:32 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA8I9b004613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:08:18 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTU014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:08:18 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 24/39] libstdc++: Optimize is_function trait performance Date: Tue, 10 Oct 2023 02:46:38 -0700 Message-ID: <20231010095229.3364786-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2oHVPXHjq23RpEUuAPL9DoSKcLdi21lo X-Proofpoint-ORIG-GUID: 2oHVPXHjq23RpEUuAPL9DoSKcLdi21lo 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_05,2023-10-09_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=583 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=EssV47Ro; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wpq356Qz1ypX for ; Tue, 10 Oct 2023 21:09:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B35B3BF90D1 for ; Tue, 10 Oct 2023 10:09:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B35B3BF90D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932577; 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=EssV47RoIIySVVqYOLn+iNghMJJz/PxvAZpDK9hH1Q81ojn3OmnoZbJNdR7gVfD0Z tc1t70CohSpCuoZMZNJz/m48RXRMGVEKMLUgFyozqbCyfarZUvXA5RBot9U0Zj+r6s TELDBEIM4AXuqsmYbL+ei9uAvt2QoTi9cjMwJVyM= 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 3466A3836E81; Tue, 10 Oct 2023 10:09:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3466A3836E81 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 39A9mj1a023644; Tue, 10 Oct 2023 10:09:06 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3jf9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:09:06 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA8kVw030500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:08:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTV014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:08:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 25/39] libstdc++: Optimize is_object trait performance Date: Tue, 10 Oct 2023 02:46:39 -0700 Message-ID: <20231010095229.3364786-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: N3tZedEqDITR1vu0DvPE_QkzELrDAvi_ X-Proofpoint-ORIG-GUID: N3tZedEqDITR1vu0DvPE_QkzELrDAvi_ 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_05,2023-10-09_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=794 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-2310100075 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jvpAuiLY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wrf5Qqwz20Xn for ; Tue, 10 Oct 2023 21:11:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE26138323D4 for ; Tue, 10 Oct 2023 10:11:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE26138323D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932672; bh=GlrOZMDEggWeopNi30iP1MfE64HfsvagcTuK3W4h43M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jvpAuiLY1qjqk1apdqBbGi6gkp5+YCOx3W/NUGH67hYZ6hifOg12fsPZiZShdRGYJ gHViYVB7grtI74+yaBZlq4WZa3/ICUu0u75FTEI/Fou/Uo8I5QJYsdMQVvz1E/QyCB 4QyV5dgG3kLuWNmS1LkkgAntVU8Nl1xDiPiagrFQ= 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 A9DB4382CE58; Tue, 10 Oct 2023 10:10:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9DB4382CE58 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 39A9klc7023614; Tue, 10 Oct 2023 10:10:03 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhk6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:10:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AA9XF4009671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:09: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 39A9qhTW014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:09: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 v15 26/39] c++: Implement __remove_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:40 -0700 Message-ID: <20231010095229.3364786-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: mLiwKuhz7w-qZbN4Sg45ru0LDem-5yUo X-Proofpoint-ORIG-GUID: mLiwKuhz7w-qZbN4Sg45ru0LDem-5yUo 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_05,2023-10-09_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=585 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-12.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 4fa14de3e90..de3779b6d82 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -78,6 +78,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false "__remove_cv", CPTK_REMOVE_CV, false, false, true "__remove_cvref", CPTK_REMOVE_CVREF, false, false, true +"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true "__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true "__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c53e234f631..503e6804145 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -118,7 +118,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, @@ -127,7 +127,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, @@ -139,17 +139,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, #line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, @@ -237,21 +239,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, false, false, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dBmq/BnY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WwK1WYwz23jb for ; Tue, 10 Oct 2023 21:14:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E565F388CC3F for ; Tue, 10 Oct 2023 10:14:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E565F388CC3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932862; 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=dBmq/BnYE85jzeSrWUi1fIoYCSMHbxa8cr80gE+m1mRrjCKJPHkaeDcnk9WOgFize KaszQcxmRxmZu6XS8x24KOETu3oPS4BBYZVM76Zh4qIZgnPpDeK97vxxyl7s4debg6 QCFtK2ivuPEFVw/P3uLSA4lo6vlXw+u3OJidEcGw= 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 84AE038323CC; Tue, 10 Oct 2023 10:10:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84AE038323CC 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 39A9TxJl002824; Tue, 10 Oct 2023 10:10:34 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqb54ass-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:10:34 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAAMgf004925 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:10:23 -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 39A9qhTX014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:10: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 v15 27/39] libstdc++: Optimize remove_pointer trait performance Date: Tue, 10 Oct 2023 02:46:41 -0700 Message-ID: <20231010095229.3364786-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FAym5xqSidCoBnXIr-izvPJ9uL5WQF2_ X-Proofpoint-GUID: FAym5xqSidCoBnXIr-izvPJ9uL5WQF2_ 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=666 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dMYjz55E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WsZ3pKrz20Xn for ; Tue, 10 Oct 2023 21:12:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DCA439540B5 for ; Tue, 10 Oct 2023 10:12:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DCA439540B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932720; bh=meNIIhQ/8gEUIxosGnyfUkmTdskakvniFbxD5ibVwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dMYjz55E65VZQBBoPf4FwqQAPazECJLk2R+7o+P0i4/iwf3oLQdnaGiuDxlqoV4Rr DCrdTSAZpjUFQD7xe4XEBfnQKFC0rlsvFOJ6tdZGdryh9wToUBgEuXdnhzqOKpi6DL 7M47+oWlqdrdaodnKGorK/GXMzBWRTfHzAskY0XY= 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 1873A388A417; Tue, 10 Oct 2023 10:11:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1873A388A417 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 39AA3njb006633; Tue, 10 Oct 2023 10:11:12 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmkta6wg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:11:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAAjOl032397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:10:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTY014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:10:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v15 28/39] c++, libstdc++: Implement __is_pointer built-in trait Date: Tue, 10 Oct 2023 02:46:42 -0700 Message-ID: <20231010095229.3364786-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: vLjzfQjlA6jChniC9WaCfXipGDtshBD9 X-Proofpoint-GUID: vLjzfQjlA6jChniC9WaCfXipGDtshBD9 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 impostorscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 clxscore=1034 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 de3779b6d82..07a333ea826 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -62,6 +62,7 @@ struct cp_trait { "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false "__is_pod", CPTK_IS_POD, false, false, false +"__is_pointer", CPTK_IS_POINTER, false, false, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false "__is_reference", CPTK_IS_REFERENCE, false, false, false "__is_same", CPTK_IS_SAME, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 503e6804145..011e454760c 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,78 +118,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 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, false, false, false}, + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, false, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 86 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 74 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, @@ -207,23 +207,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_array", CPTK_IS_ARRAY, false, false, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, @@ -238,22 +242,19 @@ cp_trait_lookup::find (const char *str, size_t len) #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, false, false, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} + {"__is_function", CPTK_IS_FUNCTION, false, false, 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 09:46:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=c5WUPe9s; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WyX6NPRz1yq7 for ; Tue, 10 Oct 2023 21:16:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6D9E387103D for ; Tue, 10 Oct 2023 10:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6D9E387103D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932978; 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=c5WUPe9svNoL+031YvwcKtoApmpilhWrh3bOPCUMQPJ1784xCrUcDntOWvdKDvJJG +DmpTvqiUVp4RpxFF1EjP9sidmwQ+AJe1+rWgXcvufj3MEz2gxp4dzn1bbWYl8DTki Hh/CmPWLXthG4aCDopzOPqXPhO5DZIh8JppEw4uE= 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 848603952486; Tue, 10 Oct 2023 10:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 848603952486 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 39AA9Kh9025824; Tue, 10 Oct 2023 10:11:35 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmu6qj3v2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:11:35 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AABVLZ009991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:11:31 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39A9qhTZ014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:11:31 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v15 29/39] libstdc++: Optimize is_pointer trait performance Date: Tue, 10 Oct 2023 02:46:43 -0700 Message-ID: <20231010095229.3364786-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: J5xLBcDb7VcxW6ByorzziKFtfZ5DI05i X-Proofpoint-GUID: J5xLBcDb7VcxW6ByorzziKFtfZ5DI05i 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_05,2023-10-09_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=487 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-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=u8VF9mzM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X1m5Yjzz1yq7 for ; Tue, 10 Oct 2023 21:19:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABE003896C27 for ; Tue, 10 Oct 2023 10:19:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABE003896C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933146; bh=x5xDCjkY/vnDf/nG9G7rrIp4yY+837dBRmj2MK7HZfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=u8VF9mzMJrgiowRp+zfVaZPBQeuS5xdHyeYTTIWYLhq7qZRQpViya2hv1Jz41ck/f HDnJro9g8lX21tK6agxTKpTr8nULbq28LnBkSch7N47Q+1ZalSCn9uacQhWsFkYf0S BtSu3/24CiAegwgLQJ7qdAkBPHLk1sfq+zP24450= 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 3FA9B3831E03; Tue, 10 Oct 2023 10:12:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FA9B3831E03 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 39AA5j7x031514; Tue, 10 Oct 2023 10:12:07 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmqb54aw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:12:07 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAC6A3005513 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:12:06 -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 39A9qhTa014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:12:06 -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 v15 30/39] c++, libstdc++: Implement __is_arithmetic built-in trait Date: Tue, 10 Oct 2023 02:46:44 -0700 Message-ID: <20231010095229.3364786-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8xDeP4I70IieMcemGrR4CgNwwJv36-Qw X-Proofpoint-GUID: 8xDeP4I70IieMcemGrR4CgNwwJv36-Qw 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 07a333ea826..5493f38bcbb 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -40,6 +40,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false "__is_abstract", CPTK_IS_ABSTRACT, false, false, false "__is_aggregate", CPTK_IS_AGGREGATE, false, false, false +"__is_arithmetic", CPTK_IS_ARITHMETIC, false, false, false "__is_array", CPTK_IS_ARRAY, false, false, false "__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false "__is_base_of", CPTK_IS_BASE_OF, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 011e454760c..b6dcb19cefb 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 97, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,130 +118,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 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 82 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, false, false, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_arithmetic", CPTK_IS_ARITHMETIC, false, false, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, false, false, false} }; @@ -249,12 +251,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 09:46:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BESUVJ45; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WwJ1NMXz20Xn for ; Tue, 10 Oct 2023 21:14:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ECD27395A05E for ; Tue, 10 Oct 2023 10:14:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECD27395A05E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932862; 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=BESUVJ45KsWbsMrNfdwNIRj7P/pfDlXy8Dw4PWaTFhfh6FIUEg1ss6G7Qbua9w7Nf lWiiwQTH4vC+1rdh8kEUcNNfSvz59gAAaG5AGC+LKUEqHygd3scl1owzW5RVyA3bF2 8EOs1mdKcT2dhrmJD4WQmeps6f/bH5Ln2U4wt4z4= 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 2A4803826B7B; Tue, 10 Oct 2023 10:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A4803826B7B 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 39AA7xom024939; Tue, 10 Oct 2023 10:12:39 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmtf3jfn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:12:39 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AACUP1005520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:12: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 39A9qhTb014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:12: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 v15 31/39] libstdc++: Optimize is_arithmetic trait performance Date: Tue, 10 Oct 2023 02:46:45 -0700 Message-ID: <20231010095229.3364786-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: SWrey1X8XmqoTthXYIm6PraYuZWqjL9C X-Proofpoint-ORIG-GUID: SWrey1X8XmqoTthXYIm6PraYuZWqjL9C 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_05,2023-10-09_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=667 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-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=GxCpuCK3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wxp4kwTz1yq7 for ; Tue, 10 Oct 2023 21:15:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACB113959E42 for ; Tue, 10 Oct 2023 10:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACB113959E42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696932939; 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=GxCpuCK3kd1F41yLjyep8h6/MgcUapipA9YGTV025NSgDuzNO4ktJWaMv+55ufy/l 2gfiaSklct6W9EtTJIX6GDRMp7/JnFhpJSx0iYfMHKjxBf8G5OQiu6tO1Ul7Jhyb4K gA8mbgDNbQmPV/fBvvs7MKSaBwayL/RmdWEwqqCE= 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 017A63955628; Tue, 10 Oct 2023 10:13:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 017A63955628 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 39AAAEDN016750; Tue, 10 Oct 2023 10:13:08 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmnkwnkrc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:13:07 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AACqQw025432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:12:52 -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 39A9qhTc014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:12:52 -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 v15 32/39] libstdc++: Optimize is_fundamental trait performance Date: Tue, 10 Oct 2023 02:46:46 -0700 Message-ID: <20231010095229.3364786-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OoFgGzZ7NRRl0Gcf7LZAeAKJwt_ont9d X-Proofpoint-GUID: OoFgGzZ7NRRl0Gcf7LZAeAKJwt_ont9d 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_05,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 clxscore=1034 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 spamscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=533 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=M/bfpxCf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X3L5bF7z1ypX for ; Tue, 10 Oct 2023 21:20:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE6723AA88B5 for ; Tue, 10 Oct 2023 10:20:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE6723AA88B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933228; 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=M/bfpxCfOGZY0uv0friv3Sg2mfXzPg6kLD2cFfg/PT5l58sFSRQiEV6lTuLWmLyZk MRXF3hTOPP26OJyp7yv/DrB9FKYbJYpsHfKThRBf4a2IGZzDikc1D31s/9eDQzolAn ODEXqtfH8jo6JprgU1ch/5dx6QKDPhkJ0ujASZI4= 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 B64093959E54; Tue, 10 Oct 2023 10:13:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B64093959E54 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 39A9oeQm025124; Tue, 10 Oct 2023 10:13:49 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843p0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:13:49 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AADeUA031315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:13: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 39A9qhTd014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:13: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 v15 33/39] libstdc++: Optimize is_compound trait performance Date: Tue, 10 Oct 2023 02:46:47 -0700 Message-ID: <20231010095229.3364786-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: k_LoURAaRVqGWgBSssEULVKf6IGnW-Nw X-Proofpoint-GUID: k_LoURAaRVqGWgBSssEULVKf6IGnW-Nw 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=597 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ExAQA8Yv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X023JGxz20Xn for ; Tue, 10 Oct 2023 21:17:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A952F3870918 for ; Tue, 10 Oct 2023 10:17:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A952F3870918 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933055; bh=Kz5aSvudzMvK549Abn1CfnJi/cRRGj5YGSIHNVsN550=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ExAQA8Yvtr3VO+Rn0Rh56i4jE4CAlCDnOHiZgo9hHm42DLbL5eIEW8ckBB8kA3HQY YRL9hvLH3VqXY6tJLrVOKNf1UY0IyBg3GJ/Z/SquX6LLgahzS5cDL8Xv+WfKPg0LJq UWd4HpZiXzFGGgRm0Bn5v3gCYqYGTGX5mfMtwPa0= 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 DF696390120C; Tue, 10 Oct 2023 10:14:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF696390120C 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 39AABdD4000914; Tue, 10 Oct 2023 10:14:12 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvg39jut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:14:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAE87G024031 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:14: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 39A9qhTe014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:14: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 v15 34/39] c++: Implement __is_unsigned built-in trait Date: Tue, 10 Oct 2023 02:46:48 -0700 Message-ID: <20231010095229.3364786-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: IyPtwUxO-BYGs8u0SrwZIkverZ9OjFE8 X-Proofpoint-ORIG-GUID: IyPtwUxO-BYGs8u0SrwZIkverZ9OjFE8 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_05,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=736 mlxscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 5493f38bcbb..c39b9d9007a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -75,6 +75,7 @@ struct cp_trait { "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false "__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false "__is_union", CPTK_IS_UNION, false, false, false +"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false "__is_volatile", CPTK_IS_VOLATILE, false, false, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b6dcb19cefb..635c9a3a0e5 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 97, duplicates = 0 */ +/* maximum key range = 129, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,46 +118,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 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 83 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, #line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, false, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, false, false, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, false, false, false}, #line 87 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, #line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, @@ -167,11 +165,11 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, #line 67 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, @@ -182,7 +180,7 @@ cp_trait_lookup::find (const char *str, size_t len) #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, #line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, + {"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" @@ -209,6 +207,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, false, false, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" @@ -225,8 +225,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, #line 68 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, #line 71 "../../gcc/cp/cp-trait.gperf" @@ -244,19 +244,23 @@ cp_trait_lookup::find (const char *str, size_t len) #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, false, false, false}, #line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, false, false, false} + {"__is_function", CPTK_IS_FUNCTION, false, false, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=bbGgRSao; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4WzP3rNCz1yq7 for ; Tue, 10 Oct 2023 21:17:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 493CE3882640 for ; Tue, 10 Oct 2023 10:17:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 493CE3882640 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933023; 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=bbGgRSaoIB9tCdVRLdmGOuDhoLASvURN5BYqJ52KDmhXsTQn3mxg/QaynQ46rzp+N 1PY4BhTZ3ZjVFUF6yls+nJp4hgUcCxOmDATuZmWKs+RxUjZjQz+xKAr/NYzQbfVZKA GcLmtQ3rbTrOCiEEtwL2WD1qIsQuhcTBvs/FUIj4= 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 B25213873643; Tue, 10 Oct 2023 10:14:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B25213873643 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 39AAChNj030167; Tue, 10 Oct 2023 10:14:41 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843p39-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:14:40 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAEaGF025720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:14:36 -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 39A9qhTf014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:14:36 -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 v15 35/39] libstdc++: Optimize is_unsigned trait performance Date: Tue, 10 Oct 2023 02:46:49 -0700 Message-ID: <20231010095229.3364786-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SWnkChO2GDlJjldBdzZUzR9pvxsxVuGy X-Proofpoint-GUID: SWnkChO2GDlJjldBdzZUzR9pvxsxVuGy 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=627 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gXrPbwU6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X1D27cyz1yq7 for ; Tue, 10 Oct 2023 21:18:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92D9738F7C2F for ; Tue, 10 Oct 2023 10:18:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92D9738F7C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933116; bh=UY3EzJEDtYYDUbG+l6wnaZUWZOQEG9IsJ755JsbdoTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gXrPbwU6ue3X5X09sZSBtk8xI+wKhDb/dqkWF6qYjYcjzs3v8gxGLf16897ZJ2X1N C6HMfDBzAplFUNJjl9vvMqJfI0bBGvdVVtU8yTLbw0lt/v7cWbQPryQEZZ0mSFIEuO WKefQgoMUj2rrs33xwdhU5mngUePYo+cJwR7Dbzg= 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 20B503830B56; Tue, 10 Oct 2023 10:15:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20B503830B56 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 39AA9DnR001861; Tue, 10 Oct 2023 10:15:19 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmvfxhkny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:15:19 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAExvf005866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:14:59 -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 39A9qhTg014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:14:59 -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 v15 36/39] c++, libstdc++: Implement __is_signed built-in trait Date: Tue, 10 Oct 2023 02:46:50 -0700 Message-ID: <20231010095229.3364786-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 7s1-z8eqvkHBxVHbJuvX7ecEN1mZlexd X-Proofpoint-ORIG-GUID: 7s1-z8eqvkHBxVHbJuvX7ecEN1mZlexd 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_05,2023-10-09_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=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 c39b9d9007a..67a1e37d754 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -67,6 +67,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false "__is_reference", CPTK_IS_REFERENCE, false, false, false "__is_same", CPTK_IS_SAME, true, false, false +"__is_signed", CPTK_IS_SIGNED, false, false, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false "__is_trivial", CPTK_IS_TRIVIAL, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 635c9a3a0e5..dd94ac56fec 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -56,7 +56,7 @@ struct cp_trait { bool variadic; bool type; }; -/* maximum key range = 129, duplicates = 0 */ +/* maximum key range = 119, duplicates = 0 */ class cp_trait_lookup { @@ -71,32 +71,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; @@ -118,149 +118,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 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 84 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, false, false, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, true, false, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, false, false, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, true, false, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, #line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_signed", CPTK_IS_SIGNED, false, false, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, true, false, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, -#line 37 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, -#line 36 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, false, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, false, false, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, false, false, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, false, false, false}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, false, false, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, 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 09:46:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1845812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=O1WGYEMo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4Wzc1TMHz1yq7 for ; Tue, 10 Oct 2023 21:17:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3853C391FAA5 for ; Tue, 10 Oct 2023 10:17:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3853C391FAA5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933034; 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=O1WGYEMo+UjVZ1DCdqSNVsg5LcEdYmePcVUiJHWwJ3DeXaYG+Y3+uDXXvrND3Bmm6 McDWcwCgtetUubdkNdW7vyZD3hlnOV+PRqTVXhl4YgAFJPwXdIruLrjyrt7btmX8PQ s9iHvzEfMh6h9o0C9znpqfMhe1VVd1zcU2iFMntA= 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 53091386D604; Tue, 10 Oct 2023 10:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53091386D604 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 39AA17bV032517; Tue, 10 Oct 2023 10:15:42 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmt3ktnhp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:15:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAFZf8025883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:15:36 -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 39A9qhTh014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:15:35 -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 v15 37/39] libstdc++: Optimize is_signed trait performance Date: Tue, 10 Oct 2023 02:46:51 -0700 Message-ID: <20231010095229.3364786-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SyF82G6YAZw63LuV5z1hDr9qU6e0Lh-y X-Proofpoint-GUID: SyF82G6YAZw63LuV5z1hDr9qU6e0Lh-y 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1034 phishscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=608 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 09:46: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: 1845814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=AA7JoxHJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X0219gCz1yq7 for ; Tue, 10 Oct 2023 21:17:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F20F73882AF4 for ; Tue, 10 Oct 2023 10:17:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F20F73882AF4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933056; bh=owWkajkFNd3Q3ESEN24lMMg61WIYkhgtoMvw076cfUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AA7JoxHJB7pf7DrQXmpGkOI0ODQPNrNJISoK0jAMQLjoIxkJac2RkTECsHHAWYw5l uKbgBeHATOhI+HertElOdAF7zrN8k6NRD3RClPLWTdPy2MeU/AyV767mcjaJH5QE6F RTph66V7OFI6Gg4YF8HyED150AcogTJ6sY0wJ9vA= 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 25DA73848370; Tue, 10 Oct 2023 10:15:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25DA73848370 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 39A9w4UX005768; Tue, 10 Oct 2023 10:15:56 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843p8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:15:56 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAFtCg000732 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:15:55 -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 39A9qhTi014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:15:55 -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 v15 38/39] c++, libstdc++: Implement __is_scalar built-in trait Date: Tue, 10 Oct 2023 02:46:52 -0700 Message-ID: <20231010095229.3364786-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: bR3ZPEovDHTk8IwAPCQg_q-LWW-I78IU X-Proofpoint-GUID: bR3ZPEovDHTk8IwAPCQg_q-LWW-I78IU 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 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_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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 67a1e37d754..654da0568ec 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -67,6 +67,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false "__is_reference", CPTK_IS_REFERENCE, false, false, false "__is_same", CPTK_IS_SAME, true, false, false +"__is_scalar", CPTK_IS_SCALAR, false, false, false "__is_signed", CPTK_IS_SIGNED, false, false, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index dd94ac56fec..3c13835a8df 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,10 +80,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, @@ -118,7 +118,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, @@ -127,141 +127,143 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, false, false, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, false, false, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, false, false, false}, #line 84 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, + {"__remove_cv", CPTK_REMOVE_CV, false, false, true}, #line 85 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, false, false, true}, +#line 90 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false}, +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, false, false, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, false, false, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, false, false, true}, -#line 91 "../../gcc/cp/cp-trait.gperf" +#line 92 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, false, false, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, false, false, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer", CPTK_IS_POINTER, false, false, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false}, #line 69 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, true, false, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, false, false, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, false, false, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, false, false, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, true, false, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, false, false, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, true, false, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_signed", CPTK_IS_SIGNED, false, false, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, false, true, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, false, false, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, true, false, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, false, false, false}, -#line 32 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, -#line 33 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, false, false, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, +#line 82 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, true, false, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, false, false, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, false, false, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, false, false, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, false, false, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, +#line 89 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, false, false, true}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, false, false, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_scalar", CPTK_IS_SCALAR, false, false, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, false, false, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, false, false, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, true, false, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, true, false, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, true, false, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, false, false, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, false, false, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, false, false, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, false, false, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, false, false, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, false, false, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, false, false, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, false, false, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, false, false, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, false, false, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, false, false, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, false, false, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, false, false, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, false, false, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, false, false, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, false, false, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, false, false, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, false, false, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, false, false, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, true, false, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, true, false, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, false, true, true}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, false, true, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, false, false, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, false, false, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, false, false, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, true, false, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, false, false, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, false, false, false}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, true, false, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, false, true, false}, -#line 89 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, true, false, false} +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, false, false, 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 09:46: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: 1845816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=pPumhDbl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4X1L41HFz1yq7 for ; Tue, 10 Oct 2023 21:18:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95A9D382E6BD for ; Tue, 10 Oct 2023 10:18:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95A9D382E6BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696933123; 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=pPumhDblnurvc1YQmZmWZxmLqXK9+xiOzjF6zLRJURvukgRWYN1EQHnUHxZBfu0RV KKC4FN3BsGAauUKu7ru8TOujuhgkCvbtKVdFemHZ6WicXBeS4frZnICqXWz+HUOVVS dMKp57uiwkY/hIiWF7Es6JgjD4Aqsiri+aphasFw= 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 3F6E6391FA9D; Tue, 10 Oct 2023 10:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F6E6391FA9D 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 39AAAjGp027391; Tue, 10 Oct 2023 10:16:28 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tmr843pbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 10:16:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39AAGDi3000903 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 03:16:13 -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 39A9qhTj014491 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 03:16:13 -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 v15 39/39] libstdc++: Optimize is_scalar trait performance Date: Tue, 10 Oct 2023 02:46:53 -0700 Message-ID: <20231010095229.3364786-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010095229.3364786-1-kmatsui@gcc.gnu.org> References: <20230915023640.75216-1-kmatsui@gcc.gnu.org> <20231010095229.3364786-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 3zw175P1wBYKqFAfwNQ1nId7p2tZAKdO X-Proofpoint-GUID: 3zw175P1wBYKqFAfwNQ1nId7p2tZAKdO 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_05,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxscore=0 clxscore=1034 adultscore=0 bulkscore=0 mlxlogscore=672 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100076 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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>;