From patchwork Fri Oct 13 22:37: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: 1848680 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=Qwhzju5J; 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 4S6hLb0bpBz1yqj for ; Sat, 14 Oct 2023 09:41:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 342D23857736 for ; Fri, 13 Oct 2023 22:41:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 342D23857736 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236868; bh=MKW1Ac2+4canAboK7rFTyrtkRq5Md4dhsl2QPGign68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Qwhzju5JMsRHoZ0liIFrxGqtmtxG7Y9LzzhGvj1OeYCBAwMUjyPRE9xepzGObqNT0 ina/ZJHFiMHhCtKhQlYd9PO251snAs15o8rTGhIfjp7rKyy5KPHRsTjRuZBKequthN je+ieNGuSB83vlVSQf8AAeMVxeIjS+aLnVZAzNsw= 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 125C23857715; Fri, 13 Oct 2023 22:40:46 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 125C23857715 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236848; cv=none; b=tcwWnIO3K4e25JAk3DRUvTRmh5ssEE88cQShLJHuUBafGm/V4twIA96o+fp4JjhaRxtQDQfseQtZ/Epogsk7PG0DRL22WljZCzEZgbywL7s6+E4Q9qsIxaKoV6F5feRL4NIrsvf2YiIYCKDvo6tJxsnBgmqzht9C0+N6aU6klpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236848; c=relaxed/simple; bh=ueEU7MagjimKlE470j5C66f9EXtFDtKqz5Vv0AXZdoI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nARZS1QI0bLw+JWkbL1ZBqOnBMt8CTLeWfkigHhnEd5BRDbnPEpC/o19QnwogE9oMN/PF7wxap6BkLmjvKWxKtdj4yLtZRL2bviPwgCTBQiTMNiFfhXEli4J88yGZdY4AycDec/5zEDnYezpvaxupkbFKV2FwgJHpBGofW9j65w= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 125C23857715 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 39DMSiAo005025; Fri, 13 Oct 2023 22:40:45 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209m94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:40:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMeSUT002795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:40:28 -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 39DMdx1E016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:40:27 -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 v19 01/40] c++: Sort built-in traits alphabetically Date: Fri, 13 Oct 2023 15:37:15 -0700 Message-ID: <20231013223957.1634024-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Etx33ZiTjClhlsjjrsOZyQG4Da4vO_f2 X-Proofpoint-GUID: Etx33ZiTjClhlsjjrsOZyQG4Da4vO_f2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 sorts built-in traits alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in traits alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 68 ++++++++--------- gcc/cp/cp-trait.def | 10 +-- gcc/cp/semantics.cc | 94 ++++++++++++------------ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 70 +++++++++--------- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 Fri Oct 13 22:37: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: 1848681 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=mvrikSSp; 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 4S6hM40d7cz1yqj for ; Sat, 14 Oct 2023 09:41:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D10D8385696E for ; Fri, 13 Oct 2023 22:41:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D10D8385696E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236892; bh=/Jev4dHfWGTZBaPM5+Vcm8mAYdnbFOU63YsXlC6lIHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mvrikSSparUHb8wid5cOfYiFst5wENI1t301sq/XtKPpOKdS/lXYE1OeCu/fJwpzt pDsf+pbYJ/XEN7lz3hQL1pL8Si04WqJjsnlt56j+eocLjolxLdezq+rSjXVwsozgAt vpqpq1ls8vI54OxTMrlOeq6OgCOdUuKceAHPLVsA= 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 416E1385701E; Fri, 13 Oct 2023 22:41:07 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 416E1385701E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236871; cv=none; b=h1XxWffoQJaPsH97uq0M/qsMO++bxIbTNeJ+qmIubKg6wOoSksJ7TRQ2483l6CcWzl8jH83N1c7ZqcjZ9E6ljw2MIOL7fWOd5fBBzNeMc1+kLbeOrg4vSZqVGy7sZZen6hpN0pjSPmyh61UWhrC8AOP7Cymxq9gZQEmClOe8CRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236871; c=relaxed/simple; bh=8rMhG14aIhD9DTAEYVTpE3L+8lb4pjYaRAWF4qQPl14=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FFDseIWvyfA3RZ1yfB0pXPUBkqeLG6K2mad+WVDuQbkmCynNQQ4DA2XZ4qOdrnXtvlLF6+T08FR/VwyMG0uVUVTdeaC50xUB8uMlVtaHicHePYQidxKe8a9/4Z9CfknnqBrDWLmm8T++AOpZnAtn6Lpic+i3dLGPbwZclcK02xQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 416E1385701E 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 39DMQpLj003418; Fri, 13 Oct 2023 22:41:06 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05v37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:41:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMewDH000964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:40:58 -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 39DMdx1F016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:40:57 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Patrick Palka Subject: [PATCH v19 02/40] c-family, c++: Look up built-in traits through gperf Date: Fri, 13 Oct 2023 15:37:16 -0700 Message-ID: <20231013223957.1634024-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bhjiIWLXe9UWM7Wdi5X7VOasMpF2mWka X-Proofpoint-ORIG-GUID: bhjiIWLXe9UWM7Wdi5X7VOasMpF2mWka X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses gperf to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * Make-lang.in: Add targets to generate cp-trait.gperf and cp-trait.h. * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait identifier. * cp-tree.h (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (init_cp_traits): New function to set cik_trait for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_lexer_lookup_trait): New function to look up a built-in trait from a token by gperf. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. * cp-trait-head.in: New file. * cp-trait.gperf: New file. * cp-trait.h: New file. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 -- gcc/c-family/c-common.h | 5 - gcc/cp/Make-lang.in | 26 ++++ gcc/cp/cp-objcp-common.cc | 8 +- gcc/cp/cp-trait-head.in | 30 +++++ gcc/cp/cp-trait.gperf | 74 ++++++++++++ gcc/cp/cp-trait.h | 247 ++++++++++++++++++++++++++++++++++++++ gcc/cp/cp-tree.h | 14 ++- gcc/cp/lex.cc | 19 +++ gcc/cp/parser.cc | 132 ++++++++++++-------- 10 files changed, 492 insertions(+), 70 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..21fd333ef57 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,13 +508,6 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, - /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..051a442e0f4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 2727fb7f8cc..a67d1c3e9f3 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 -k '8' -D -N 'find' -L C++ \ + $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h + +# The cp-trait.gperf file itself is generated from +# cp-trait-head.in and cp-trait.def files. +$(srcdir)/cp/cp-trait.gperf: $(srcdir)/cp/cp-trait-head.in $(srcdir)/cp/cp-trait.def + cat $< > $@ + $(AWK) -F', *' '/^DEFTRAIT_/ { \ + type = (index($$1, "DEFTRAIT_TYPE") != 0 ? "true" : "false"); \ + gsub(/DEFTRAIT_(EXPR|TYPE) \(/, "", $$1); \ + gsub(/\)/, "", $$3); \ + print $$2", CPTK_" $$1", "$$3", "type; \ + }' $(srcdir)/cp/cp-trait.def >> $@ + +# This is the file that depends on the generated header file. +cp/parser.o: $(srcdir)/cp/cp-trait.h + components_in_prev = "bfd opcodes binutils fixincludes gas gcc gmp mpfr mpc isl gold intl ld libbacktrace libcpp libcody libdecnumber libiberty libiberty-linker-plugin libiconv zlib lto-plugin libctf libsframe" components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc libbacktrace libphobos zlib libgomp libatomic" diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..b1adacfec07 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -421,6 +421,10 @@ names_builtin_p (const char *name) } } + /* Check for built-in traits. */ + if (IDENTIFIER_TRAIT_P (id)) + return true; + /* Also detect common reserved C++ words that aren't strictly built-in functions. */ switch (C_RID_CODE (id)) @@ -434,10 +438,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-trait-head.in b/gcc/cp/cp-trait-head.in new file mode 100644 index 00000000000..9357eea1238 --- /dev/null +++ b/gcc/cp/cp-trait-head.in @@ -0,0 +1,30 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf new file mode 100644 index 00000000000..47e3c1af499 --- /dev/null +++ b/gcc/cp/cp-trait.gperf @@ -0,0 +1,74 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false +"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false +"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false +"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false +"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false +"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false +"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false +"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false +"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false +"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false +"__is_abstract", CPTK_IS_ABSTRACT, 1, false +"__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false +"__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_class", CPTK_IS_CLASS, 1, false +"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false +"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false +"__is_empty", CPTK_IS_EMPTY, 1, false +"__is_enum", CPTK_IS_ENUM, 1, false +"__is_final", CPTK_IS_FINAL, 1, false +"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false +"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false +"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false +"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false +"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false +"__is_pod", CPTK_IS_POD, 1, false +"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_same", CPTK_IS_SAME, 2, false +"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false +"__is_trivial", CPTK_IS_TRIVIAL, 1, false +"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false +"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false +"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_union", CPTK_IS_UNION, 1, false +"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false +"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false +"__remove_cv", CPTK_REMOVE_CV, 1, true +"__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true +"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true +"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true +"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false +"__bases", CPTK_BASES, 1, true +"__direct_bases", CPTK_DIRECT_BASES, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h new file mode 100644 index 00000000000..97ba8492d15 --- /dev/null +++ b/gcc/cp/cp-trait.h @@ -0,0 +1,247 @@ +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 4 "../../gcc/cp/cp-trait.gperf" + +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +#line 23 "../../gcc/cp/cp-trait.gperf" +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +/* maximum key range = 79, duplicates = 0 */ + +class cp_trait_lookup +{ +private: + static inline unsigned int hash (const char *str, size_t len); +public: + static const struct cp_trait *find (const char *str, size_t len); +}; + +inline unsigned int +cp_trait_lookup::hash (const char *str, size_t len) +{ + static const unsigned char asso_values[] = + { + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, + 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, + 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, + 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86 + }; + unsigned int hval = len; + + switch (hval) + { + default: + hval += asso_values[static_cast(str[7])]; + /*FALLTHROUGH*/ + case 7: + break; + } + return hval; +} + +const struct cp_trait * +cp_trait_lookup::find (const char *str, size_t len) +{ + enum + { + TOTAL_KEYWORDS = 45, + MIN_WORD_LENGTH = 7, + MAX_WORD_LENGTH = 37, + MIN_HASH_VALUE = 7, + MAX_HASH_VALUE = 85 + }; + + static const struct cp_trait wordlist[] = + { +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__bases", CPTK_BASES, 1, true}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + }; + + static const signed char lookup[] = + { + -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, + 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, + 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, + -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, + 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44 + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + unsigned int key = hash (str, len); + + if (key <= MAX_HASH_VALUE) + { + int index = lookup[key]; + + if (index >= 0) + { + const char *s = wordlist[index].name; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[index]; + } + } + } + return 0; +} diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6e34952da99..62e134886fb 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1226,7 +1226,7 @@ enum cp_identifier_kind { cik_simple_op = 4, /* Non-assignment operator name. */ cik_assign_op = 5, /* An assignment operator name. */ cik_conv_op = 6, /* Conversion operator name. */ - cik_reserved_for_udlit = 7, /* Not yet in use */ + cik_trait = 7, /* Built-in trait name. */ cik_max }; @@ -1271,9 +1271,9 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is for any operator name (including - conversions). Value 4, 5, 6 or 7. */ + conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE)) + (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ @@ -1286,12 +1286,18 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion - operator. Value 7. */ + operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ & (!IDENTIFIER_KIND_BIT_0 (NODE))) +/* True if this identifier is the name of a built-in trait. */ +#define IDENTIFIER_TRAIT_P(NODE) \ + (IDENTIFIER_KIND_BIT_0 (NODE) \ + && IDENTIFIER_KIND_BIT_1 (NODE) \ + && IDENTIFIER_KIND_BIT_2 (NODE)) + /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ (IDENTIFIER_OVL_OP_P (NODE) \ diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..f6e1f6a4075 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" static int interface_strcmp (const char *); +static void init_cp_traits (void); static void init_cp_pragma (void); static tree parse_strconst_pragma (const char *, int); @@ -283,6 +284,23 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + id = get_identifier (NAME); \ + set_identifier_kind (id, cik_trait); +#include "cp/cp-trait.def" +#undef DEFTRAIT + + /* An alias for __is_same. */ + id = get_identifier ("__is_same_as"); + set_identifier_kind (id, cik_trait); +} + static void init_cp_pragma (void) { @@ -324,6 +342,7 @@ cxx_init (void) input_location = BUILTINS_LOCATION; init_reswords (); + init_cp_traits (); init_tree (); init_cp_semantics (); init_operators (); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f3abae716fe..39952893ffa 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. */ @@ -246,6 +247,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1167,12 +1174,6 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_CONSTEVAL: return true; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - return true; - default: if (keyword >= RID_FIRST_INT_N && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS @@ -1182,6 +1183,51 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } +/* Look ups the corresponding built-in trait if a given token is + a built-in trait. Otherwise, returns nullptr. */ + +static const cp_trait * +cp_lexer_lookup_trait (const cp_token *token) +{ + tree id = token->u.value; + + if (token->type == CPP_NAME + && TREE_CODE (id) == IDENTIFIER_NODE + && IDENTIFIER_TRAIT_P (id)) + { + const char *id_str = IDENTIFIER_POINTER (id); + const int id_len = IDENTIFIER_LENGTH (id); + return cp_trait_lookup::find (id_str, id_len); + } + return nullptr; +} + +/* Similarly, but only if the token is an expression-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_expr (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && !trait->type) + return trait; + + return nullptr; +} + +/* Similarly, but only if the token is a type-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_type (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && trait->type) + return trait; + + return nullptr; +} + /* Return true if the next token is a keyword for a decl-specifier. */ static bool @@ -1190,6 +1236,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); + if (cp_lexer_lookup_trait_type (token)) + return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -2854,7 +2902,7 @@ static void cp_parser_late_parsing_default_args static tree cp_parser_sizeof_operand (cp_parser *, enum rid); static cp_expr cp_parser_trait - (cp_parser *, enum rid); + (cp_parser *, const cp_trait *); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6021,12 +6069,6 @@ cp_parser_primary_expression (cp_parser *parser, case RID_OFFSETOF: return cp_parser_builtin_offsetof (parser); -#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_EXPR - return cp_parser_trait (parser, token->keyword); - // C++ concepts case RID_REQUIRES: return cp_parser_requires_expression (parser); @@ -6065,6 +6107,12 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: + { + const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + if (trait) + return cp_parser_trait (parser, trait); + } + /* FALLTHRU */ case CPP_SCOPE: case CPP_TEMPLATE_ID: case CPP_NESTED_NAME_SPECIFIER: @@ -11033,28 +11081,11 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, const cp_trait* trait) { - cp_trait_kind kind; tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; - - switch (keyword) - { -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: \ - kind = CPTK_##CODE; \ - binary = (ARITY == 2); \ - variadic = (ARITY == -1); \ - type = (TCC == tcc_type); \ - break; -#include "cp-trait.def" -#undef DEFTRAIT - default: - gcc_unreachable (); - } + const bool binary = (trait->arity == 2); + const bool variadic = (trait->arity == -1); /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11094,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 +11110,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 +11125,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type1 == error_mark_node) return error_mark_node; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); tree trailing = cp_parser_enclosed_template_argument_list (parser); @@ -11144,7 +11175,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 +11189,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,20 +20112,21 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - type = cp_parser_trait (parser, token->keyword); + default: + break; + } + + /* If token is a type-yielding built-in traits, parse it. */ + const cp_trait* trait = cp_lexer_lookup_trait_type (token); + if (trait) + { + type = cp_parser_trait (parser, trait); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, /*type_definition_p=*/false); return type; - - default: - break; } /* If token is an already-parsed decltype not followed by ::, From patchwork Fri Oct 13 22:37: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: 1848682 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=vy6ZrdjI; 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 4S6hND0wTmz1yqj for ; Sat, 14 Oct 2023 09:42:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08B2B385773A for ; Fri, 13 Oct 2023 22:42:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08B2B385773A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236954; bh=QVChz69Gyt60mbU9bGpz82rR2gXDD0jcc7ySui8Wybg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vy6ZrdjIBFx88XjlpmubISrynytBeOjB615IQOSMoYPoyFKaNyV1/vns8r0hllyw4 s4vTlX+jcsVWh5BTLTs7Q69Kcyrhcv9YooisXLMNiiuUSYhmsTbDB+uZ6AY0MaQ2Hg P+5AEr9mkpVZZOX6V6MivraXWGtjzwzPHKp4ttdw= 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 16A813857033; Fri, 13 Oct 2023 22:41:39 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16A813857033 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236900; cv=none; b=eqDis7QAVjfvaEBON7+iKbe2x02M9XpoDmJFJ8cQZWVdfWvpJUd7iLOmAYVjQxsdsCQO41v3+YXMyYTiBYq0NYui2vKo2gfFQNQUbb5qrjx1nKb9EvhaWHCT5ixDwvAIY16mpMP80cwA3TvrX+HP6IZMpElhbLdR0A2hgxsy3rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236900; c=relaxed/simple; bh=2JyjEv3NKZpiwAUHDLDUZlXV/snu6Qd2uC3fAj1M/GQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uuQSAKtQXmLNqIQ0HS7q9Cq1Wq0yQZxT+LeWMN+6YxIULgb31I0qymm7Y8j60wi6IJj0Idpfbg96JpKR3QDGeWsNCvxWilfue5couT5aaDccZiVMkV5gEypBBpbqqTwlMK36ky8GudTcl0yYbVKJeRp3plRfSgvwJ7nPq+oo5DQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16A813857033 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 39DMX5Q4030783; Fri, 13 Oct 2023 22:41:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tjr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:41:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMfOs8001159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:41:24 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1G016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:41:24 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 03/40] c++: Accept the use of built-in trait identifiers Date: Fri, 13 Oct 2023 15:37:17 -0700 Message-ID: <20231013223957.1634024-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: W-RuDFrCOM4egB9w5acXla-3_02YK_Ds X-Proofpoint-ORIG-GUID: W-RuDFrCOM4egB9w5acXla-3_02YK_Ds X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=991 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 accepts the use of built-in trait identifiers when they are actually not used as traits. Specifically, we check if the subsequent token is '(' for ordinary built-in traits or is '<' only for the special __type_pack_element built-in trait. If those identifiers are used differently, the parser treats them as normal identifiers. This allows us to accept code like: struct __is_pointer {};. gcc/cp/ChangeLog: * parser.cc (cp_lexer_lookup_trait): Rename to ... (cp_lexer_peek_trait): ... this. Handle a subsequent token for the corresponding built-in trait. (cp_lexer_lookup_trait_expr): Rename to ... (cp_lexer_peek_trait_expr): ... this. (cp_lexer_lookup_trait_type): Rename to ... (cp_lexer_peek_trait_type): ... this. (cp_lexer_next_token_is_decl_specifier_keyword): Call cp_lexer_peek_trait_type. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. Signed-off-by: Ken Matsui --- gcc/cp/parser.cc | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 39952893ffa..59015eac596 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -247,12 +247,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *lexer, const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1183,21 +1183,33 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } -/* Look ups the corresponding built-in trait if a given token is +/* Peeks the corresponding built-in trait if a given token is a built-in trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) { - tree id = token->u.value; + tree id = token1->u.value; - if (token->type == CPP_NAME + if (token1->type == CPP_NAME && TREE_CODE (id) == IDENTIFIER_NODE && IDENTIFIER_TRAIT_P (id)) { const char *id_str = IDENTIFIER_POINTER (id); const int id_len = IDENTIFIER_LENGTH (id); - return cp_trait_lookup::find (id_str, id_len); + const cp_trait *trait = cp_trait_lookup::find (id_str, id_len); + + /* Check if the subsequent token is a `<' token to + __type_pack_element or is a `(' token to everything else. */ + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); + if (trait->kind == CPTK_TYPE_PACK_ELEMENT + && token2->type != CPP_LESS) + return nullptr; + if (trait->kind != CPTK_TYPE_PACK_ELEMENT + && token2->type != CPP_OPEN_PAREN) + return nullptr; + + return trait; } return nullptr; } @@ -1206,9 +1218,9 @@ cp_lexer_lookup_trait (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_expr (const cp_token *token) +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && !trait->type) return trait; @@ -1219,9 +1231,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_type (const cp_token *token) +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && trait->type) return trait; @@ -1236,7 +1248,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); - if (cp_lexer_lookup_trait_type (token)) + if (cp_lexer_peek_trait_type (lexer, token)) return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6108,7 +6120,7 @@ cp_parser_primary_expression (cp_parser *parser, keyword. */ case CPP_NAME: { - const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + const cp_trait* trait = cp_lexer_peek_trait_expr (parser->lexer, token); if (trait) return cp_parser_trait (parser, trait); } @@ -20117,7 +20129,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, } /* If token is a type-yielding built-in traits, parse it. */ - const cp_trait* trait = cp_lexer_lookup_trait_type (token); + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Fri Oct 13 22:37: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: 1848707 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=YqxUvE0B; 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 4S6hZ41qmHz1ypX for ; Sat, 14 Oct 2023 09:51:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DF0D3875421 for ; Fri, 13 Oct 2023 22:51:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DF0D3875421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237466; bh=A+QpW2RW+MhQraNL0kHmj2hvnz/HJE31o+NReBlrjYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YqxUvE0B8SRYKdr19xs8FrmpPJ7WjS7BFsCtN5v8qfki68EO8xYGVr7fVUCHY4exm N1J1sXF87y42KWXkztrWcnlQSMO3wTfrokis1+Y/u6VbUPM2JKUGs44pmQTQbdhfJj iFFBteTkvNU7k2lrVWDXmaL230zKPZZ9AOAQy9LQ= 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 033FC385B513; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 033FC385B513 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=KXwU3OLBQNqE83xP/h3H2btzYb2VfoBm3x7coTB3q6rzeM4uB2MbVdQSPNIvOOX4g3utC/E+CUvAM88dEQ8bwBuy7FxjXJpcRuByp3aI5C76/O5hM4MtkKmNH+MyxbCwAUt9OMpW3GlaKoy1oq7Ux3knBSj2KJrHASeyNmJlmGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=Y2kmhZlE5hdHH4cuuwyfH68h6RYqgjOE8+aB26KxFqA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CgYfMkUP6x0/NA84dzjYmuPAKx2RzRuFM9SJxPzPMTzUbsnItj4ibRYtAvS7J6/r0YjnEYvZv4nsewFHPMVcE7AicdQVBhN099qFSs+LJ4qi+K2VBBInWM5X+Dy/29a9sqnoqjJ04lCFnL8vPifAvAV4i3GkILDv9sLw2dBduT8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 033FC385B513 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 39DMNtCp011242; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbgdj193-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1BK001570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1H016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 04/40] c++: Implement __is_const built-in trait Date: Fri, 13 Oct 2023 15:37:18 -0700 Message-ID: <20231013223957.1634024-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: MpH5JcfTs8Q-aIzi05NTpg1RK9AKGOV8 X-Proofpoint-ORIG-GUID: MpH5JcfTs8Q-aIzi05NTpg1RK9AKGOV8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 malwarescore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_const. gcc/cp/ChangeLog: * Make-lang.in: Update key positions for gperf, based on automatically computed values. * cp-trait.def: Define __is_const. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/Make-lang.in | 2 +- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 202 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_const.C | 19 +++ 8 files changed, 135 insertions(+), 100 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index a67d1c3e9f3..7479e7dc00b 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -195,7 +195,7 @@ $(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf else $(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf endif - gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + gperf -o -C -E -k '6,8' -D -N 'find' -L C++ \ $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h # The cp-trait.gperf file itself is generated from diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 722fc334e6f..567dd35fe0a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47e3c1af499..47a5ec9ee6f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false +"__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false "__is_convertible", CPTK_IS_CONVERTIBLE, 2, false "__is_empty", CPTK_IS_EMPTY, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 97ba8492d15..c9005eee1ff 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -1,5 +1,5 @@ /* C++ code produced by gperf version 3.1 */ -/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ +/* Command-line: gperf -o -C -E -k 6,8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 79, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, - 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, - 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, - 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, + 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, + 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -104,6 +104,8 @@ cp_trait_lookup::hash (const char *str, size_t len) hval += asso_values[static_cast(str[7])]; /*FALLTHROUGH*/ case 7: + case 6: + hval += asso_values[static_cast(str[5])]; break; } return hval; @@ -114,116 +116,118 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 45, + TOTAL_KEYWORDS = 46, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 85 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, - 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, - 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, - -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, - 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, + 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, + 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, + -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, + 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, + -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 782aa515da0..23f1d1c249a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Fri Oct 13 22:37: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: 1848687 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=rQ7wG0Ub; 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 4S6hR155tCz1yqj for ; Sat, 14 Oct 2023 09:45:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB14B385E012 for ; Fri, 13 Oct 2023 22:44:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB14B385E012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237099; 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=rQ7wG0UbJCNgZ+nhgWiUIhxUwCNyifgrVodSVSUp3+GhUOU6KYUxfwN8sbm1ftx07 mw8C1hYTH0oeJJZYhX64oAin/wviyZ3GKPGf7QefzL+sR6gOnjC8wPuqYwpU4z8NcQ 8OkYA8HKBynUwRTG5R7cE3A1UyeuY/x1W1VhlKQk= 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 29FA5385701C; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29FA5385701C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=DCQ2Pi1yRQ5FHME5aKnXWb7SmyCcYzYHf2wvGrgxBUFBj4XP5d7cLtRiLnxBp8DJYIuwOvMKlGjtZsMxptG/QkFhSZir1b1oMRzCffKfHl42TNI1dsDF05++Vx+bUXQDsuwCIERCul1b6Z7Z2JZeUXgHY4TArtW/sJVpB70Qp10= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=Ig95QKG3jMRJ2d5xxOfPZpdM9Fw/zdK52c0tgvu9+Dg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=h4XI/OAuCRFu9fIsu6m7t1+Dg/WBijx+UtKLBshV9RBz4aYkrpKDp7WNKkDJI7cXwv5CbYhFFtNJu+h8+LCPAt2tNSBRAX1ZJO+HRq9FeRExhQ6l3vB8c6FEVlaWbgIQIrY/P26Jp9ljVsaDj6bNwvs2EAvDGICPYcWKbOEW8cE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29FA5385701C 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 39DMaGag004536; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfg9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1B5001530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1I016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 05/40] libstdc++: Optimize is_const trait performance Date: Fri, 13 Oct 2023 15:37:19 -0700 Message-ID: <20231013223957.1634024-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: tt7kH07b2xU4V5UwjtQUf7XkU4N0dqga X-Proofpoint-ORIG-GUID: tt7kH07b2xU4V5UwjtQUf7XkU4N0dqga X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=716 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848713 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=qBjdbi6q; 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 4S6hf90sYbz1ypX for ; Sat, 14 Oct 2023 09:54:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24B2E3850373 for ; Fri, 13 Oct 2023 22:54:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24B2E3850373 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237679; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qBjdbi6qkZQDjfy/e3EbDDsGP6EEGFCp/CSB25K8vQ+PMp/m/PEc/THxy6BifoGdu jEbQ0P7VA4G2eTANXZzjTfxk8ubFwqmpUmylX/8Bi8X+8S1RgpYPP8/Xqde2nn7WXT vHjVqqv7h2IYWRG/ay//7MBilFQsql/W5aOobaK8= 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 C4FDA385697F; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4FDA385697F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; cv=none; b=fSMXryriqRqnLTj2Qit0XgPjc0wYxOaVeJoVo53jMp3X7k9TKwF24hIl6pCZqfvYmzvZk/dO0i9mS/woGVZdoKbOUJaADzMm0YDhK308g9ddpablbILA2mqAttcmX4nmjEdq9Ll+2x1kZPBAFddRXJ6y26NuXk4ur6qZYf6lhvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; c=relaxed/simple; bh=IB28/p6AlpOolsW4jPzzQOV9D+fmGQGsZO62I2hPsCA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fJxq4k8bzqX2a1nbSrS08unJA3j47H34zlE+Q0fz9Cdj5JJrK4YIYRR9RPOUzstQ1RQIM7dQN7MGvu1010LMJhwczPAYyKaqRHOu4gL1MIevgxLtrq5wJlwuaiHt9jLU2rhyUDe5VPyx5KMNpFlmVodfQsUNk8WD4rLXnDJVKAw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4FDA385697F 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 39DMfdDU031258; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh18L001578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1J016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 06/40] c++: Implement __is_volatile built-in trait Date: Fri, 13 Oct 2023 15:37:20 -0700 Message-ID: <20231013223957.1634024-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2VzzOeQfK2B_OBkXG-nKniF4xygA4uCf X-Proofpoint-GUID: 2VzzOeQfK2B_OBkXG-nKniF4xygA4uCf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=850 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 47a5ec9ee6f..ea7abda6c75 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c9005eee1ff..f462794d5db 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 46, + TOTAL_KEYWORDS = 47, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,27 +125,29 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 70 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, @@ -159,9 +161,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -215,19 +217,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, - 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, - 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, - -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, - 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, + 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, + 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, + -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 23f1d1c249a..73178540fbd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Fri Oct 13 22:37: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: 1848692 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=wSl3VIqr; 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 4S6hSd6kwnz1yq3 for ; Sat, 14 Oct 2023 09:46:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B160C38618D9 for ; Fri, 13 Oct 2023 22:46:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B160C38618D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237180; 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=wSl3VIqr3XNr7ZyHlwYWQvUtByvqb3Go8E5wYyBjo4kpvIcnConwi10KzDJQbbyfV UvN4Kot4MaThPGqbTVwE3zXREPlSqxoTcdbdpQy4mq0NDffquhRudZrJqGTjIYaiWr 5XhncjSZ89u2fzyzAkUsJXAItVhXLDr7mRGBgKVQ= 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 551DD3856DD5; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 551DD3856DD5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=Tdl2GGy/9Srs3b77Eu7pv5rxde9M8CTaiuGB/st0Z6sYYKQUesX6jakuIaoOuacsi+vQN88ezY1A5ktXZqNwR9xg0JQO2vMKoGoYInjJFLGwfG5YVm4Qhk4mxRGZc1ZP9Miwaa46QQWiL2dRI2vVgO3yvy2c7Q0hAKyNr+nTa6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=C0QfeWKCr4uUzOqn+4ufr8dEtmbXQAN/FqKqiHue+Tc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NpGVQdsa5IyzA8trOt2qghR2sLm98ZoRCUX5GlpuvyaOFJ5gJbmI+tfldg5fdu/28Rvp3KVgtt0XspckNFmoruHwX4ipCvF3OxEjEmvWGmXEiwY9CnK5gxM5yQWfPxRcbYkGvuH6UMilHMhR3+/JvPCDR2vNmYM/mJ7zFkF65Y0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 551DD3856DD5 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 39DMgiqh001139; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh15x001531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1K016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 07/40] libstdc++: Optimize is_volatile trait performance Date: Fri, 13 Oct 2023 15:37:21 -0700 Message-ID: <20231013223957.1634024-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7jyEK_DsyEkAqu-rfNDM48Ey4acM_JDS X-Proofpoint-GUID: 7jyEK_DsyEkAqu-rfNDM48Ey4acM_JDS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=762 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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 Fri Oct 13 22:37: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: 1848691 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=x4WBbahQ; 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 4S6hSb0WNLz1yq3 for ; Sat, 14 Oct 2023 09:46:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DFE93857033 for ; Fri, 13 Oct 2023 22:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DFE93857033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237177; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=x4WBbahQ1b37NZjjMI2tXChn+PcHgujQBNlasgl9bzCoBu777l5+Rv3ytQ/U2Q13W usii8puTeW241ai8eNQ27EiRBYb7SJ6GCYvFAec6XYei4VWLqKgHYR1KM4Odz4MjTv Ysavdgu72j1jJsVUAXBndMn6dfcC/YkYCKesQxCM= 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 440CA3856DC7; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 440CA3856DC7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; cv=none; b=ZvJ2o4xfmuEmERZ8fGyfnM/ul2BXueQx22h3fDxqITNH+Js3J8QKzPH5QdNR6SPYMXh4E/gNCKjmK2kH6Kd9GiZpDvjuq72zUWQ/M3eHRhQnKJgWrhggnWdxsInt+FjZoO/84YrsZ3vKmIvzHAwcQiV+bQ9XzUfkRJPalie4/1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; c=relaxed/simple; bh=fprXPj47qmbdOKAPiDQTOc09TETOPKb/XjolEnUDEw4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ERp4wHkGXXtFZCYSIoIDcO5aS1HqXqa4eZkzk7jsPx1Pj7Hd9w6lrcgt/3JFrtEjgIZE1WaxfOWRoyVlohYTAK6P25LOf2B2rLaM/2ZtMQCS4zdP5YbmEpZn7agxhRcqkklVKKkAIOW311yCvRy8aBoEjSCOTKJmRvRMkZ/xv+I= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 440CA3856DC7 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 39DMceAr024615; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh195001532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1L016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 08/40] c++: Implement __is_array built-in trait Date: Fri, 13 Oct 2023 15:37:22 -0700 Message-ID: <20231013223957.1634024-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: I-_nUzHZQblR207uAHpxYqbPM8x5yeEP X-Proofpoint-GUID: I-_nUzHZQblR207uAHpxYqbPM8x5yeEP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=832 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 148 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_array.C | 28 +++++ 7 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f031e022541..5e30a4a907a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARRAY: + inform (loc, " %qT is not an array", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index ea7abda6c75..fb162cac164 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f462794d5db..526e63dec42 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, - 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, - 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, + 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, + 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,108 +116,110 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 47, + TOTAL_KEYWORDS = 48, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -226,10 +228,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, - 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, - -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, + -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, + 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 47 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 73178540fbd..e1358afcb3f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848709 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=XuxoOa4o; 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 4S6hbr2St4z1ypX for ; Sat, 14 Oct 2023 09:52:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47B61385CCAD for ; Fri, 13 Oct 2023 22:52:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47B61385CCAD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237558; 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=XuxoOa4oM3BVJqmPRAkwb4h5qcyosrBaS9janbRp6yEmX6wIWQjA4RvJVmjv7qgVT srhRZbCtgS46vVBJpRck5jh+0naG7ovrq/PrbdQgt9pz6IJ4E/QNuN7TjoWgB/sz3E FBbI3Xp1dKzyejnDepgYbDk+1PIUV7grWXP065a8= 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 36B87385B522; Fri, 13 Oct 2023 22:43:18 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36B87385B522 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=ASifs7kN8Ag4DjMUhEbDs4FYr5JzCXMGv1PWMVr94NTulsKAL6IBg04gjQLTP5NIcUH6vspeANAgm40f8GxTK9HJBNlWRDqcY0/0qPfmGaHJqXJ9AwEdcd39jBo5tYmohXCnj1HID5EHyv7Jwq6WBwEqL2kv02e026j5gvlSbhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=MOf+TxQspyRPPZlZdf9KhTx3QdQB9mHppfT5BFfsWxE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZUFH5WxtovsvN+QgIzXmY3RZA3p+HHaNZNcpsZC3Don5yKU+EqZ2HTyhR3vZ5Cl70cfmsngHLOc0fEYWTbh+YDdneH9L2Z66DjXbJQPiBjqjLko/UVyHi/qVbqglahqJyV+NVi+hikCKvF3BwjOsvbyCz/1tHReG+fHNpLpaw7k= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36B87385B522 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 39DMgPUZ001997; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05vfh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh15c001583 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1M016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 09/40] libstdc++: Optimize is_array trait performance Date: Fri, 13 Oct 2023 15:37:23 -0700 Message-ID: <20231013223957.1634024-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: FVhzGe5XbcYQAy0URv_ztA-23L698MJd X-Proofpoint-ORIG-GUID: FVhzGe5XbcYQAy0URv_ztA-23L698MJd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=477 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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 Fri Oct 13 22:37: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: 1848719 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=ncd4Mt0h; 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 4S6hj72byWz1yqj for ; Sat, 14 Oct 2023 09:57:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 529BD3857033 for ; Fri, 13 Oct 2023 22:57:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 529BD3857033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237833; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ncd4Mt0hvEbC9EWlAKRxCYSiLZulLO+h3pltLQ5/7583RQJS59stksUYJsaeTisYy iFYSRy25sO4aLR4+aXDI8B/lOTVr152aNqHOA+eMz9k826HsEdzhBnsdsBGwCZqyg8 MjO3EMcK+XX3p7MASn5CKyQUWamybl410Ldr3f9c= 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 14A4B38560B9; Fri, 13 Oct 2023 22:43:23 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14A4B38560B9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=O36E6f81M2SLIu4c7wr/q9de8yc8n1j6BjMS6to+yaQpLkFrawTqRdBvpjhQ1hLTugXXrvYVgWkQUj42sDU4oLB5Nuj3mDFOMxhuwJVlbt4SjY9KaTB4wgeNfag7u97sP5fDbztsxgpkDKfFtJqkHyx3j+VVRHZEu1mO60lXMjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=vyFkIM9zU5ChqtdiViJHgtZOBQL7xlNrBxml/awmanY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DPn4BhsBgLdYNrtrXh1mn0fRu5BodN/6JlDfXnWGioQ6l8A6rkES7GXUSaVL7SCjhF/MdNjSSl6w2tYvHzhspkkfbodosqXnTroHQU1YOiME/0eplS3Pj5wt6tDo9/gOPdcknwJWsf2ZtXgmLOWyQl2XX+3+amSy/jSej45mlTs= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14A4B38560B9 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 39DMhMv5016991; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8ttu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1lq003471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1N016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 10/40] c++: Implement __is_unbounded_array built-in trait Date: Fri, 13 Oct 2023 15:37:24 -0700 Message-ID: <20231013223957.1634024-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ExR_fl6-CGV7XVF8GqGSBG9SSrtD0tQ_ X-Proofpoint-ORIG-GUID: ExR_fl6-CGV7XVF8GqGSBG9SSrtD0tQ_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=775 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 42 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 ++++++++++++++++ 7 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5e30a4a907a..751ac61b25a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index fb162cac164..a894fc8c74c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 526e63dec42..47060ffbbef 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 48, + TOTAL_KEYWORDS = 49, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,30 +125,32 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" @@ -161,9 +163,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -219,21 +221,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, - 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, - -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, - 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, + 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, + 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 47 + -1, -1, -1, 48 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e1358afcb3f..0a2699be476 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Fri Oct 13 22:37: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: 1848689 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=YlMFDdYV; 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 4S6hSF1K0qz1yq3 for ; Sat, 14 Oct 2023 09:46:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 096513853519 for ; Fri, 13 Oct 2023 22:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 096513853519 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237163; 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=YlMFDdYVOVwEKbEyb2+Nol8gmOmqIL6u+lm41Rtck0n2LWxhgnMU05/3+IHpD9+wR CCTRvBzxjE0z4RG3ajPWmd6o4wRmswD4RjF7LhK03J5MRaEoyhRB56J6uQ7nEWn6Xy gKXkq8qCPDbQn18TI1FBQ84bnEgZ9PCMUp8USa9o= 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 D42103858025; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D42103858025 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=sjqlG5H/Aw/z5Li1LMqbNMh+2nF490Y9u2HHP1ReFunnzIaBpbJRIsE6mFSweiEGhEBg04C7xpjk0Lsp4LinhNAEPnLuxlmHHFWdMVrO0m9mLzNP8vfkrXLjoHxgA8Mg/SXlQGEBAR/4s3rpJsZnL7L+J2ALTZl6YJCmixukPFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=Cijkk+1KKS2ERennoIfTZ8dR0bWLbMoE2sdRxU4V8ZU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c8/yGnWRCNCyW2HCZghgsC9tWk8gi9VU7foB6q8b6xoj/8/jDZggMSRtWvdxi7LyUVvZxSTRJ8pimBYKFdlxReziDegnotU5sz3Ofw9KuhBtlxyv8Ed+xFj5FEyuBFnxftGymFvYLj3KRLgg0i280Lt5dxqTyQ5DAlkRO7TKD/8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D42103858025 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 39DMdxxD029917; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0md-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1tN021531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -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 39DMdx1O016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 11/40] libstdc++: Optimize is_unbounded_array trait performance Date: Fri, 13 Oct 2023 15:37:25 -0700 Message-ID: <20231013223957.1634024-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7z_7tWmsNxk05Ytsdbs01WL6tTKowEzV X-Proofpoint-GUID: 7z_7tWmsNxk05Ytsdbs01WL6tTKowEzV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=628 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848693 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=fi/yyuZq; 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 4S6hT45JvPz1yq3 for ; Sat, 14 Oct 2023 09:46:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B963A385700C for ; Fri, 13 Oct 2023 22:46:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B963A385700C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237200; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fi/yyuZqgr9lJNsfyfJ90sWXF9jQF7fqMdbsoTmjE2To7BZWtB4O+Zh0rTFlPcMiA FHYwTCvM9nCpiNcWWUKFyImiGV71BBm08II+iSqQlgnJHfePCKxyDzMVFvV0qSSi4W SPRqy0pIUeu056pH0O8yWnbzJKGKYW97a+iPTNgo= 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 583F63856DE6; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 583F63856DE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=bByKcci0zrB6HB9nthmIe/6s+/Gcm7o6xobh3fLcXiAbU9zQ6FnJpur/xAm3ps7jcwfzCdEjfxluA6zyYM9KBXIpAoMKyiyM+KNRk6ekWbQVF7960ZSkAtkU5RaUxNGc9RcuOsoInIJokDKUyBfOzLKEuOCPu54xTqWStRme/IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=Q+HVP/m3j5zcZWnVVUZYa33+EcvTbYtL23oYcv3ef04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EgqIAdIwCN+DEJVyLyX5RJLdAyaVh5TU2x8TIeman5y/2pw9P34WZLev+Kcu7XB7AwQ+Ws3k7bQ8n2NURLvD5rfoW+5Y+sSAliLeCHS/7HQSzatTKXi2+NrR4yZPvk5cgid0y3aQROTKelVMH5Uk7XCub8RKLcWhtn2Teog6Kk4= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 583F63856DE6 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 39DMfHFe030971; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1As012731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1P016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 12/40] c++: Implement __is_bounded_array built-in trait Date: Fri, 13 Oct 2023 15:37:26 -0700 Message-ID: <20231013223957.1634024-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Mvht2kRUl70ESpM9_y3GQX_UV9BL7Mee X-Proofpoint-GUID: Mvht2kRUl70ESpM9_y3GQX_UV9BL7Mee X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=843 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-12.2 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_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 86 +++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_bounded_array.C | 38 +++++++++ 7 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 751ac61b25a..d09252a56b6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index a894fc8c74c..90fcdc01de6 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false "__is_class", CPTK_IS_CLASS, 1, false "__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 47060ffbbef..f22a6e93618 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 49, + TOTAL_KEYWORDS = 50, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,54 +125,56 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -181,7 +183,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -191,27 +193,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, @@ -219,9 +221,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -230,12 +232,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, - 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, + 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, + 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 48 + -1, -1, -1, 49 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0a2699be476..32880754020 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Fri Oct 13 22:37: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: 1848699 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=DHNxbiGa; 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 4S6hW84Kmlz1yq3 for ; Sat, 14 Oct 2023 09:48:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AF62385E000 for ; Fri, 13 Oct 2023 22:48:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AF62385E000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237314; 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=DHNxbiGajzGPN7X8i+sd7TaelWv3UuM5BGkHXUdzFxakOMwJ60yf5ufVhSeYPQqfQ ub3T5dPEXri7t1nvLtEAt46h7ikA1oxwwiakTR0AftYERXZ2HjolJ+GAqZAH5Dlz8W +eUe9DVWv/iWNB682n661W9oVhsXdkHl1fQlHY5c= 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 2BD103856965; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BD103856965 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=vq/y1601+LaJ5dhz/+6WmCznE3twVayycuiD4a6e3QR61AjyFBf18JPtQFhVnkpVbuO/Pe8fhSFCyyhn6v2oLFHHk2TdOY7P3Wn6p0wMsQ01vYzs3tejjfGOI9ODbLUpWNGJRdGSLV+mLxwFLD/gkovYhXzKVy4j/oFP58Y7Np0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=bh/DHfcrUuildpW5273OfXvIzy/3HS7X5XXA7BH7W8A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GH6czaHwsbTKCcI9brXumWpKb5t6XRXM9WIizKBTz8p3iwu6B+ICm9WkSoTchdZp3A7Q+wdiGZ0ZRH8rEsanJoxTuNx7YblkMMum7J4lbg94QO6ozSJujPM+hcHX3GJNymWUqv/IvjAo5QRbQPsh0pHwMn4Lr9JwXbIM/5dhnYY= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BD103856965 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXSNY029268; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1YJ008020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1Q016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 13/40] libstdc++: Optimize is_bounded_array trait performance Date: Fri, 13 Oct 2023 15:37:27 -0700 Message-ID: <20231013223957.1634024-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iwZDedicFaSSzKa-U7h0iDEUCsJNIZ1O X-Proofpoint-GUID: iwZDedicFaSSzKa-U7h0iDEUCsJNIZ1O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=620 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 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 Fri Oct 13 22:37: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: 1848715 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=n6pHa5Ib; 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 4S6hfN18yBz1ypX for ; Sat, 14 Oct 2023 09:54:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10CEA3850364 for ; Fri, 13 Oct 2023 22:54:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10CEA3850364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237690; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=n6pHa5IbzWVr0ol/RH1GiGrvuNqUwKkz5PRXMojfAcSeOJ2i9o02/0DPLI0NmgZhy IKesZfPnfWq8vW0/sFXOKUXdtnUs8qawuJ9Q8h37b+s7aGqH6Mxg3q7H4lXgG8QkOR Lj4PFHiKDVbYWbqwz5QVczO27zsuE/aYakNg72hQ= 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 2E6D9385609B; Fri, 13 Oct 2023 22:43:21 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E6D9385609B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=bahp+jXBt78VR164bjU+fTnfNAwnzcb+X0Sa3L6xjCcy20nvdYI+gV4UXbwxZSDL13v1YKFvEO+h5Hwzt3LMcoekoZtReXg4sB4yP6EwOBsY3OS/7/+0oQ1BI1aACo6YsEh52qF3LNeq1/ppKZzYo/PYqSUHRyVxeDdfy0N/Dlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=wZ4cErfodga3j0e2Ef9CtgdrrubkZ3aLrFe+WfKn78U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CkNX0o52897/ycIM/sTK6DPE8wKwm9KaoqE4XuxsTbpX6sPcR9woyPx3aXs9lqrASELIc+j6/q3iWDwvLgS67D4ceXoC3/Zx0LBc+JWjXMwqWtsIJE34gpE6XQ60pMJzlI3PkLQ5ax2t2AYV+J9Yb7/aWzO6d6Bl8iXVJWeTAYo= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E6D9385609B 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 39DMhK41008504; Fri, 13 Oct 2023 22:43:20 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc7usj4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:20 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Qn008021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1R016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -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 v19 14/40] c++: Implement __is_scoped_enum built-in trait Date: Fri, 13 Oct 2023 15:37:28 -0700 Message-ID: <20231013223957.1634024-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8aufoB2dQgTN5KBii8q-syxFGGhouSEi X-Proofpoint-GUID: 8aufoB2dQgTN5KBii8q-syxFGGhouSEi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=866 phishscore=0 priorityscore=1501 adultscore=0 malwarescore=0 clxscore=1034 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 90fcdc01de6..f3fd82ba549 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -59,6 +59,7 @@ struct cp_trait { "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f22a6e93618..9c18165eb68 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, - 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, - 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, + 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, + 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, + 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,56 +116,60 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 50, + TOTAL_KEYWORDS = 51, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -173,22 +177,18 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" @@ -197,47 +197,48 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, - 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 49 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, + 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, + 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, + -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, + 50 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 32880754020..f56ab031d5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Fri Oct 13 22:37: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: 1848701 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=xMXc8Opk; 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 4S6hXN1xzzz1yq3 for ; Sat, 14 Oct 2023 09:49:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 458CD38582A9 for ; Fri, 13 Oct 2023 22:49:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 458CD38582A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237378; 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=xMXc8OpkI6RJX0m07LYn0BeSTRlW4rCoJ6tJR1IFEleFlqi9awhCj4pZew4JG8TbM FXuqG4lXRy6q8dierfLwjt+bHN+4YxLmrKRVUJCvOdwu6p5ZHgh5agUPu+UTAn7FtG SYDVL7yuxQwDeYo+F6C8ykRgWRo0O8UoXxmi61gE= 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 67EB23856DFE; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 67EB23856DFE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; cv=none; b=Si2WBcjYxNNjL4ztYndwGu387+/XtvawbftNdUaYN+E/pWhU/Ssmxk/Dhsl9Gj75Ie6nLcxv28e1/0qYBZ1Bew2m+UzlJq971B1yGtAr45IDoku3jDsEWMCIIzQsH3f4rWCNpuRHVkK76bZPc3mWrErVlG/xHINWxbeETiKzpV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; c=relaxed/simple; bh=Nz7P73GKgdaoysk+y3xwS5zNXk6vIepk6igOSMNcwIA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bEAUOpV8lydxK3rqL1eSSbpEhIQ88m2bWr4wpaU3kX7K2aZsIU356TP8QYXLyD8N+eY48xZ062AMqmhrLQmZ+W7Clf772RnxOfAbWdfSWRDbc09edWgfTCIUCzLZ+gMhQtx2/qG9IZiC/tE0PN+IhHRVQhCV/esQVYAhya9bdCE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67EB23856DFE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMTicc021741; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15ex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2DP001548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1S016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 15/40] libstdc++: Optimize is_scoped_enum trait performance Date: Fri, 13 Oct 2023 15:37:29 -0700 Message-ID: <20231013223957.1634024-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 1xKiETtWJSXOxGMTeSttVWACAL8JO2hU X-Proofpoint-GUID: 1xKiETtWJSXOxGMTeSttVWACAL8JO2hU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=768 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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 Fri Oct 13 22:37: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: 1848702 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=VnLqwabT; 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 4S6hXy0MCgz1ypX for ; Sat, 14 Oct 2023 09:50:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05F1638618D3 for ; Fri, 13 Oct 2023 22:50:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05F1638618D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237408; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VnLqwabTxW1jXkre2EXlAdnkmooBYF7AWDoJw0w/xQ3I8redfeFph1Uuu6fbNZH2a NWTBG1jRvOX+TGMjpEDzAglO69j7j2Ey8T43dsrj1nbt6YGwHe/4KE2YxqSWUkL7oA eGxRU4WXKw/6rT3CEPhnNmaKYuPhjn/S1L27024M= 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 C7B58385B512; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C7B58385B512 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; cv=none; b=I1sMMuvh1gaaG+yg+YoDmfPpXtV5aFcJ9qldV4wrHb12R/kL4yF9cr0KNQED0EypT/P1K3pbYSJ7XxWQom+AIFy9+4iDvTg9ofdIhHNQy347ag+bP218Ihcso8DEiBICZShsVy8UE7HYDhRjdxZSBKYjEKYe5cedPsl30QLfTck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; c=relaxed/simple; bh=1JB3WSn5crkfytlv76hSa+eBAv+J5ca/oP08hFCfW/8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DajBrvoa34WNFtFNB/TaOLwk0CxQEsU3BT+LDhf6nltzbuqcfPDF8HW0EpHzTh/Ka7UdRTVZp7CcVFjDB1Pt1M//yv42m2NiK7D1rDWhUUOhRxY7BAD+u4VegMxfpF4tKgGgLhdl7nf1g7QOoS4GjXMRyLh5074tT4QluZo81PA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7B58385B512 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 39DMXhBC030698; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfga6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2jD001588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1T016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 16/40] c++: Implement __is_member_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:30 -0700 Message-ID: <20231013223957.1634024-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: f1jC9NT5UnOw2CBCsuwMDbBNLQXgt0Tj X-Proofpoint-ORIG-GUID: f1jC9NT5UnOw2CBCsuwMDbBNLQXgt0Tj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=832 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 f3fd82ba549..3775b11283d 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 9c18165eb68..dfd60cec6e6 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 111, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, - 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, - 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, - 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, + 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, + 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, + 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118 }; unsigned int hval = len; @@ -116,69 +116,67 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 51, + TOTAL_KEYWORDS = 52, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 117 }; static const struct cp_trait wordlist[] = { -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -187,58 +185,63 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, - 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, - 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, - -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, - 50 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, + 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, + 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, + 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, + -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, + 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 51 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index f56ab031d5f..6c4880d8a33 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848695 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=LjWIEbbD; 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 4S6hTd26Dmz1yq3 for ; Sat, 14 Oct 2023 09:47:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 130323853501 for ; Fri, 13 Oct 2023 22:47:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 130323853501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237235; 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=LjWIEbbDvNADKz1jQqEvEeuOzgM+FN7l+UCAIEkBCDxmhaGL2/kNTHo4n+HemsDdq ZBI4kru4cT0N4S69YTqFZa3f+QZSO6lFTq/BFkRQJydCqTUD7T0OCyFPbbtKcchLms 7fGe6wFYGnm6MzdT4yh2hWG+aggcYsXKF0nxsHSY= 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 5E5EC3856DF1; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E5EC3856DF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=REKJllSS7fOYSayRLtcxzD9R3onfdomLcWTssOCp442LpAxY3Uq0t6r5dlTgwByEG0/q4Wlyghx2Ta+HC/fcJHlzkFxl+soNegSHWpl+lBt8v6BWu3drNUAwrZGh9+2GFe+5JRUBGv2KmHn3q0yK8g830V0pK4wTwU4s6KEI7JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=UJgksNSlORUlZPpOVuq0Q6PZq76Ryp5/hjZPmLb21rk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=G6/27GBcFEsT7OZdrjt5qC/iV0JjVTUM+o/U87f2t3ntN58Un80SYsWC1t5q2BD3H0JYxjX2htunFo/MHr974QCiehBG1HMbFMaAWOiDzkvFiymWsYeKOU5HUNFuDjEegRJIK5237LLNdyoRe/TiqU9gVLqoOAcCJsGGjnj4AiI= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5EC3856DF1 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 39DMfHFf030971; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2BA003481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1U016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 17/40] libstdc++: Optimize is_member_pointer trait performance Date: Fri, 13 Oct 2023 15:37:31 -0700 Message-ID: <20231013223957.1634024-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mFdC12rHVB74noYNf-PuF6_qmu-27ZY_ X-Proofpoint-GUID: mFdC12rHVB74noYNf-PuF6_qmu-27ZY_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=580 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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 Fri Oct 13 22:37: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: 1848697 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=DzdZFL7/; 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 4S6hV3291xz1yq3 for ; Sat, 14 Oct 2023 09:47:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D91C385DC30 for ; Fri, 13 Oct 2023 22:47:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D91C385DC30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237257; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DzdZFL7/mje2mYo2UISvTZvZhXZ3USqrf4muHXvwtpqhkq2acXZ6LfklxrAhZ6lGo 9rVsxV3joJcJP33WJ4KVvPn1BVRs8JhJ94VF3SLNwPzuH8BJa6WsB9W7w2UcHzuT+y S/dIwX9qm2xv5h5o+OQFwgtUWEkZUWCZxCBEY1FA= 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 616AD3856DF8; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 616AD3856DF8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=mzNGe/DJzJunZDXOPjKAUtCSahtCQOrxbNbmwt4/pehpgKcm6gNNY63I+9qbRsNiCDBONN2Z8UcW1ZJ/fwSiuHRrcteuKuNo1cuZJMOxgcokMFlQwwjANUEkr5git9VeoydOz87NR4sFX7SGO3pYrzqlahoWbWWIG/JwvLedEE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=DzUVpyOctR/NNW/yj3m9FlgZDpcOLFX/MSM4xIbD5xg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ng7JElLXOISljtGumJikla+o6XtgLSr5xjxiqFxYeFUHfrB/tDTEqNihA5vu1/FgTJnyFVyU24iwzRTtakZwaIbi5gLqKVyQTo/fXHogdPgweSVQt+ot/Qv+SaK5oZWlUEdDb8R/7lZPhxisQLN8Lrp9+wqxcjbQy+TxYKkdqKQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 616AD3856DF8 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 39DMdklR026434; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqe7n8c4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2XI003483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1V016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 18/40] c++: Implement __is_member_function_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:32 -0700 Message-ID: <20231013223957.1634024-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: BuGulSSrgRFmZVcR0LE1YYumEX5bgqI0 X-Proofpoint-ORIG-GUID: BuGulSSrgRFmZVcR0LE1YYumEX5bgqI0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=901 clxscore=1034 malwarescore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.2 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_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 176 +++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_function_pointer.C | 31 +++ 7 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f0d3f89464c..d0464dd4f6a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_FUNCTION_POINTER: + inform (loc, " %qT is not a member function pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 3775b11283d..b28efbab322 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index dfd60cec6e6..d3d4bdf9799 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 111, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, - 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, - 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, - 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, + 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, + 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, + 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -116,132 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 52, + TOTAL_KEYWORDS = 53, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 117 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 75 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false} +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, - 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, - 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, - 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, - -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, - 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 51 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, + -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, + -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c4880d8a33..4d521f87bbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848716 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=J/e0Gu0n; 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 4S6hgR4vVTz1yqj for ; Sat, 14 Oct 2023 09:55:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF2A83856943 for ; Fri, 13 Oct 2023 22:55:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF2A83856943 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237745; 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=J/e0Gu0nbTrYgrjMzWbCAOAvmO+2/eJABsnXDxhKoMZ3vnQKx35XT7PpLQaj11rBE OfpREg3YwK8jWNEl3UAZOcwZPQlXoxPf1lEBRrsiHsVpzwPe3xsUtMnnbccK3MGmac +qHGv5LwSCfGtmmZRcpOi23tlM3HF/pJxPLrU7vA= 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 0B0F2385B531; Fri, 13 Oct 2023 22:43:23 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B0F2385B531 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=n9AjlQSvG1zM6MwlZZb7k6d6ozcI1SRV1uBcYmZ9mDUZzKwkTirFAtKSv6MWGxHRUuoVpgOHFGv3tJsXFxSFajAA2inyZGUCdNVnHnUhqC+iSEv8XRwuQkqKRbPEUn/+/KuIan9CjupLktOQoz6BQhd/pn354fplN7lRsg6XeoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=QuMkc1ehlJ5Wg8V4Rsxxo7gXiPPchTtHkDih2h1/T8E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nBX0kASE5OBYWEU1O+xElZUrwzj1KAOruNj05KTxQmL2tJ6bZsZAwmB3pFqCfom/UxUM27mBw6qfjwNoje+En9+14icX7v9GNvLvpeZ+9U5qZSm3bY5ua88mIhJZ27ZzgBbx9Hqi2cPv5zEB7QUxfsnvCKtV4FDH7EEzv29IJVA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B0F2385B531 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 39DMaOI2005493; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2q5008029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1W016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 19/40] libstdc++: Optimize is_member_function_pointer trait performance Date: Fri, 13 Oct 2023 15:37:33 -0700 Message-ID: <20231013223957.1634024-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ppefL4jqnpTd19YgFLQrK3FwIU_05hfL X-Proofpoint-ORIG-GUID: ppefL4jqnpTd19YgFLQrK3FwIU_05hfL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=665 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 Fri Oct 13 22:37: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: 1848706 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=gdYUaxCh; 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 4S6hZ24gQDz1ypX for ; Sat, 14 Oct 2023 09:51:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88FB63857351 for ; Fri, 13 Oct 2023 22:51:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88FB63857351 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237464; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gdYUaxChRvvV2bzlRPSVfBAMkCiDbxoHRv1O0HVqVKTwOsPqkqNPx2I002ROYi5LC 1djVkIH7hR/RhlIpK1+wIkQxXb4xAcoXP4IN8jjfgNsdEqvKkoTYuVIcLUGX3SD/Fx e6Nu8fPdZ4HhO3MtdUx+wraFSJHGl8HrsBuJL4aM= 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 558A53856968; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 558A53856968 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=bf7rJ8Trlo2hv9Q+Kptdll2Ld90WGg2Tjbk3gQXLlVTd2KHehgq69THZCqJOCQKxtka5B3gU60i5mogBo6NFSbVQVFq5LP6bcJcMSMdFVyRhzbglyFa2O2XIG2GkPtXX06dwKC3A4u70M31KpPnsUkih31PbI2LtinxGuNqW87U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=17iXH4Kz9nRm/qvyK7TLTejC/fcRvg9+OrOovzXpYJE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JaVcfDCFU0tO/AYnlHCXoWXEuWASTmHBgNPK1ZpawXc53CPvnLZaWNgswaIjwtrPrsHYKXq2p7hzD/oH04647uRO+Mx3gHCFdxpjwGecr/GdIw+7eOmx6endWoghmt5mEPChg9/c/vMlRFkV2Uj5qWwsNyYRMxJJGgwlVmxuRTk= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 558A53856968 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 39DMdxLw028167; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2SL008034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1X016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 20/40] c++: Implement __is_member_object_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:34 -0700 Message-ID: <20231013223957.1634024-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: NlJaf4rxOHYa7O-BcVORvz4oeMhtZz1s X-Proofpoint-GUID: NlJaf4rxOHYa7O-BcVORvz4oeMhtZz1s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+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 b28efbab322..32199a1fe9a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false +"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index d3d4bdf9799..799fe2b792f 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 53, + TOTAL_KEYWORDS = 54, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,57 +125,57 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 76 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,25 +185,25 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, @@ -211,12 +211,14 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" @@ -229,7 +231,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -240,8 +242,8 @@ cp_trait_lookup::find (const char *str, size_t len) 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, - -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 + 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4d521f87bbb..9cbb434d4c2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848690 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=g1aSXFab; 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 4S6hSM2Fxyz1yq3 for ; Sat, 14 Oct 2023 09:46:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1A7C3853537 for ; Fri, 13 Oct 2023 22:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1A7C3853537 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237168; 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=g1aSXFabC6IJ1l7LqmGM2vLdhsgiKh7TW9uAyHW1H8AopqdTkrUf3U8WPGG9qcznA BZmENabeOpr3p1enoob4D4PUih6pbMe0TUxzUnRoM0mZbzRYV1p39lt0Ol4u19FvNz IqXw4cAjQ2kzQSwuxvSDrpc/HAt6UnwQHYyQvKE8= 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 3C1453856DC6; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C1453856DC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=TJ1D0Izk44j3CE9TSYlQ5RreR9FfJMtHxZgRqhILePwy/Gk8BPiSrrmGEHzKy+Q4P79aGus4qoymHRLIrjkp0LNexvRuDOgD0CksmMxqmCP6lEoIWCoJuI+AoFrFgsLG2SsRXBL08vIInDqOpry2kV1CnfhFrTjvZ36C8yYtiFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=0fPox7o95TE1z8HSfQmP62vuVnxXyv8pdeoAV2lJZWk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EjlrlyCo3CqzxWTNaRQmRqjCe1JUGd63w9v22Z0ExzobWf+h6RtGUwsWKcXgA3uBiGV2jd+TEj45E9xr2zUwAPVV7UGXNHdIfROGomnwmFKoJxihR9rip3eGxKlCllmI20VEHTLfAioASNZdESRYuABYOdzA0O2b4X9Vvp09MI4= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C1453856DC6 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 39DMYn2x019858; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2ao001560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1Y016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 21/40] libstdc++: Optimize is_member_object_pointer trait performance Date: Fri, 13 Oct 2023 15:37:35 -0700 Message-ID: <20231013223957.1634024-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: p8LRpHXi2ITTL8wPFvh5CDzW5Za4uvgF X-Proofpoint-GUID: p8LRpHXi2ITTL8wPFvh5CDzW5Za4uvgF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=596 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848717 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=i3fbovmA; 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 4S6hgx5ynnz1yqj for ; Sat, 14 Oct 2023 09:56:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7076385CCB1 for ; Fri, 13 Oct 2023 22:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7076385CCB1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237769; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=i3fbovmANLaqf3o54p+DZi3QqDqXYCg1tZ4/2FiGqCMt+hLaygFOrI71E0Yb0wCw1 tLTr4uZCRVm8cFqhB7s88N6SOB1enrQOE0zUe9daAIy7ETgGeTp4OfVRPOvm+Jk5uY s7cmPkhn/MRhaxK6GMHxTFrbrjHCcGR985PtkmDA= 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 27802385B516; Fri, 13 Oct 2023 22:43:18 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27802385B516 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=lQ7c1XtWejsPHH4aWdp8RGK3Wvv0GqQ2xJcXb721Hu0glQ/i5l4HWgK/L7hmdD2lJ1r34nbwYBrgaOLoga0fpAOPAWcIjzsGYg9Wy9RGLLht8FG2Kff18CIGoUKw5JGbJrvg+/lZvwVVf9P5uwT5Kcm5z+avmq1vMZP1dXLViDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=72rISvwIVqIt7ZM3nxe5nJUSOIHMsd1e1LaJlDExQxI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rzugrf0moie7Xq4oI7oIMJvuvZtjx/VLzCfW6HHuP/q4HI35W+O8uLm/px5kC5yU8U/S9q+UU/Ele3NWMIlutZAUW6KLRyIweWX3gHqJFYfIXXR0U73yJFjfP5hVqRG9eNJaFyQv4Y3DhUFSBbXxsiGUGz31tfExzOf6EgqdYQY= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27802385B516 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMMQHV005607; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh24I001598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1Z016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 22/40] c++: Implement __is_reference built-in trait Date: Fri, 13 Oct 2023 15:37:36 -0700 Message-ID: <20231013223957.1634024-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FDWHMJ4G79SaznbLelILqiQSVMN6fJFb X-Proofpoint-GUID: FDWHMJ4G79SaznbLelILqiQSVMN6fJFb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=795 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 32199a1fe9a..5989b84727f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 799fe2b792f..f0b4f96d4a9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 94, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, - 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, - 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, - 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, + 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, + 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, + 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101 }; unsigned int hval = len; @@ -116,58 +116,58 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 54, + TOTAL_KEYWORDS = 55, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 100 }; static const struct cp_trait wordlist[] = { -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 77 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -175,7 +175,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,7 +185,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -207,15 +207,13 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, @@ -223,6 +221,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,8 +231,10 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 82 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false} }; static const signed char lookup[] = @@ -241,9 +243,10 @@ cp_trait_lookup::find (const char *str, size_t len) 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 + -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, + 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + -1, -1, 54 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9cbb434d4c2..df720459458 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Fri Oct 13 22:37: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: 1848694 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=NL58qL4i; 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 4S6hTS1wdCz1yq3 for ; Sat, 14 Oct 2023 09:47:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45462385E019 for ; Fri, 13 Oct 2023 22:47:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45462385E019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237226; 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=NL58qL4i7zSXn0l7GDkw8jbXadTKNe/hULSfxoFxIpfzxnnohplsfiRNJUrk33abx QL6BCvAeRuNYMsIGRhFpAnZyj+4nI+wHSgbfoVMKr6TPc4Mx/+wUPsbxRc7XZJq5nC tohni/kZKaH35Q4/H2JXOxad91xskb9oJDfAklDg= 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 6C6403856943; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C6403856943 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=s6X6E0kf5AURbxIeuVeIWZH21ngp48R6DsVIONzS8k+s/7fswRDGXRaxmsIfCJp9Ezh1IqewKlIcQU2hqDA8kMvstOf5/EZqZBnTac2J0MkcsbY8D0q1kcy1CUs7kqKJWc9smYudAp88RTrazAzAadvadt4GSelsMTa2HPW719U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=/ZpKzUC/+Cn+6c4i+PdtJvMDzWz2wSkg6dqToHkptIU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kglCAAYevoB69tAPBZ5cYV9nu9Q1GQOUijKGPOtnP306Hxa8myK7esEmV6dcrTTqZHru5DD+wyAXXUHhbKHkSo/OpmtX9Dz3B1/TESmBnkqZKGaCHleA5SiPX3Mdz/SxF0aC1cUKe8QUmmAmLZvKVNo6yEVT9Pc7SF2jZS+RENE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C6403856943 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 39DMd4Eu025980; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2UZ021601 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1a016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 23/40] libstdc++: Optimize is_reference trait performance Date: Fri, 13 Oct 2023 15:37:37 -0700 Message-ID: <20231013223957.1634024-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kTdIoD7Agry36Il-9d3ghDZo_NkmffCc X-Proofpoint-GUID: kTdIoD7Agry36Il-9d3ghDZo_NkmffCc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=782 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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_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 Fri Oct 13 22:37: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: 1848700 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=WaXiuK+a; 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 4S6hXF74gkz1yq3 for ; Sat, 14 Oct 2023 09:49:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0997538618E7 for ; Fri, 13 Oct 2023 22:49:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0997538618E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237372; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WaXiuK+a2Q1T2zKxK+ptZe53RSY/TmzL61yzy0vuNAi0QhbTcWz6o3dhvWj3fI85c fFtPZ3QWpSxwIvnv3VEvxEbcXFMlGfJNzJHQDRm+eHWWl6RK+bXxeeILxZL/urAGRR M+hHvUbVYAZ/8PwPwgpGQBGjCi/NWrdyD/xL3iIU= 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 5B5983856DEA; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5B5983856DEA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=ov8+r+2FfolT3Wf4X+CLTnF9pf+8wdW2o6E1oKYA0h4rEJo3T5JxdmZw5aUa4PivhdTtxhnpx1b9ZPdVOO4QC6tnTHsdQ0SLZIOn9xeSSipKY522xGcQ2rGN9A76Ee9WrFETmrLgx8Dw8TNfOCfYOFnlgyHvb000LTmPq31IeYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=8ltNAspFMVEShE4/X+456cDQXE0Fa0kNHV/uOBHUK94=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KhUrIY1s6KZ7dEDlg7AhK+xpWy0g/iJvMSFS1xRZPbYzzCF2TNMkNb5IUfgzQgZNdjNw7TWY5tjlp9eAAe4L+dnObfv28tXEYG/O1ry2eE5a90SrJKpc5X7OuKMtLuMg4TjfBObB9DougRjZwpnworv9i4ydocnVpV21LBJFGfs= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B5983856DEA 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 39DMZuc9017804; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqe7n8c47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2te003493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1b016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 24/40] c++: Implement __is_function built-in trait Date: Fri, 13 Oct 2023 15:37:38 -0700 Message-ID: <20231013223957.1634024-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fQDJy8JkOWkwA_KVExD5tv1nYeqVWc_J X-Proofpoint-ORIG-GUID: fQDJy8JkOWkwA_KVExD5tv1nYeqVWc_J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=936 clxscore=1034 malwarescore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.2 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_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 143 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_function.C | 58 +++++++++ 7 files changed, 143 insertions(+), 70 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5cdb59d174e..99a7e7247ce 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3750,6 +3750,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5989b84727f..771242a7f45 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -50,6 +50,7 @@ struct cp_trait { "__is_empty", CPTK_IS_EMPTY, 1, false "__is_enum", CPTK_IS_ENUM, 1, false "__is_final", CPTK_IS_FINAL, 1, false +"__is_function", CPTK_IS_FUNCTION, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f0b4f96d4a9..b6db58e93c9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 94, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, - 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, - 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, - 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, + 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, + 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, + 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,113 +116,113 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 55, + TOTAL_KEYWORDS = 56, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 100 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 78 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,10 +231,12 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false} + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = @@ -242,11 +244,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, - 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - -1, -1, 54 + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, + -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 55 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index df720459458..4b8e80f3e62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Fri Oct 13 22:37: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: 1848688 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=J+3G8o0n; 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 4S6hRH4f86z1yq3 for ; Sat, 14 Oct 2023 09:45:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFEE6385DC0A for ; Fri, 13 Oct 2023 22:45:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFEE6385DC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237110; 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=J+3G8o0nBtPc4s+2LIcWad4SqgcWOHRDGXXnS/cEQHHTfxqjzLS1AHrO4xMx0nhfK Zjjmzvx/4kxeAtcWHcxOE9VuZwiPkhXXn7p5BtE6at2BbteaXG/FGXI4CsVn+wnwaR 0nYO7WQm2pndKAlUcdj/eZSULQX/UTRVAkCMf8tg= 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 23D1E3857359; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 23D1E3857359 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=G+W4Z/71PUsd8HDoT/s2Vj/d8KV1/WD5jcj45061HpowSI3tmcEWV0yvLjOfRoWHRE6/Ff4vgStv6TOZIf+uuhydXDV7XYHomEgGuMsSaUrXr/Z8Bm82e/MWEM7HZFbpJ5Vzy20CDtIhgKQ5e8ViG46HHKHM7oFO+a73925Rv3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=c205PSleSo98VKF72O15l6crxQGKXbefxic2LHXRDwk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vIt4hy5+Wi0JpIucaA9ExPdAo0g1RKPQyaWsKq4RqHF8rlGLNRjJmVT5kfe2JEliMhV85K3i8X6X1S7KlmhBcJpf8BHpICovPltM9uZbTy6BwHecXrCrUhYn0XTCMiwGdUFP4bQNo6eY67u/BACXYMZfdr+kHU/xjIqx7fdL7XA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23D1E3857359 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 39DMYn2w019858; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tbx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2ek021602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1c016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 25/40] libstdc++: Optimize is_function trait performance Date: Fri, 13 Oct 2023 15:37:39 -0700 Message-ID: <20231013223957.1634024-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dcwnQJIGOAsrxb2UU4hFzN74C4Kmrx-C X-Proofpoint-GUID: dcwnQJIGOAsrxb2UU4hFzN74C4Kmrx-C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=583 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848698 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=J3mUj9mq; 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 4S6hVX59ybz1yq3 for ; Sat, 14 Oct 2023 09:48:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B013C385F00B for ; Fri, 13 Oct 2023 22:48:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B013C385F00B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237282; 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=J3mUj9mq1XsTE6Zb+reCuUWDOTIHc+pdF6JBrdbgK/LNx08VkwJYHduuLyuWR5BRG K9x2YyHDvjFzw5u+MBrf0eOrssrWLafXn/pr16aHl3vxvsDSsts+gCVcMKAluIvXQm 0rerSVjWqmpUlnAxN46+MArBoUa3SM+/fMrDoKoc= 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 64A9B3856DFB; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 64A9B3856DFB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=YMLB4WiWrk3CJCZJerFbiR//fM5MNPnrdTMsi/gageJUMnpO/X+1Nn6vpjhMwy6w0DaHCfckDdN1whba8KOnv3gR/0dP7acgR3+AR+c280zsx3aGOhMT4ArgLh9U2xUc+R1Bacw76OX7uyvoo5nXJMe2y2aare/ItbYtGLCE20U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=zHRUm094zuZ3ZECOAp015pu8rl+10kg38IxbocgWKRo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Oh/aJCVm9OHsmrp0Afk6Fp3f6D0+PpcRD46R9EVp1HZW2vsdSF48MWkIm1t4xOIkGwPhOx7IGztG9e5eKjavz3ruUyuNCgu/o0dgUTtxZkTZJA0x/zAA7ko6e1C/lWjlwOPr+ZPMVqsOJ+kd/mlD4HOig1k3uI2lJ9iBgM44oK8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64A9B3856DFB 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 39DMXZwh011654; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbp41w84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2BX012744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1d016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 26/40] libstdc++: Optimize is_object trait performance Date: Fri, 13 Oct 2023 15:37:40 -0700 Message-ID: <20231013223957.1634024-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Q3rCoOdy4TkVUC8P4GcCaiqXNMqE3NZG X-Proofpoint-GUID: Q3rCoOdy4TkVUC8P4GcCaiqXNMqE3NZG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=793 bulkscore=0 phishscore=0 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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 Fri Oct 13 22:37: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: 1848703 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=wBFB5OBx; 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 4S6hY80G1jz1ypX for ; Sat, 14 Oct 2023 09:50:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A2203861869 for ; Fri, 13 Oct 2023 22:50:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A2203861869 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237416; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wBFB5OBxIMxBKxa4IYVCmH/74u1E80jNzAoWVDsp3Pky/l/lMNxjJw5EogH2Az33c ueu+QB2DwAfesZqDTxR0LDgcjTTAiVF1x+S2v323MuG5oagMU3z3BHWOQviKhKkJzB Qx4TJDviZIDLd2CZNeIoJVJQ9dODFcx4uuJ1TlbE= 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 0D1F73856962; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D1F73856962 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=meFUNMYbOxSnL8oTp68s0dzZEN0vxgGy5s+0bvzDnIiW8vdgvWeFffyJZJGgvPnM71/kqkypA6IcDQH8+tGJ81dnj0u45PpKXMck6Nd77d1+OCmbhshY/MwQFVMw/ffX10obOzajbPFZgqiHjkvif219LmekEDib7+04XKUvdyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=2r3iD77OE/JU9ChDDj7KX0mfbuBR5Uuh+aanU0JlCFs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=odf/QlC9wvx63f28sVX2SZ/iiMpxzJuW/CUhWlttglDg1OCVPAYQYw+e8mI2UlEROK0YL8JT6FSigjZhj5uYtXznquprlHbfLckJoHplEkGq/ULVtpMqhoLZCSwuqDsaxZIiRSt2L8wjiuzqKiQ2YeYzXV56FS65VpZU+OWxc/8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D1F73856962 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 39DMYVmn008921; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2AU008046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1e016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 27/40] c++: Implement __remove_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:41 -0700 Message-ID: <20231013223957.1634024-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: LDiHjk8iqCP1sSwUBod-xPVNe4xbCbEf X-Proofpoint-GUID: LDiHjk8iqCP1sSwUBod-xPVNe4xbCbEf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=587 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-12.2 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 771242a7f45..8fbd67788d5 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -77,6 +77,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true "__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_pointer", CPTK_REMOVE_POINTER, 1, true "__remove_reference", CPTK_REMOVE_REFERENCE, 1, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true "__underlying_type", CPTK_UNDERLYING_TYPE, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b6db58e93c9..ad2c2a2d250 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 56, + TOTAL_KEYWORDS = 57, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,7 +125,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, @@ -137,17 +137,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, @@ -235,21 +237,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, - -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 + 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, + 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, + -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, + 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 56 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Fri Oct 13 22:37: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: 1848684 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=DDdkYKxf; 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 4S6hPX1TP0z1yqj for ; Sat, 14 Oct 2023 09:43:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D387385C6D9 for ; Fri, 13 Oct 2023 22:43:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D387385C6D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237022; 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=DDdkYKxfexN5vsKolat1VSRVDvII4Ws+71yf9/QoksWoeOypxw9OAzaUkuu0RqOvf DOPpoacNcdVqB89XhgjETn1z6fDxd1kgBnvLU1VYiQpHfpKVPkOjQbk/yCT8oRgs2x RW5ZpmVqJDGs6VQWK1fXz6N2ITu4iLy2SjkfKWPI= 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 1D7233857725; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D7233857725 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236997; cv=none; b=fyT+bICMmIb1SFFKkaIYKdKiwAlKTyNZOTtQF4Jpqm45xL1C1D/fE0uEcdF7lhJrD04kmxFoeGYzLbGV81L1hk3y2GWJBwGT3e79M2NZG78dh0oCs8ltEPsc8T0wHVytGhKaqkxAEWM2b/1bCLp/3cisI9yf9N2p1yZL0pCBmNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236997; c=relaxed/simple; bh=vHI02GzVWW7SZ1SaoXTatpzigzV+rRMb+vomEf99kE4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=v2hYuJTjJQYaOuVztsv0AeRCgZy7tnT1mL99lPRbCz368zMoNBv9YL7au8G/pY+nwRfb9cM/eSkaKWv8akeKAROQksd9zfLGiEHPnROJWk5/9lxz6wuyW09fFRdefR5yLgh1odwS7ORggmXjTm6S4XZZoByvbzaKf3NFAFiBroU= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D7233857725 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 39DMOew4028987; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Pj001569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1f016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 28/40] libstdc++: Optimize remove_pointer trait performance Date: Fri, 13 Oct 2023 15:37:42 -0700 Message-ID: <20231013223957.1634024-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lyBJYGM3_IKAI4DnVsoE-3_B_NsF2xwu X-Proofpoint-GUID: lyBJYGM3_IKAI4DnVsoE-3_B_NsF2xwu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=544 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848718 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=hZrHNiBh; 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 4S6hhX3VLNz1yqj for ; Sat, 14 Oct 2023 09:56:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79E8E385700C for ; Fri, 13 Oct 2023 22:56:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79E8E385700C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237802; bh=EVJ9kreNFo7nGznrJ7E7uGFZi9YprPq8mLOXjF0MpZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hZrHNiBhI28YB7+Vx33UeArU8D4sd59diOjJQDhf7xDqF3MZQOTfUUCyCQ0m2smIP 7mcm90ZHP3JP1PxvmuVKum7tfwtuHhByxUtVtZDFrer+B1FAXcjUlYOB82D2ORNOUH iQlreSWfxojOoAcU8vMQrTscoWfE2vkO8jizTIvE= 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 02697385624F; Fri, 13 Oct 2023 22:43:22 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02697385624F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237018; cv=none; b=cYjbvi1GSNT631ly+vi5bLFZbO2eM6vL4ceQgWMLh4hHcPdXTQ3fOiOMWrNIxKwDMiRrXSfH7iuBirQ7MbMJxnGcx8XZiTtno4vCmfvJDx6tJT5kn3grr9yRW4mfY0uXj7UzTS5ENnQXKJ96+l5XNtSqQUIC2Du6G7FAKOCDIY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237018; c=relaxed/simple; bh=JtzlHXI4pYeWX7a/62xfVB5JJROmVV/h5dLE82v9Y8Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mUqBLps14w1O7hW8pOylz/LElro3omcoBkr9Tyb1pS0cgYloSooU62eI1lD64yYv3H7jEKjwAqTlTqmSwex3aMh5CqDL0dkEEJ1g73Co+1wsBuAzCdz4wzyinBNnr+iGVmRDYUguvKDJf8HHytK6pQ98YG44MDQgfNla2T31D84= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02697385624F 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 39DMO6dC012574; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2cT001614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1g016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 29/40] c++: Implement __is_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:43 -0700 Message-ID: <20231013223957.1634024-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pe7iDUPfHWFD4PlsBmqlXXl_pZpvWXi3 X-Proofpoint-ORIG-GUID: pe7iDUPfHWFD4PlsBmqlXXl_pZpvWXi3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=786 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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. 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 ++++++++ 7 files changed, 141 insertions(+), 77 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 99a7e7247ce..c9d627fa782 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2add97ae749..c60724e869e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 8fbd67788d5..5d40e04f91c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false +"__is_pointer", CPTK_IS_POINTER, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ad2c2a2d250..ab783b161c7 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, - 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, - 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, - 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, + 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, + 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, + 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,78 +116,78 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 57, + TOTAL_KEYWORDS = 58, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -205,23 +205,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_array", CPTK_IS_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, @@ -236,22 +240,19 @@ cp_trait_lookup::find (const char *str, size_t len) #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, - 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, - -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, - 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 56 + -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, + 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, + -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, + 57 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 168411f6700..83ed674b9d4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12412,6 +12415,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcab0599d1a..efce04fd09d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); From patchwork Fri Oct 13 22:37: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: 1848705 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=qW+8FfxT; 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 4S6hYT01SQz1ypX for ; Sat, 14 Oct 2023 09:50:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01C413860763 for ; Fri, 13 Oct 2023 22:50:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01C413860763 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237435; bh=drDSkwF2b66LppQZo7mvO/N7JkJbD5f+nFqDwGJeobc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qW+8FfxTVCplzxgD7Dv2OtEcS7OWXR2peivHOqZ+50SAh++pPUx+YiUB0MpL0dmBR daoeMCKWcB17wQcnGx1oJdrTG/QEV5KNWRsOEIM428Rz+ZZr7BjSEVwIaCZjvEbIOf U8rHqnvqgp+eDLipsy50negZBIbCqsvrIMyR9lFQ= 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 92DC83856956; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92DC83856956 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; cv=none; b=YscOqHoCBZpuw/8Ii1b6wyXfgGWxA9rGFWYOort+leelO7lI4zlfU12Ef3fuaZTPtm8wND5LhM5DkZwkewCr6aySiwevN91NPHSQ9SwQHzX/hMEKsvE4ygInZAqqofTI4tdXoAyaSdSj4cpzRqG8GYgxaqiYqHZgxN5yBi125B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; c=relaxed/simple; bh=BfhYt/j2VRJjuMIYFbFyeiniSUdXiuS4K54TRYwyHXs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Wxoe7Evu7Tfl/+BEsmyt/n6cHURItTbsfNti0wuGTYH7zQNLZDWSurSrC20+CBXsXYe/QZdeAe2H07IhIc7at53F2si21e5gXGPCTKW1k6eM7FQMk/D4HbXCIcJAm1vDcHfPTePO/xL1aoQ64rI/NHTBgjZ8U1PPbM1klwKmeiI= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92DC83856956 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 39DMdxA0011122; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfg9v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2fW003502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1h016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 30/40] libstdc++: Optimize is_pointer trait performance Date: Fri, 13 Oct 2023 15:37:44 -0700 Message-ID: <20231013223957.1634024-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wsWAwSHK3l4JbU-GDRllQAT0S8V_YAXL X-Proofpoint-ORIG-GUID: wsWAwSHK3l4JbU-GDRllQAT0S8V_YAXL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=486 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..cd5ce45951f 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_pointer : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_pointer { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 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 Fri Oct 13 22:37: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: 1848696 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=XrRsG5Op; 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 4S6hTz5YWWz1yq3 for ; Sat, 14 Oct 2023 09:47:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C23FA385E02A for ; Fri, 13 Oct 2023 22:47:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C23FA385E02A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237253; bh=zsCGf51BpLy+ZfS3NOkl9r5HeKT3mprpbJUZjo/kKH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XrRsG5OpCO+m5SrvsECxoETulwS8c3FLl3C+Ap4wCVSakKhIcTyiDeyXsN09OFrjv TFmOgK6K5I2sRMrUMbkk+AnAJuUaw+AXUepK4C+LU1KVKHckwuD8YheoL0dAxtW+lC 3NX3MheKAktiT6h1pJJAKtNCHEU/06NeOON6o760= 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 0CD02385771C; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0CD02385771C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=G3dBORcYKD92rcsqHC9l8YgwgcGN/8oaBeFeA8ObqT+WWvkudmPHVQ3H04jevdAX4arE/dugv4owdANdtxKlW+1L2WO7vb9EuFmRPamdkKpNYMguKmjQV3e9EH/gytqX5Ojl9hIRse5FnSfUQvA7IltZxqPOxqkoa84oeCYA3So= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=8YIFuUboBC8SvXVm1jt6NYeF2dY9CF8Y3S+k1xc+who=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=be/H2D7Jfnc3jKXR1mCBSe9fK94nKwcpnyLWja0w+8YfwgCxrJtJJ+NpyK5UfKEB9ibzOgssXpnj5uWI9v1f2hY9HPKkkNS3YuX4l6tG4Pq/PJ3SMVFZZXyoaKSUTovAV6985ZC1zdzUyeAhWtU5r/UMnE+G6Or7t+3anJOjov0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CD02385771C 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 39DMdvag028132; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2JY021613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1i016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 31/40] c++: Implement __is_arithmetic built-in trait Date: Fri, 13 Oct 2023 15:37:45 -0700 Message-ID: <20231013223957.1634024-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0QOZFQ7SBfeB4tqrVfQ-GIN_ldPCRr7t X-Proofpoint-GUID: 0QOZFQ7SBfeB4tqrVfQ-GIN_ldPCRr7t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=972 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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. 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 ++++ 7 files changed, 138 insertions(+), 91 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9d627fa782..3a7f968eae8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c60724e869e..b2be7b7bbd7 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5d40e04f91c..9050c36f105 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ab783b161c7..31fd5075f2d 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 97, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, - 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, - 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, - 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, + 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, + 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, + 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104 }; unsigned int hval = len; @@ -116,130 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 58, + TOTAL_KEYWORDS = 59, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 103 }; static const struct cp_trait wordlist[] = { -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false} }; @@ -247,12 +249,12 @@ cp_trait_lookup::find (const char *str, size_t len) { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, - 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, - -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, - 57 + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, + 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, + 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, + -1, -1, 57, -1, -1, 58 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 83ed674b9d4..deab0134509 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARITHMETIC: + return ARITHMETIC_TYPE_P (type1); + case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848710 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=mmtKQK+d; 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 4S6hbz2rfqz1ypX for ; Sat, 14 Oct 2023 09:52:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B1CB385350E for ; Fri, 13 Oct 2023 22:52:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B1CB385350E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237565; 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=mmtKQK+d+Lv8PIbPabTfAYkDydmbgq1fkKgYcoRfs20Jpm9nxsfU5DC5UtrM/uAvP QagnARA1Bo3wGojHuzQS/6wvaPmy+5lUpw6Z/avDxImWg1qDLgSPgJ3lyF4bjG0HSb c6NlBfbb8NpZxDAIafPEKh0BkkkqE12KZW2rezLc= 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 5D9B33856969; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D9B33856969 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; cv=none; b=BCA81mMIIlYZGofu1yLg4fyKOjlI3zkm9k3KBGQ4sRUCiXssIkkCFqbti4exCX1nS9QnTY21K6PE2vJzJ2e8ao9lc88L7HMTWMogoDdTDqEpVCCZeRI52DRGRv+AXyXTFbhz3Aggi6W551lHinH9K5Z7V7xwrYGkGcP/bI8GGD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; c=relaxed/simple; bh=axxlZKKPGB8wuYsjw8SAimjjV9ZTlh7UjEpqEksZVtQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DpHkzDXP+UkBSgyzebq7vt2A/d7cAlZlwUqLn4mNlkhOoCSE1+EjYioBO3vWlQlqhbKAdQeaPdfNIl/BmwYi++pGW/HcUrmYIN83zoSYkcOAgF0gMDJ2XcU03yEGamTYCIoLnxpQUs7dWevw4lx5Rjn+kLDhMnlzzz9Qg1BVOPw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D9B33856969 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXSNZ029268; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2xb008053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1j016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 32/40] libstdc++: Optimize is_arithmetic trait performance Date: Fri, 13 Oct 2023 15:37:46 -0700 Message-ID: <20231013223957.1634024-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: agyfHrdoMJYfNDSVe1ae_pHXIPe6STMe X-Proofpoint-GUID: agyfHrdoMJYfNDSVe1ae_pHXIPe6STMe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=666 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 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 Fri Oct 13 22:37: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: 1848708 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=pl/rQuwZ; 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 4S6hZj1sp1z1ypX for ; Sat, 14 Oct 2023 09:51:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37C66385C6FD for ; Fri, 13 Oct 2023 22:51:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37C66385C6FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237499; 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=pl/rQuwZcB7cmeJMWvFZIifYEL2wPRZMyyc6znhFTHHX7JaE7TWTl1ZSsbpReqVwh WLvoYH/g/4ylJ9/w3NbcA/2W1QRAkTy4Xidz66KJDeE9NxHnjVMEtf2Tgmvv0rx15U 5Gglkbrt1oYpUHdu3zUj0prngH5tuEyGzph3I/wg= 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 2927B3856964; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2927B3856964 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=xmyvtAtxesi3HMcYErnAyGLs/xJtgn5VmkzaAjDkP/4yEsznssqlsIotOImwIIW0Kq2l2LIlNyVW/htwQBcxXrbpuENz0wYeTveB91ISYWu97qxDZJsX3SUJA+lKS2wwyII2D09acmyyg5o+eCycbXW9XfHXHb0JAZ5MX3wCLmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=VMehu4HE7BzN624OVO4Fw+NnsTWTfYiByT3bQXMD4Js=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PvLWz1Tz2YhXD3zXI8VDwmpwRGSCUw+W7BBr+g4JW7pu7M87WGJ/J1i+zVPhfCjpYksEAD2pJeH2RHsa2QUn4MbO6CH/Lr9R21Wz5vfeJet+rj1gqwml0qpsdsQRkBx+336q3CdJPi8qLY8lPjEnDGHem8HKxih2Rd9fs4Kfy84= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2927B3856964 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 39DMh0aO001171; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2e9008054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1k016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 33/40] libstdc++: Optimize is_fundamental trait performance Date: Fri, 13 Oct 2023 15:37:47 -0700 Message-ID: <20231013223957.1634024-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 4LF9fYgV63lwI7nvBLaRJGH0VeI2Rbhs X-Proofpoint-GUID: 4LF9fYgV63lwI7nvBLaRJGH0VeI2Rbhs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=656 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+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 Fri Oct 13 22:37: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: 1848714 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=dgyr1m0Z; 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 4S6hfL4s49z1ypX for ; Sat, 14 Oct 2023 09:54:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1F49385770B for ; Fri, 13 Oct 2023 22:54:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1F49385770B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237688; 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=dgyr1m0ZJSSncQ8Lob/k4YjUEnuIHpu3ZeJs2G0ssJ5bUAdVFmes7vT+zY6UgxAgP 64XzcFzErH2UAu0/77y+EVVWSOm+peF2anLjwM4P+72QdQ6MIxWKH1YLyv0RPIhZOi yErLB8PitqJFZZWXir2tvayoUtdTcNYGtazZk5gY= 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 8FA8F385C303; Fri, 13 Oct 2023 22:43:22 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8FA8F385C303 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=Wkq7f+qyz1akgj2TgWgCUpqfZQGBF8kHEpzphr7hUz9/fJz6Ikh4n8jwX2lrPtdCtpRyb4ybjy4eEsSMFYrC7jE1wELi6BdnRgFt8S1zMo8LjrcPVudrjLxdxmrJzMPosAk/OmDmVy+ET+d+CWa6XdZnIGg97N4Qv2W0JOxWJuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=oaOZvY943DFsKkUU3T+LqLGilkqxFzx+Qlt1BfE8jdQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uP3YO7njphLQtRgi9FsgXTBtRjC/C9a5HGZZr5x1SnhgRKkxnN4qaAJyg1CF2Wc20t/XF2REaqmgLcPbLIeROsbOX5ktuNj6B+mOas6F8II1qDbCCs04KbwKnbkiTC9ceJCTMJq6DA0LNibVk6FUyp4fxb5cIbc1jzWvDr4Hakw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FA8F385C303 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 39DMhM4G016990; Fri, 13 Oct 2023 22:43: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 3tqdeu8ttv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Zs001570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -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 39DMdx1l016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 34/40] libstdc++: Optimize is_compound trait performance Date: Fri, 13 Oct 2023 15:37:48 -0700 Message-ID: <20231013223957.1634024-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: KSeuGorZXu6hUdK_zUx1ZltPzT5ebfxl X-Proofpoint-ORIG-GUID: KSeuGorZXu6hUdK_zUx1ZltPzT5ebfxl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=475 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 Fri Oct 13 22:37: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: 1848704 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=pFeWGFtN; 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 4S6hYP5dk3z1ypX for ; Sat, 14 Oct 2023 09:50:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C788B386D617 for ; Fri, 13 Oct 2023 22:50:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C788B386D617 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237431; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pFeWGFtNu7ZFdLBQx4A9B2wesSbN2AuTqAn0hmsYUcEv0Tn+hPBacjiJNpPmUgMaH dLqHDaE4UIcKDWfUMElesJxM0EURZI+R1yE/+A76+Fv9XOSXySeXgtjwTkX9qmCv9u VtNeLy81aaaNx8Hg/s1MJL8SN8QbProVB+5H7HLc= 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 16367385B515; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16367385B515 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=EJYDpvK0SA19q1WAjn+B1qWltS7FAJiQfedVBAo8lHzw9nJ6CdHlkCQLT1VVPEcaawqASqzPvxJu72/3YkISeO5Jc9wzYA9Q4gD/y+CDxKK90Ha5T2ScbrxyYcVK+sUBHRunbkqAVNvqS8LLmKQXfzve0nIoA4NCFMfUsSHHfKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=Lgb7wPNnMiIQRjEmMRx6vIFR149IoCrg8hydCryUerg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OBKkb+yadoLGita8a+rczgCwnVL2SG9iCdFbvepeZVebqg+sjFENa7WGGwdzHL/AJQyy75tHN5MG+VQoG3Es5yRlgOjMyUzxPwbvXvZ70gSPU8joaV1qwuyjDERUC4ZN64b07pSwrff/1C1Y9MdKbfPJoT7qJPbjAVQdtVDBgK0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16367385B515 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 39DMgwW6018439; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbgdj195-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Lm001616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1m016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 35/40] c++: Implement __is_unsigned built-in trait Date: Fri, 13 Oct 2023 15:37:49 -0700 Message-ID: <20231013223957.1634024-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ynKdYZ3m-4IBb6pP7CFSnmSbV4QJTQHU X-Proofpoint-ORIG-GUID: ynKdYZ3m-4IBb6pP7CFSnmSbV4QJTQHU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 malwarescore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=739 lowpriorityscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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 9050c36f105..90d05bca5c1 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -74,6 +74,7 @@ struct cp_trait { "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_unsigned", CPTK_IS_UNSIGNED, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 31fd5075f2d..75ab2b5edfa 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 97, duplicates = 0 */ +/* maximum key range = 129, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, - 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, - 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, - 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104 + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, + 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, + 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, + 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136 }; unsigned int hval = len; @@ -116,46 +116,44 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 59, + TOTAL_KEYWORDS = 60, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 103 + MAX_HASH_VALUE = 135 }; static const struct cp_trait wordlist[] = { -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 86 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, @@ -165,11 +163,11 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -180,7 +178,7 @@ cp_trait_lookup::find (const char *str, size_t len) #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, #line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -207,6 +205,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" @@ -223,8 +223,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 70 "../../gcc/cp/cp-trait.gperf" @@ -242,19 +242,23 @@ cp_trait_lookup::find (const char *str, size_t len) #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, - 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, - 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, + 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, + 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58 + -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index deab0134509..14387821b85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12250,6 +12250,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_IS_VOLATILE: return CP_TYPE_VOLATILE_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4bc85f4babb..3d380f94b06 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..2bb45d209a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848683 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=ebFpQ7AC; 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 4S6hPX4Hwdz1yqk for ; Sat, 14 Oct 2023 09:43:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50C5F3856DF1 for ; Fri, 13 Oct 2023 22:43:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50C5F3856DF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237022; 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=ebFpQ7ACQ1thSurTIQ4gUWI2BpBGQn/Bfhu5tvp87OICgv+EXw6S1DSUydWCBsdeN J6qLJnZIW3dSv4ktVhQG1OQyli1JU1q7I1lNXH+JfQWzn6YPVeQcULG+YTttCQ8jDU MXRaIOqG2ujza1zkN5RHmqX8gMLtBAMycWOO5je0= 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 082643857707; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 082643857707 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=dBcJ4w74Ru6b4grNZ/e6QHmlUItJqL6l0kGsvOABmibdCM9dXMarpV2VdgQCgjQ6F8VUIzRu/tfXdxW74wxCBXe/zLxfDz1ngaOkTBufKeKsqYx7yx4Io5jMpW7ewbw42daOnRAkeH5c6B1awwJNpblJvH1edGrSZlSO7D3mZ+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=OO6VSbfKobcguq/wZw63boKixhRizHhk1hfPeW9ER2I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LI5ZoqnPWpabXmG//js6xsGZvjKMTU3RgxxTLcaG20gOmy7gc5xBLv2hhQObaZstfcdxer0eWtxs05LU0mbyj4h+0b/NXcaXDbqNUF2NyKEYQlWDkv6SvueO2HyGZBrWMRNaESXuVmr6uzyVhaZC8sQPfXn8oTuxoSONF6tGoh0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 082643857707 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 39DMZOWX011530; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Z8012759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1n016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 36/40] libstdc++: Optimize is_unsigned trait performance Date: Fri, 13 Oct 2023 15:37:50 -0700 Message-ID: <20231013223957.1634024-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: o4VyTW-wXhb2XZMHgJHQio2wJbR1XoVa X-Proofpoint-GUID: o4VyTW-wXhb2XZMHgJHQio2wJbR1XoVa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=750 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848712 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=Vrmtpx2k; 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 4S6hd42zDkz1ypX for ; Sat, 14 Oct 2023 09:53:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 548D03853523 for ; Fri, 13 Oct 2023 22:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 548D03853523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237622; bh=VFV1FjvPw5MG2C0PVVDdB7G4ONd1IAwh+EchNoWGrqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Vrmtpx2kw5yppH+b1IBBWZ8vt05X+wIgJan0Zh5iH+vFKd1FIKFCvHO2MfsM5DHaS rDQGZBcHos5z4qM76t7pcVkoX+/XJPO2O/9V2YAc9VT3jPH+NswJZKE6o4u91PcZim tMa/f/FSWT3WNyYn3yJySaSR7jc13YgxhoIQxGJE= 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 52CC0385734F; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52CC0385734F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237009; cv=none; b=i7YPItLpwRLbjSAZgdUGY9bjXd05Aleb2Nmo0hrHSZClndizxPD+swvQM6LDTxdxOTkyzZ6GwD+G0oRWCKze6jA1isSPbxY25F3e8y6SxUaNHnnfK/fxpERYRIeUlocAldnXxFsDLH6XqhXBG4asXKDMNUFGsksRAI9pwgl3Zps= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237009; c=relaxed/simple; bh=kq1u3jMRGoU3/Ev+UFDFUiHgq/Ix7yUbsxOmOQHFY6o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cP78mUnI9FYxd6A0ZF/ft/taUP2JPCYxKi6ZjObrQkIIv/6CmU2GqO9e4oQbzMrjwQWrmDHW1IatHgTOZIm49ZXACVevzVxiE1CG4Vvps6bsOtzvY/xrwkjOYJDyZW301LiLyCIOOEag1pMOnqFtCAFWiApuqigWdydN6sz2c5c= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52CC0385734F 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 39DMapkk025263; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05vfe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh311008057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1o016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -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 v19 37/40] c++: Implement __is_signed built-in trait Date: Fri, 13 Oct 2023 15:37:51 -0700 Message-ID: <20231013223957.1634024-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bBvh0JBbLgtV4RCU0AnH2KPD3FUoNpEb X-Proofpoint-ORIG-GUID: bBvh0JBbLgtV4RCU0AnH2KPD3FUoNpEb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 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_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. 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 +++++ 7 files changed, 165 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28dad702c3..b161c9b2c9e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0603b4a230f..b0faa4c8937 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90d05bca5c1..de0ba162e7a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 75ab2b5edfa..6d1078de2fe 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 129, duplicates = 0 */ +/* maximum key range = 119, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, - 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, - 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, - 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136 + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, + 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, + 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, + 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126 }; unsigned int hval = len; @@ -116,149 +116,150 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 60, + TOTAL_KEYWORDS = 61, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 135 + MAX_HASH_VALUE = 125 }; static const struct cp_trait wordlist[] = { -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 83 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_signed", CPTK_IS_SIGNED, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 36 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 37 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, - 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, - -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 + 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, + 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, + -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, + -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, + -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, + -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 14387821b85..5e6b2ca37ac 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); From patchwork Fri Oct 13 22:37: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: 1848685 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=UV+l3Bny; 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 4S6hQP1ZQTz1yqj for ; Sat, 14 Oct 2023 09:44:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3735B385B512 for ; Fri, 13 Oct 2023 22:44:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3735B385B512 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237067; 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=UV+l3BnyxzQhpxBxrhmRDMyHL3xbrriJjYbpwmUSmgBe747v3wGVjKFD+NCE0DNI1 xHwzqO5We5Vi/6wdgXA6bVFjgAT0p3YN96wVgLHusy7zsjdf9ENUpSXlbsQU6gaXKu e2dA7ctKXsbaPhAhR+ZzOr8nQh2+LKC1PJv3zCHU= 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 B856E3858439; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B856E3858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=DOqVqT0stR3V6AR+XTACeSjLzbK3Pre1p0YWkkuRCk23O9Diup58V4jgLTshooyMpTbvVLCBDFXs0cF76+utgt1Uih5pO5hUhw6V1aPz5z4B1XIu7SQRhFWsUt2123D14JOrtFcRkS/XcTMEVBT2nBs0PiDkRAm7kpf2/7QS+IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=fm6aTmzL/u+DvSJqIIKZX3rAVzVD2tqarjJM/UYhTyo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GIzmFNWeZklON7nEmG3TjoCl+iiwhuHOgpIczDRAXAZGysf3ap4FDao+xUXsyjNEzyXQ/ZnDPA7Ib4o3vSdp5vmbr+xPJxFcSZF4TIBrNCEmcp0VGoAfRTR5B/2OdJh+sitzAfqyWtOYgsltatrYd+uJufPwpvi8Or5qRExPmXQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B856E3858439 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 39DMXSpH014551; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh3kW021625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1p016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -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 v19 38/40] libstdc++: Optimize is_signed trait performance Date: Fri, 13 Oct 2023 15:37:52 -0700 Message-ID: <20231013223957.1634024-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: i2t82heX8u9BemQANbz4FSvbadS3gbco X-Proofpoint-GUID: i2t82heX8u9BemQANbz4FSvbadS3gbco X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=732 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 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 Fri Oct 13 22:37: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: 1848686 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=Xk7khnAO; 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 4S6hQn2L0Hz1yqj for ; Sat, 14 Oct 2023 09:44:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5776138560B9 for ; Fri, 13 Oct 2023 22:44:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5776138560B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237087; bh=EU6QwlroNYbuozq9y4oD1NN+xP2fyRjkyDiKNsypsB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Xk7khnAOgXFK+29GjvM+sReg4icK9cFwFqKKSTK3NZQqUS0ns3/9iNJgIA6uxBuGh vK9QcyQ8cRgndP2Fu5ZPqdobPVhiMhhgbiUiQQAvevPcIbK9tMJ/LkVKetfmThWJpA npf+/BA+pK7X0KuoaJRLgmqDmAU19fOb/rK+rRpQ= 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 355A3385703F; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 355A3385703F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; cv=none; b=bEmhJ7FaMtuBV4okeKjmAJATX9OQP5LZYu0bHG0T+Gr5ac6NZz80IvdtYSPMwCiQEkopfv6xMxJqyFEr63DemhLsXUv6rZpU2sOQwOTW7I9btWURdZU1q2mGjQQVlwomGXWi8JS0MR4N9/uKCv4M9k/YKDwlL+Sev2/fwmq9EdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; c=relaxed/simple; bh=RDSBV+PCBbsB8fHtDmG3mZJHO58uwQaWOfg/TlDTAgo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IFiZgOFCv7gWaDovn9H8dFJBN4/Wzmnpttk3YUnVDhCFJkON7OK6MGdT8x4x/3lpx6xLvicmZoG9ogsTK1NkXmlTfI4oRuWEuYl3fZYucBtgkOPJoguospgoFDulBpQQSH10HGMKT0ElBbvuju5sD3q2fFltLoH7z3Qo+rQCgek= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 355A3385703F 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 39DMh0aM001171; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh3sT003504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1q016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -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 v19 39/40] c++: Implement __is_scalar built-in trait Date: Fri, 13 Oct 2023 15:37:53 -0700 Message-ID: <20231013223957.1634024-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: oGFzPsYERIl3lEF4TVBvgr-Sg3imCMoC X-Proofpoint-GUID: oGFzPsYERIl3lEF4TVBvgr-Sg3imCMoC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=909 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.6 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. 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. 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 ++++ 7 files changed, 137 insertions(+), 92 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b161c9b2c9e..78f100d2745 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SIGNED: inform (loc, " %qT is not a signed type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b0faa4c8937..08a2780c929 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index de0ba162e7a..ef51c713c58 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scalar", CPTK_IS_SCALAR, 1, false "__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 6d1078de2fe..8c68af420f9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -78,10 +78,10 @@ cp_trait_lookup::hash (const char *str, size_t len) 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, - 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, - 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, - 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 40, 126, 25, 21, 50, + 0, 0, 30, 10, 126, 0, 126, 126, 25, 5, + 50, 0, 61, 126, 10, 10, 5, 0, 15, 126, + 126, 5, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 61, + TOTAL_KEYWORDS = 62, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,141 +125,143 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 84 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 89 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 68 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_signed", CPTK_IS_SIGNED, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 33 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 32 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_scalar", CPTK_IS_SCALAR, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, - 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, - -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, - -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, - -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, - -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, 6, 7, 8, 9, -1, -1, -1, 10, 11, -1, 12, 13, + 14, 15, 16, 17, -1, 18, -1, 19, 20, 21, 22, 23, 24, 25, + 26, 27, -1, 28, 29, 30, 31, 32, 33, -1, 34, 35, 36, 37, + -1, -1, 38, -1, 39, -1, -1, -1, 40, 41, -1, -1, 42, 43, + 44, 45, -1, 46, 47, 48, -1, -1, 49, 50, 51, 52, -1, -1, + -1, 53, -1, -1, -1, -1, 54, -1, -1, 55, -1, -1, -1, -1, + 56, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, 58, -1, + -1, -1, -1, -1, 59, -1, 60, -1, -1, -1, -1, -1, -1, 61 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5e6b2ca37ac..be345f9aa47 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_SIGNED: return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; @@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); From patchwork Fri Oct 13 22:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 1848711 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=X8ZILYLR; 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 4S6hcV0k0qz1ypX for ; Sat, 14 Oct 2023 09:53:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F0AE385C301 for ; Fri, 13 Oct 2023 22:53:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F0AE385C301 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237590; 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=X8ZILYLRNQpGhzyfdVEus5SPLdf8tg+L0JKbOhfecSpbL/wqliiVR0/rarTbA69V7 pRfNPTJzREISE3I0k8Gj3Ku1LY/+5PL7p/qkMcA7UUe5QiQO/mBueQxDsPY5Xmzqoe KyZtTwkoObmfLLSjFVXzIu7/XleV4C4vavVAbwv4= 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 B39F83856975; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B39F83856975 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; cv=none; b=oVclhfOxC5ND6bWklLL3g0TM2CjuZ1SpdVVbo5/azVxYj9I4VL/hmX+zwoCUDS6xUyEZDf4C7gevVAnQQc9JGPQsDstfExpGMBcHxSAf/h70b0OnuG/MktYuvf8A8NcEoJ8bGBEXW2r0w4OZ3kFdDqNuDVm1wf4VLF89OKYEqGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; c=relaxed/simple; bh=yZDHLGphd8jxjnk42PZPq1zND4PhrwWhUcJ7anaWSLE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LDFZ0t7y/HgFSUKbpgh9d7UHeLoHhymB6T1/bSD/O+vOa9jrRhLFd8FhgN4xN03okdoS0USWYHD9U2362EjWh+m3KUbZvADhsicg04DRaZBHlCIT2mT7gf8Cwivkv/L/rZjmQr4iC4kANRjLum3fafFWIOjK74Tgi7oVmp9HpsM= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B39F83856975 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 39DMgb9m003205; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh38D001617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -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 39DMdx1r016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -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 v19 40/40] libstdc++: Optimize is_scalar trait performance Date: Fri, 13 Oct 2023 15:37:54 -0700 Message-ID: <20231013223957.1634024-41-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0c1_DTiq1cewC3nRqHC_9mwJFqpECQft X-Proofpoint-GUID: 0c1_DTiq1cewC3nRqHC_9mwJFqpECQft X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=551 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+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>;