From patchwork Thu Sep 14 06:42: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: 139388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp168970vqi; Thu, 14 Sep 2023 00:21:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbfqhv0cZuReJpV4hk8HZO9/5WJORANwzT20eKk1TuO8+eKLSIEGsGktMqDDNeXeLEL4Kw X-Received: by 2002:a17:906:76d3:b0:9a1:abae:8d30 with SMTP id q19-20020a17090676d300b009a1abae8d30mr4046711ejn.47.1694676118329; Thu, 14 Sep 2023 00:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676118; cv=none; d=google.com; s=arc-20160816; b=FhT0rLKBvL+ZZG8RQfP18OLFOB6Pc12L++CL6cTGuav+iMpqZLGjZV2nlyr4th71uL k7pIwccffVvNQbpTXafPJs9K/9U0HifvCVgWYWfqJVDqmbpJBovygAX536f25dionYfB admJyfv84gXlouOvzK8H5a6Bvq84/NlAsLJ7FH40xdHxzXKFaT910d1oeG8tnfduha6a hHsmjAzfRg0z4pFjksmnlLGvN3/c/UCFfEuGDHdBd5fMxsuMVEx9Rjn+zdYXqPVRsdk0 jMvhTMfTadqmNAqMmZjkwO2VtyH5ODA2HMk//2P/XrOAQmsPXMrCyrp1oX1jp5TBDGyt yXyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=KDuQRNGN19hKw9KCN4x3zgp5kaW9F5LEgHkSJdwG4Sc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=RDzcVdimKDNENCnEdAAJ4jlXRjcG6VTpL5j2xT6M9lWLt/OsOdxCYgJyi/d0DM9+Nj sZE9mgMpVXsMznp8p3blvl9I/BLVw6SPUPUbtaDLJMFi/WylGnY3ERCHdfRTslD/Cz8D lBabiFEjafF8MYd1Da98cJch9rbvv4U1M8KripPWUOgtrlKIo2SV2LFJVRj2L3Oop8Sx PW1cAw44JQ1X8xRfbs9oA0xrlrVtO/4C2ipXtfjfba9yDHroXDprjpNPLsahae5SaUoB uAKtv1clsftB5OnD1uf+x/bi3BujABKRAdV9ymUbnK9bS61mzxGQ2XSAWXwBglumozHe PqhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Pmgm52TG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fy26-20020a170906b7da00b0099bcb3ad50csi736960ejb.504.2023.09.14.00.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:21:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Pmgm52TG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9CD63923E63 for ; Thu, 14 Sep 2023 07:01:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9CD63923E63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674888; bh=KDuQRNGN19hKw9KCN4x3zgp5kaW9F5LEgHkSJdwG4Sc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Pmgm52TG+5zLblLhgRaJc8htBLdJTxkLeC4BaafUDOlsAJA93Wuii/PNbAAb1mKaA SK3cASv58iHyP1z97dz9OXvWxqp3wmb3Fhye+5uiWpsTgL78CRoDTpUbfVcsw5Y3Eg 0MINpOranaL3aeBQqDm1SHrI3G98rEtEdzAXr+bY= 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 97062385781F; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97062385781F 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 38E6mT8k015362; Thu, 14 Sep 2023 06:51: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 3t3jx7v1ce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6opTV006958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupO027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 01/40] c++: Sort built-in identifiers alphabetically Date: Wed, 13 Sep 2023 23:42:40 -0700 Message-ID: <20230914064949.29787-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mVLjXN0_Fz94rU3uJa8JKH3r-kaqSVE7 X-Proofpoint-GUID: mVLjXN0_Fz94rU3uJa8JKH3r-kaqSVE7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 malwarescore=0 impostorscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996705538360058 X-GMAIL-MSGID: 1776996705538360058 This patch sorts built-in identifiers alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in identifiers alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in identifiers alphabetically. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 68 +++++++++---------- gcc/cp/cp-trait.def | 10 +-- gcc/cp/semantics.cc | 86 ++++++++++++------------ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 70 +++++++++---------- 4 files changed, 117 insertions(+), 117 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..ce3733df641 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 0f7f4e87ae4..7d0240edcc0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12075,15 +12075,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) @@ -12092,17 +12083,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. */ @@ -12116,18 +12116,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) @@ -12136,6 +12139,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); @@ -12151,6 +12160,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); @@ -12181,24 +12199,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); @@ -12357,8 +12357,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: @@ -12421,25 +12421,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 Thu Sep 14 06:42: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: 139386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp167765vqi; Thu, 14 Sep 2023 00:19:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERMjoICqmNVx+Ix88aYflpatPIFUSWhgUMK1pPdNxN61JuxHDzDJPnI6C7oVaP5Sb5D9cu X-Received: by 2002:a2e:b0ee:0:b0:2bc:da4a:4649 with SMTP id h14-20020a2eb0ee000000b002bcda4a4649mr4119858ljl.22.1694675946660; Thu, 14 Sep 2023 00:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675946; cv=none; d=google.com; s=arc-20160816; b=QwqaxZ0Iq3NenA8j7SzyESJuyHWWHeZvqvtGzQuc6gDNBn77P9vIzxm7e0GnvY2Hjo s4fwvIo9a/i7yQdG2X1393TkXtrL/IartJPvRzAB70lApmYPeFrAIvj+mf0Pmo7eOcy+ tnuGQdQ5xfHPicMEayIV51HxgFW/udENKPUMVNrJ0HTkwRqQd0p+AS86S8x3PWM2KZ0M YbBPH422p40mMjj/+wFY0hQY9sFNnh0VnFl0ovhJMYkNAyN5EO9UXxBoItuHtuM/uzZn WSjcZ6qqAGCHaG+Pg6btf8bYb+2q6szPTt4UEwy2n5zdrgcbhW0Xshf31zJHCWhPIyEF j7KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=Hs5SN/nNkgRi6jAwTTJrxf8W5Hy53KJZKw3rdNs3nxc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cLsaSlKOiPv76Y35JZT9cbYycDsRx0q/4tS1AvhD684oautQSiP3PBCvOx0NTZv934 GYksZ9zQ7X9p63tjrXjI8STJwi89mW0rFNkH7zS0pEEYudl15aNWlp3C73hTXTyJIJkV nu9+2m8n/BWiBxWioyAEfy8HWavz8+R25RRxD/9r4Eq3fqmE61hEa4OlvAChg38+tH7j ivl6KR9IVDNVNiZbYc7bT54ukvIUIz2I9AZzxhXh2wEas+nw1f9SthfRkVTWvSpa7eS/ ETSNeySDkFd9Zukm+hj83KpvnsUXDX73i4c1sVHlBgiiKYI74uJhHcHVKBsZRbUGKql3 4D6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DNjaRvGL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id by8-20020a170906a2c800b0098d85fee2e2si737072ejb.608.2023.09.14.00.19.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:19:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DNjaRvGL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71897392B3D6 for ; Thu, 14 Sep 2023 07:00:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71897392B3D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674836; bh=Hs5SN/nNkgRi6jAwTTJrxf8W5Hy53KJZKw3rdNs3nxc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DNjaRvGL1YkPhK/v6PCbTS9JkftQ/KfDVR5jc4w0e3YS4pr/b/+hSgyHEVVbhqBi3 5vRBw3R3ZnUuGeZ0w2/BGgR9JBQ2HXloNA0Y7EHqSxwOJTYrTVlkICnwJRmPB4LR6i mcaucd3BSlT4VLzf1agfxsgmDBqIFD5idtLhiPL8= 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 11746385842A; Thu, 14 Sep 2023 06:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11746385842A 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 38E6OmC2005215; Thu, 14 Sep 2023 06:51:11 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n8djeqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6ops5020551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupP027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 02/40] c++: Implement __is_const built-in trait Date: Wed, 13 Sep 2023 23:42:41 -0700 Message-ID: <20230914064949.29787-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: cU4hi64TTxGO2qYJ7c9b3YTJXlPghCf6 X-Proofpoint-GUID: cU4hi64TTxGO2qYJ7c9b3YTJXlPghCf6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_03,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 bulkscore=0 mlxlogscore=935 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1776996525378678276 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * cp-trait.def: Define __is_const. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_const.C | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 ce3733df641..a4ebfd9f319 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7d0240edcc0..baeda9f03e9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12139,6 +12139,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); @@ -12356,6 +12359,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 Thu Sep 14 06:42: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: 139363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp159019vqi; Wed, 13 Sep 2023 23:59:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4OLKOmRHAULX7/waRlBcrVQugw9fUoPrB4ZcezV5J24OlTqEDZ6t965DDSQGOKloJqwkQ X-Received: by 2002:aa7:df8b:0:b0:523:bb8a:8dca with SMTP id b11-20020aa7df8b000000b00523bb8a8dcamr4219227edy.16.1694674762535; Wed, 13 Sep 2023 23:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674762; cv=none; d=google.com; s=arc-20160816; b=U8VPMSXQGK7c9qDAMxZgak2Ff3S4VRBBbMD3nbInUeYFqgt21hmnHJFCer0QCYuePa a2fDkr6cdQpZ0zj7mywLwE1N6vRUpODZZpbaOtcgUb7vVxr6XxYwTuj+iFwQP9Rd6LBO LqnlH4DTU/iximNDFpGfwpSfljv7me2Nrzg2N2vtr9qDT3KuNJDi143KsXCxskPlqbGQ ZoWc+7Ago2d0yKqLxwe5/masWlaIujjEYeguAx3xGg3n/LruYa8E4YpXY+W1J8jLFqs/ 8ZPhYbZqUJfomQk9iPAQIQqk9K/utsVug2Z5rc7+8HmWLeYrdp8mLwbafEL6Q5mV5AxE nPSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TNLJvagWTZXAgNvx8U/p5DRBX96tUvz6QoIvqr3Du1BMS97pCvVbCTR/gHhfGnG75n H58/o3gmzCETIwAze0MTAaBhlX78gMxY1inYEEDtqIJ7TtWb2INY+w8uN6KQihOXnW+t E1qWuZzpHCTXc/jO2PsKIBiSogIWr9r7N1Cf9EyO/QNKv5VJfnvZ4J1SmYMTarKLLlmg RuOmr6Iwv5P/5Mb3O29coMn25K6cCZU8klORMSpPJyNhnulpDEF2hniESFMq9S9cRu2S lC3YfuZ7nhClYevYNzNqp5hXv6pkCJN9I2zwenpGYUfKCdIxWdGB0PS+ftSKI/cQHQTI X1iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R3enG7RC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j6-20020aa7ca46000000b005257e010883si780479edt.527.2023.09.13.23.59.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R3enG7RC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71FC438AA247 for ; Thu, 14 Sep 2023 06:54:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71FC438AA247 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674453; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=R3enG7RC/2D7CdhXrUWPVdJhYCZKkhuU+Fv5zgNsZwKc/4PED3sgDrebuDRWJaOED PDg7KRsW0wUmPh3JoHiM4ygabSWylbW4fXMvGSrLYZPA6EChDPe5H1uxZPceUNUp0v QY9lU0KTkHCLxKYa5U+22SsddVXf/60Edo5WvKoQ= 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 34E163857738; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34E163857738 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 38E6oIL6019709; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3jx7v1bm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6op6o004220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupQ027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 03/40] libstdc++: Optimize is_const trait performance Date: Wed, 13 Sep 2023 23:42:42 -0700 Message-ID: <20230914064949.29787-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: AEtIeyF3pHKcIpi96Y9_SYbyEM3U5n6j X-Proofpoint-GUID: AEtIeyF3pHKcIpi96Y9_SYbyEM3U5n6j X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 malwarescore=0 impostorscore=0 mlxlogscore=842 adultscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995283749276021 X-GMAIL-MSGID: 1776995283749276021 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 Thu Sep 14 06:42: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: 139390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp170245vqi; Thu, 14 Sep 2023 00:25:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjy9vHsy3WTXH3ETFxkhMKvdOwxaZryqQioiB2RxRFJl/WakryQi7EN9GDWUlup+buidv7 X-Received: by 2002:a05:6512:401c:b0:500:9031:bb1b with SMTP id br28-20020a056512401c00b005009031bb1bmr4724459lfb.41.1694676320276; Thu, 14 Sep 2023 00:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676320; cv=none; d=google.com; s=arc-20160816; b=UDlOcZGUmx8ddrISucEPp/MtG93U8NKLHo0ockpIvRe/J7reQOJl/62UQhPRtm9ZNS olwKph47Agwv84KrQa4LaQNkqTU6PfhzU83g5L3rwXCZKNGR0ZSmzZjEffVHQWC2mI3D k1MSJnGSga09jUs5gjv0PkcqJGukVebpdusqwI8n2p1PAViE/ICPqez8nZPjHqtGLuxF HrBAERU5rMxrdZ69gxW1xtO8OUpGdm16DyUl6954LkLdbkO3hdXT/M/1tSmNXkLLjhEX ccwiGxl2O452VrDuCMC4/mBEHyPnZvaf1RHGXUFGLowtNyFuRnY/48GYg8rXNoyeAEvU vR4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=KvAgdxRJOeKFyWZridzxWp3UZ5cTW3wECgTi9hzoAZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Y3U1nDcK1NtVNU6iGEotDB/CEnhEkrAgOrpxtZXhbSsqOW2twuEcz+/SqOIJiOWD5T kf39vnO6VudUEFGJ7wSB8oZygRDuAh3Dj5T1cPG2IXjEEbhL/BU+OG3dtm/ejRIBBcWk vAit3zuSu9DAQtH6HKCTfOGTVtgv/+ERj5NvExTrZytRn2C/uJer9okmi9CxOKYFCJxC Q07bOFZTr2pwDC6KD2ViNnaDSOQ5lo4gvAdiYa7WvhaP52yGdtJFFGvt30Gm9FTZyjos OLO2sJOiWD7QFA5IOfm+Y6f+0va8IgyAd3n0nxLxwA4cmd3LmDhK804tQRQdlaY2qxk/ TyCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="NY4/xFCr"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d4-20020aa7c1c4000000b00525b948f961si801714edp.291.2023.09.14.00.25.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:25:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="NY4/xFCr"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 770FC394B6A8 for ; Thu, 14 Sep 2023 07:02:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 770FC394B6A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674956; bh=KvAgdxRJOeKFyWZridzxWp3UZ5cTW3wECgTi9hzoAZU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NY4/xFCrXEYeLu+hgQXJh1NLEkd7rPK4IzbqPaV50hlY2M1D1j1N8CgiyYAjUfarb fuiIym1Ggc0K8eN2lqeanvwDih/0Fw1wNV2UE9qw1rD1m5BSai4NUQitm0m9vfki98 sGDwpilqQR9NF+xOQP49S/3aFRFFwrldemsIdofE= 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 54AA0385C6E2; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54AA0385C6E2 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 38E6oKgw018463; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3mfbaw72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6opBP026243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupR027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 04/40] c++: Implement __is_volatile built-in trait Date: Wed, 13 Sep 2023 23:42:43 -0700 Message-ID: <20230914064949.29787-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 4Ja35AglEAPvlrCnxFwTCThHgr4a4Frh X-Proofpoint-ORIG-GUID: 4Ja35AglEAPvlrCnxFwTCThHgr4a4Frh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=784 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996916785922643 X-GMAIL-MSGID: 1776996916785922643 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. * g++.dg/ext/is_volatile.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_volatile.C | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 a4ebfd9f319..60462cd9874 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index baeda9f03e9..18390f530ee 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12202,6 +12202,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); @@ -12363,6 +12366,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 Thu Sep 14 06:42: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: 139394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp171321vqi; Thu, 14 Sep 2023 00:28:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJuYXnovTnBHC74S2IImVNofJra9SrvzoAT/cJymjtnC1UORzD8tjhrb/ETJFYYvDNLXr5 X-Received: by 2002:a17:907:763a:b0:9a1:b98a:c723 with SMTP id jy26-20020a170907763a00b009a1b98ac723mr3787087ejc.4.1694676490480; Thu, 14 Sep 2023 00:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676490; cv=none; d=google.com; s=arc-20160816; b=ITjST1WFKAze57UpBTUOMwIZFusPoIVxkpPki2G+4eztvcjR9Mgsk5YgzMxeICHxUu Fp4OyRl0XpEHnXVrUmj4j3aiVevhKyR8YT38O1MO6GEGaXk9ii2q9F/1xJg7CuDiribx uwendUqO7NGACo8BWjw1Ee3EVCBV2xNR7f1KUnYM4Pm0Qv65besSvwHdF+D1Hy0WsCLD 6zuDr+H+HSldI9DWxrV2oSdiZgQaxbVfaWNgSbF2XWaP+GqTcmv7Kx6slQNR4l2uHdOn aTsp7cbM0ODd5okBFrofephKBNreWc9roTrzX0oIhDHbLNdcGGvcy5UBeeF0OQUhWB/b KfCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=NYRJp+xktHO6PjAOArWFAabjLncbCTrOyV/zyMyZMACvzD+bsQ/sb6L43kkE038tyN 4togz6Uj8vB66SwTCWCV2tXH8fWLK476sUmdv+qQ0rv6g9B/W8iVzmWZP4JS2XzUJKGC 0xSAV5PN24NgS2fh9wMZe/I+2TN+NB0z+BQiUNkwy3df3/lm6Sa+nHBUjm3jrJJAaa3+ yblstZkTMCDq9mJuHmKrBfbLEAOczUqdagTSSONk5lZUduYYSiA+qqk3amBa7IkYGt0a 2MKWzQu1yFwJwLpAR1hjuWR5mZuVMCNQu6z+TcCz6+y674UJ1wootczLq9n2GiuraBRE hbxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LhVDLZUN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v8-20020a1709060b4800b009ad80078e76si809381ejg.793.2023.09.14.00.28.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LhVDLZUN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEE6738E7C2C for ; Thu, 14 Sep 2023 07:03:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEE6738E7C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675023; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LhVDLZUNGHsDIpk5PZhfjrsBknybb04qhJpKFQ5G3+ob1n59DYN1Sp+IWTTwc00CD hE6P11xwK2HiWDalIxlUhqjTqNOa+ikW5ChZwm4TEtnhrtgJ+YIrHij2vL1TOPms5p cHGlGt9yrW90DljCztoUoJJ1Mh1hd7LZJCB+Aklc= 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 EFF76385696B; Thu, 14 Sep 2023 06:51:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFF76385696B 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 38E6mVs6015374; Thu, 14 Sep 2023 06:51:24 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3jx7v1cr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:24 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6op5m029078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupS027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 05/40] libstdc++: Optimize is_volatile trait performance Date: Wed, 13 Sep 2023 23:42:44 -0700 Message-ID: <20230914064949.29787-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: vmDcCGI1Z5Q26CY5pwXoxhZfHJI_8AsA X-Proofpoint-GUID: vmDcCGI1Z5Q26CY5pwXoxhZfHJI_8AsA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 malwarescore=0 impostorscore=0 mlxlogscore=888 adultscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997095680917896 X-GMAIL-MSGID: 1776997095680917896 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 Thu Sep 14 06:42: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: 139399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp172829vqi; Thu, 14 Sep 2023 00:31:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqqgcF5n0VemFyyaPixgV5ElYugPMq+VRV2kAU0i/0NUpjpDp2NaAcqlBxS6IE6REuVn9S X-Received: by 2002:aa7:cd19:0:b0:523:364b:e6a9 with SMTP id b25-20020aa7cd19000000b00523364be6a9mr4127075edw.38.1694676715601; Thu, 14 Sep 2023 00:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676715; cv=none; d=google.com; s=arc-20160816; b=MkAu+7Bgt2yBVAjwE6/ffwkNbKQiEte/gsgfRoTUPpL/ZjKxppisftRXBlWgecz+QG UVrweKqsKVdd82oRVB8UJoMtnmnrelqfrffkj2U8RVzEjciu9RvTY4B5UNo2QczHsZBa 91DURrMdrbZS6o8ycc+UH+CEV+m7SJw70wcv5Dub7DqRnhK6Ot8uheLYVH+y9Bod6DAG 3TaWgAuJlG+CgM0EhQzVwHohNlTzUUpSFMRIen5qDQRSOCKO4jTJon8Z5LpOACcLEt89 Lu7Sg/q3bCmZlv1CxvvYy+VgW6aJW74XZlKTT72mQTgW5BCEUfA5AlBx0BOpB90oNxab pc8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=cjMHMlroh9iNEQStmTYwZ20OlQtjFSDk5+OsWz7lCMo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=GiWaCWi2vKvEsP781eYexxJ52Mre7zDD6mMiiYPmSeaASFjlXi6saEzl2JFMsEsdU0 zUtKc3tn3zHT55IDYeriTqAn4yNuVqOVOHglmLyTdUkGz0krpqpGh5+48akb6L+MGvXO ivV61e3V5+aHmgHUTDZqP3dVh/uRS3JDEHIFmEHKqrFgtH09HiGT1F1Rn1WJIEsYZr6a VpTMiuMoMVegkpZLOKzNtEB7HR9BMPpO8Lyb37VjUd4nkMyMd69gBNva0bfNxytRZKV7 7qc/jB00iIXGgUi0UPhHe1oQ1UZQBf7gBIlMa2dVPZqfHHryjGOFKsE1QriLSwmRWFRq UeuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OY89hVVe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x19-20020aa7dad3000000b005283c8d6619si838547eds.355.2023.09.14.00.31.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OY89hVVe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A0ED396D802 for ; Thu, 14 Sep 2023 07:06:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A0ED396D802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675169; bh=cjMHMlroh9iNEQStmTYwZ20OlQtjFSDk5+OsWz7lCMo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OY89hVVetJ7xjn2zSNsl3kfTbBONnnYN4d3iRAniO/wPdEc10YH8c/rgwRnwc1lcA 1pZkbpXnEff6JfkTbFBDXMosW53Evt5ngZNqGx3i9RCsP0d2gvqwR8QueOLWps3LkP FXO0l8pgNKqGYjjM6fVhCcqeBxuVTMg5OI359Y00= 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 5ECE9385C6EF; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5ECE9385C6EF 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 38E6mlbP015521; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3jx7v1cn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6opMT026244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupT027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 06/40] c++: Implement __is_array built-in trait Date: Wed, 13 Sep 2023 23:42:45 -0700 Message-ID: <20230914064949.29787-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: hF8TjTYaXOY_U93ySRoIpnyk7iZRYWOk X-Proofpoint-GUID: hF8TjTYaXOY_U93ySRoIpnyk7iZRYWOk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxscore=0 clxscore=1034 malwarescore=0 impostorscore=0 mlxlogscore=708 adultscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1776997331947317165 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_array.C | 28 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 60462cd9874..c9106242bc8 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 18390f530ee..562b0bb8438 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12128,6 +12128,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); @@ -12361,6 +12364,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 Thu Sep 14 06:42: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: 139397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp172320vqi; Thu, 14 Sep 2023 00:30:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaFsbUOSl83hSugqYSJ6uw8MEEXx4KB7i7ohIMUKiElVAO4vNV0LNw7J3UsrsPeDXvflt/ X-Received: by 2002:a17:906:55:b0:9a1:fbfb:4d11 with SMTP id 21-20020a170906005500b009a1fbfb4d11mr4217337ejg.73.1694676650512; Thu, 14 Sep 2023 00:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676650; cv=none; d=google.com; s=arc-20160816; b=nQ6XnA4q8aEHDs1sxtlWw/prMvtnMmo7zpl5Cl3ju87kLyKoJ1eir0lyTvQ0P31mPL KhoasvG+bRA1I3IqE72I/Osp1Dre1OZBqA4EellptuWb5Y2RuEMmuAlaDFmro1Re7oDD rELpJVkzn2jyYlzw93Dugit4Hi4VbPKHBQoNpp2HY7jt8rCZfy3yfBS//cmV21kQ+vvE a+RjnkwfTGVOWsD0834Dn0SDLQgt30A+LkiHZ5WOY9P4KWjw8f/wqjyfWtypFId2MJrr h0aSAkxivZQ/ONOdjPLBOHD60PzwBO+iiOf6aXjFxAlDdzsovoQGiIZgGta1NHaiI8fd V+0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=nl78XCYE04tR3Q6/Axl6KiGHz8iE8/3VPNTM4RRtwUGQe2UrsHSBZiRxsW/wOEjsHp u8ptg7HE5tBjGzltUlO09eL6L0E304y4f91g2yAt/KfRBGFG01ofqyG8zZvigfLjlmlx ByTt5K9u6jb/D6WtNH+r6T8n6xBMANPfuVCvTL97ZAv4zpwWtatxegiiC06lAR+jsMHe bx3riMrFrklG/bnVCP4CywkyCmr8UkteyQiqfgrVYNtr+EjHPBFNiq0S5DwkjPrfXQCp dYqQFtC/ruwGBnUjKwZcrWb/1UVJxLUonkW5+AAJM+gftCsvAZtFv6hRgya93/p0GZ7J s4gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UabXhuTm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i26-20020a1709064eda00b009ad8da45ed7si791561ejv.861.2023.09.14.00.30.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:30:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UabXhuTm; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DB7F3951900 for ; Thu, 14 Sep 2023 07:05:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DB7F3951900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675119; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=UabXhuTm6jdtzZgQpmEPEfmzy1bX0q9fbUtWxv+yBC5o3qi24X79hQhQVXHnG7S+t iV3/FupxN1BpfMyH+sOxXQnR2Vg0RyQjEgIlrLvMjoTQlO0eLtQWoiUbxIhY6LlhtX qJLOzts1/ukRnpqs9F290g+pj7EhrYbVZQ0I3z5c= 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 07039385696F; Thu, 14 Sep 2023 06:51:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07039385696F 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 38E6oKgx018463; Thu, 14 Sep 2023 06:51:24 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3mfbaw78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:24 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6op0X029079 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupU027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 07/40] libstdc++: Optimize is_array trait performance Date: Wed, 13 Sep 2023 23:42:46 -0700 Message-ID: <20230914064949.29787-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: GAX6RUI2U6XuvemIlUQ25AZr5xlQOR2_ X-Proofpoint-ORIG-GUID: GAX6RUI2U6XuvemIlUQ25AZr5xlQOR2_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=603 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997263374731491 X-GMAIL-MSGID: 1776997263374731491 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 Thu Sep 14 06:42: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: 139393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp171315vqi; Thu, 14 Sep 2023 00:28:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzZGzjLbgZUhD0ozJKDqsYsoDAjXKWCbdxNmFj/0cA6H+wxISIDoa0CHccfNiJ8ogalA7/ X-Received: by 2002:a05:6402:510:b0:526:e585:e25a with SMTP id m16-20020a056402051000b00526e585e25amr4401981edv.38.1694676489603; Thu, 14 Sep 2023 00:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676489; cv=none; d=google.com; s=arc-20160816; b=r+FMm3i7QXGYEKWu3Alc4cJeiCeaOG5wg3K/yyKozD6H/cwIw6w7NE+fE3GJn5PN8r XRqDpe5DqNhkHbh2FwISw0TNX/4V8HTx5DIMW/X9EoQFZvoQKVK0crefG/f9WUgnAeuU LE6ESq19LC4gAuMqTOB76CVHSPW5wxFHjEYM8n3VA7qWjANJcJqCQtXF73oV1NdvWDI8 hFJ8TtndTtxJoHoiT34kWzbs5IS2wSE071vRASxbt7SfkhfQRTzuN1Ci5WfYFxskV6WV KmDaj3k7AXFOuLyKZLW6mkLFAL+FV4RBXrhJCTDBRtoIuyWIln0OmV973kvnWVbu0ACt aBqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=jOXzlr2Ep2ZtGwonbgdiyMZldA34yPfQBHS4QrwXwn8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Vs2K9Dih8v1P80DPltbVQwQsqeAcjmvyupd9eZhO20phOc7GfCzOR6pXew8X8SqIGK 2E/mNwCA2RYbhjLq8tWh0Eho8k+b4557AeLMbNpr6kTIZ+rjvhGkNv9E62bYqDuC9xaz FLnYxLjKmUUILCm3Gc4WzwxzWTJmA6JFHaUFn9ZTRtiq9b8aru8gmiieVonf339vovih JZ9hC8TyKQBVMxqOcW516gVkDUNNUCuoiY6HtrqIhnnY4b/BKFzXSBKSWHQtEs89IeFl ndaTBCKYBwT2q6UuHXx7PAnm5rTbnR30qB99szSn4FBrDdDE26AwQcCcNsgJVYVa50CI uuWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hSQVK4WO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j17-20020aa7c0d1000000b0052faa7f8cd9si755732edp.148.2023.09.14.00.28.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hSQVK4WO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81D743980A9F for ; Thu, 14 Sep 2023 07:03:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81D743980A9F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675023; bh=jOXzlr2Ep2ZtGwonbgdiyMZldA34yPfQBHS4QrwXwn8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hSQVK4WOptBUOX3hk42NbI3RREswQOUTZ3iC6NEzr6EmMB1im35uwkSodxS49KJHX QNskUaoWGHBx+PL8vCklog9A28cWxcB6DywgkDbasZz8S4+gDi7BdTc8keHcRGByHj CptF7z76JRBbCXLUpcN4wnnA5XBXiKsowE1jh+qI= 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 88D95385E021; Thu, 14 Sep 2023 06:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88D95385E021 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 38E6kMGG009453; Thu, 14 Sep 2023 06:51:15 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwagj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6opHG032283 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:51 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupV027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 08/40] c++: Implement __is_unbounded_array built-in trait Date: Wed, 13 Sep 2023 23:42:47 -0700 Message-ID: <20230914064949.29787-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fXQ7cwEbbGV_t3AnrVvhu-T_HbuvwV9f X-Proofpoint-ORIG-GUID: fXQ7cwEbbGV_t3AnrVvhu-T_HbuvwV9f X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=596 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997094718165190 X-GMAIL-MSGID: 1776997094718165190 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 c9106242bc8..1e67a3d2089 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 562b0bb8438..4fdec0c30c1 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12202,6 +12202,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; @@ -12369,6 +12372,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 Thu Sep 14 06:42: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: 139389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp169649vqi; Thu, 14 Sep 2023 00:23:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHZJSQKst1+Lx9QOq7COR9gN/528MoHNsCgAExcjVSnpV4uEjuBSwfPkI5gXVDG6G7JyiM X-Received: by 2002:a17:906:197:b0:99e:39d:4fa7 with SMTP id 23-20020a170906019700b0099e039d4fa7mr4158796ejb.22.1694676225592; Thu, 14 Sep 2023 00:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676225; cv=none; d=google.com; s=arc-20160816; b=wpiqUtrrJV3RwkqiJxGIDUAVHuzGrMojK7tM+bGZ1vfVWKARjsxmKA7zWrtErzYvAg YibI37/gwoEaOqbbwG7eSqavWLgKYOuFytQ5gFq6hhJ0K92APEye0Zah9VEZ+oBQvzzk +L4Fkf/zXc25CHuTxd5QrKAd+8/P5btGA3t9jAaCPXdjn2iUc9a8motXgNLzqNC6ynEr 0bBVYA6qEQx73UlVks3YpALWcjmtpymWfm4Z0law/fqcpQod7CGBmRuTWMiDhJ+RiJwz lV+KqYEGwjftqORQinXJPVtkMPb0Q7f5XwyqzUBBGompSI8YGuAgtkORGbHKZ9Awo0JJ RA3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=eoczI2XqoPcrWaXhexOO3DQqqy0ZUr62gZ0cAMckUS78vllJiB8OL1uixLXqmEVqDQ hBDUWWq+OpY5uojESKZCHvpHuuA3Yp85W3n7+x9Zg0XIM3vWaSc0RQO9oEq3jYQK+API gzu07MOuwRRshLbeFtA+Qt+K90s5ALQTrPNWyEytXMmAV272AD2qtuFJ3hQs4Mijztni zaqHIQbtpeVv/rcqNUGbG6e7FjzhEVUFiM5Y1cep8eS4KYdT3dYRNmZWrAFqMmI57JK9 Z/pRuycC2ozCLCcl1CS0c4OVkc3ogvlSuiS3bpV0H+owxnm8nVVT5q4WbE9Nt9oF0vQQ Ov0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AbvGshxC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t25-20020a1709064f1900b0099cd74ad42fsi807389eju.106.2023.09.14.00.23.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:23:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AbvGshxC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 095273A4EA99 for ; Thu, 14 Sep 2023 07:02:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 095273A4EA99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674921; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=AbvGshxCSJ/kLN2u87Wq2wLE7mJuGvIBk1wNFw953jLIqx4Ly/0vSKGBsIN1r0c6J VrAaWV5Tj6Qxnom8rHBoWpfJNie1vmyO+hO2HPenxuwEygky2K468SjT9qUQIIMvwF K38fqI4j+WrKpMUYN/3l9MhDQyo5A2huhCKk3tP0= 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 697513855581; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 697513855581 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 38E6lECg010648; Thu, 14 Sep 2023 06:51: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 3t3p4h9yxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6opGi006960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupW027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 09/40] libstdc++: Optimize is_unbounded_array trait performance Date: Wed, 13 Sep 2023 23:42:48 -0700 Message-ID: <20230914064949.29787-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _hM4KkUBdM2rMJ6z76RPHdZTc_gw64TU X-Proofpoint-GUID: _hM4KkUBdM2rMJ6z76RPHdZTc_gw64TU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_03,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=625 impostorscore=0 suspectscore=0 clxscore=1034 phishscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996817880022434 X-GMAIL-MSGID: 1776996817880022434 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 Thu Sep 14 06:42: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: 139379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp166295vqi; Thu, 14 Sep 2023 00:15:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqsg9cACbApB5bnVfUyVHQBxWJ/QjNKAXiGs1s4DsQh/5FK+xKiTlRvUJd/wIKJ7ps7JzE X-Received: by 2002:a17:906:10cd:b0:9a5:c5fe:af85 with SMTP id v13-20020a17090610cd00b009a5c5feaf85mr4276160ejv.3.1694675711574; Thu, 14 Sep 2023 00:15:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675711; cv=none; d=google.com; s=arc-20160816; b=TTFoqMbGMHUVNISoCXumPe7kC+pB9U2W1Int6BVA5qtWPzEwSvF/ASeHXWB8l26DtJ r4wnOpAAKHscpSMid/9IOpajCBuQKGtGx/wZD5GzNXH+6xihI6XMW25j6v0TF4LBt8gU lGojRcNdPuACoY28YLJxT/7nAYt5XU85G9XSdwlDaVF4Jn8wMxQj1MjhrmACpSrgUni9 FJkGksG8iQOYSoZf/4SGw9iy3I2BBUyw6Zdp8PzxVwoTaPlVgdZJ28KgKZiwao3YnQpJ ALTyqvY/b5LDeVf5khbKlwq5pNpOUsNRsAAIm8WPQaTjZ7iVxa+vSJhj7PyF+8v7G5mI lTAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=uLf5qqneGaZsUvQ4+/wHn3p4R7fZ4hmx0bPoc3q8UFc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lKWJt8RcqXSAAsf15q9vJo1Bne+F4weYKWKy1pUqil3f6BAqUwzTAdB7qBXt0kWTP1 JtI0btgMVdEyly8KTR6vfYQRkDlQJnBweul9THO/QQfu/N/56ERTsSPhIVnTGU7+7m0K 6Z50258k5lIQhtjo3RhKsq87lGPXGODBGZt0OpVjT7KTvLrqmTg+kaVAHp2JRIdbZ20f iEKjIAL4t3Tisp/57sY9LMIXzkui0GoTKH7Oyj7ej7/TNPsDwR7cwZFt06ojkjKSUoaI Eh66axL155VpjRgJBSuBUMqVeVWvJH7QgFLdppDdEPZYFTgYlaXHseEGJ7v2xpS01DP2 q7LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ILeiB6B8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g10-20020a1709063b0a00b009a198078c54si736280ejf.628.2023.09.14.00.15.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:15:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ILeiB6B8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C6B838A9090 for ; Thu, 14 Sep 2023 06:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C6B838A9090 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674755; bh=uLf5qqneGaZsUvQ4+/wHn3p4R7fZ4hmx0bPoc3q8UFc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ILeiB6B8OWiTvF8lhZSoSuXUr7LZLD3NkGB4RQbKD+fp0o+nzqKWWVGAAk4VCB9pj gnqhBXDu/HiTbBwkzRPqSiEiQFu7EaEYw2y3mb3JlZYkAmiDqzjGLepOrc4DejzOY+ ln851Y8nCSf4LbGCMtomaBF5yIcMVq/tijlo6y6k= 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 7CC803856DE2; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CC803856DE2 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 38E6mxTW012835; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3ner2b8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqmL004226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupX027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:51 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 10/40] c++: Implement __is_bounded_array built-in trait Date: Wed, 13 Sep 2023 23:42:49 -0700 Message-ID: <20230914064949.29787-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yzW-PgKJZpbHKpOVW2JoMHqIDAwoOCVX X-Proofpoint-ORIG-GUID: yzW-PgKJZpbHKpOVW2JoMHqIDAwoOCVX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=646 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1776996279060207258 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_bounded_array.C | 38 +++++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 1e67a3d2089..b6146c010f6 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4fdec0c30c1..bf6438fcfc5 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12139,6 +12139,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); @@ -12368,6 +12371,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 Thu Sep 14 06:42: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: 139391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp170697vqi; Thu, 14 Sep 2023 00:26:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPRwfHF1VG//6+Y0NBJSB5XDBxSeD87qKAAPF05J+8a/WpeZJYbbq+AO3xajx0kbOzQZBT X-Received: by 2002:a17:906:1da2:b0:9a5:ed5b:2418 with SMTP id u2-20020a1709061da200b009a5ed5b2418mr3826183ejh.55.1694676398740; Thu, 14 Sep 2023 00:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676398; cv=none; d=google.com; s=arc-20160816; b=jG5e7DjonaG0v6K1J5E47OssTuwQIbAI1xcWec0C+UlSsnUHik5YvFgSCbwJZPDTN+ fXnpc/zp5he8Toek1PbQTO1kEDmgmEiTa2NZ906RGhQ7Esl3vd/gCHrkV3gQLBJwXL6U AbJuy1/cWfwIgjTc9ikLU9MvwqWgqC1BRprUbAbV7WjLDNWEpe+GmDr4V7galCSeB7NN MdzxEsxjZCo0+FB/t8un/vlbg7cM5Vxxwj2+xZ5oURMb2vt+DnC6gNjVIuAU6IjG2krA 2+GtBKNHYF/DILismiy70x7E+n76vsH29spTxNq3OImPofG2f5bfEmd4JnfGvQ3AU2Mh 3pSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=V/y6cFbG+Wb5WRu+bYW5C4L5LvG2sj9kZlF3Ap70eeLn3YrcPmXIInxBwcJ0N4CWL8 Ko/1bEeYf2Els0TZprDFW35E10ewtPf6SQj5BuwzMJw/fJfHNSJYElFraeJraXimXbQA BnUNBtw14Mf6Pua3dnqzhE5jvj/QT9MhlzkRj+itHbqD7J/0Pr7H1wr8Oy6P7AM1R/I0 ccKoohNL5ioaRosb1VZLWEntckuhpDFdFBmVlsiZPfPQESg4yCp5j1DkBWrroNQYlhg/ qVoSKd6lqXgof82PHRAeDXAKxjt1AOicAQvdptblMsarBK6HG//HxmhnXCphltyD2K5Z 8XvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=enHGWSlK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g13-20020a1709063b0d00b0099ce147d6b0si798971ejf.823.2023.09.14.00.26.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=enHGWSlK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B52EF38E2FB3 for ; Thu, 14 Sep 2023 07:03:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B52EF38E2FB3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674986; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=enHGWSlKZSwbG5JAnvO0KyhPj0W2KVQs4Q5sT/P0Nvehk0kF+sFJdFpxe6KDACrkQ DhFjSUYHxOmyzi5U2GjQcHT4sfSXtf9MK2fZNEep9bu8FRQHSnDYLLjMZkw9iFbvlR sCWsbVXSrNyG5MGnTe15NosDhOmNEqWZ1znx/Ip4= 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 2E756385C424; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E756385C424 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 38E6pLqB018918; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwagv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqSI026245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupY027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 11/40] libstdc++: Optimize is_bounded_array trait performance Date: Wed, 13 Sep 2023 23:42:50 -0700 Message-ID: <20230914064949.29787-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: T-ag0VWAWEQ_hRmQPfMwZgeAnAJl_Owa X-Proofpoint-ORIG-GUID: T-ag0VWAWEQ_hRmQPfMwZgeAnAJl_Owa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=495 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996999788880715 X-GMAIL-MSGID: 1776996999788880715 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 Thu Sep 14 06:42: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: 139407 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp174417vqi; Thu, 14 Sep 2023 00:35:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGA5A7WdbzF1o35G4aWm35r4xpcT6DcsxP2e5c/ySwz6qy3vPaYE8czPhxjqoPxx1RrDqxy X-Received: by 2002:a50:fc0d:0:b0:523:c19d:a521 with SMTP id i13-20020a50fc0d000000b00523c19da521mr3469134edr.40.1694676953137; Thu, 14 Sep 2023 00:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676953; cv=none; d=google.com; s=arc-20160816; b=WIP2gYo04rO0u8c6pc/6oRSv8T3b+z2+4h3a/f5s0dp6YusXaC9MxnnQlsJl8OUn8Z TMrW5dz+rM9sKjqkpKi9dJrfKNvT8llcZtn7LTdmzUpeImr/w+IE+ccRt8WJkbIbfIL9 o/0b7PU/yoJmrD74Mq+Mo3FglYq+kF5gBTFCOhJR1RPCB4Sq5DzwX6kXLl6pbKllVV8C v43NiFRZS3wpQTi+HVbqbxrEpfCA1OHXQQuBSZuBAHknRxfEUzklzUd+yaeqzSxid/1R BmgW+sqZPJ6n/1ud28yclz7c3e4gQJt0GpWGKALxpYytk6sAtFpuUmpxjygq1+Jr9ErJ aZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=L4fiLrW80i6AixdNZN/UW1V519+OjB5bT9jNCAShrxw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vrJYOuU2Sf9NQJ6sqwYwTWdWqwqak/oRCuxueilab5SggmpwayLz4cHOGoxbYs4LLI Qe2h9+fjkrfu2vjtkiYLOZeG54QzZqIAHsmqBwy4mFrSsBYNRTlzbMCTfrMZ465KZdMn 1j1CDrvx/AlGi/TrOcHqvoS2jve+yIGoccysWZUtRUpScwe+Bu12ETX1HGkhrcGpx1vN 90qbiaAr1hEiNM3KI4GRN24uo6Es5WSvIM+Zkyme3i56c+BmJFg/oL6Vsb037aeG4xsW Dj8pFDsIvfjSQ0Up3R/4EHB2zJYT/IimmP6/RlADbZSQ/bVsKJ32ZJj5MY7jaRsT6Z0e m1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZmpIC4+C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z25-20020aa7d419000000b00522c1367415si814553edq.658.2023.09.14.00.35.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZmpIC4+C; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79B413894C0F for ; Thu, 14 Sep 2023 07:09:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79B413894C0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675373; bh=L4fiLrW80i6AixdNZN/UW1V519+OjB5bT9jNCAShrxw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZmpIC4+C8sai3VkReL07X5/3vcfyOLTdRgkbcqNswTZ/+XeD0CtJjJJwM1vFeH7OD QnoSTdlcMk3zkBMXU8shJrm9NkZu/gCFuDiSrz5AoIjb4Hfuqk+5TP4TJ1vyFZBRWP kYTZvlP/EvPJpGD9EeUIRIR7IYldKeEf+hYhp9F4= 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 2E45F385C6DB; Thu, 14 Sep 2023 06:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E45F385C6DB 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 38E6dCF3027958; Thu, 14 Sep 2023 06:51:24 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3ner2bak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:24 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqEK029081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupZ027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 12/40] c++: Implement __is_scoped_enum built-in trait Date: Wed, 13 Sep 2023 23:42:51 -0700 Message-ID: <20230914064949.29787-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 0QdVMBhuCz2MNrnlRQBmt-itprw_BzKI X-Proofpoint-ORIG-GUID: 0QdVMBhuCz2MNrnlRQBmt-itprw_BzKI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=745 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1776997580847515671 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scoped_enum.C | 67 +++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_scoped_enum.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 b6146c010f6..047307c95ce 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index bf6438fcfc5..7f89616aa03 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12190,6 +12190,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); @@ -12376,6 +12379,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 Thu Sep 14 06:42: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: 139358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp157037vqi; Wed, 13 Sep 2023 23:53:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+IZq0wKTpLwD25M4TY4HpeiH7aPLEsJ622zsvRQ5I3/nM7D/BEh+uA2q3xe0lhSbZcqIw X-Received: by 2002:a05:6402:14da:b0:522:2dcc:afb6 with SMTP id f26-20020a05640214da00b005222dccafb6mr4356457edx.7.1694674396100; Wed, 13 Sep 2023 23:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674396; cv=none; d=google.com; s=arc-20160816; b=WVXSi0wnIsbaQY+W9upa8hxDRlb7gmyvO1eFLaFHd/oqKuPREUBmGbHtVQae5fUnQl NDEvuty7/zq1LiirimV1V9Egevc9WoBTEQrvoEiLzsty+rqbIiV/FP7sEJVZxNJF4M6+ D+NxLlfde6SUwTB+qYHnTS3HbJhj6CxZkKkUSzWkpz8bbvAsG62o4gDECqNBbyh5+bK9 qJk3mpMEnt9Ne+NEkf9ULJzGagPthmkKplAarZK/fkuVCABK+n7Z/T6saSeT1aSioCoE Pz6JjVghRzSwk3hOcsti+0O1+54W29UFoy5/8nYmJWKT5UXZMVuHhMUE0iA6fmZLZfnr nicQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=pxmDdZ0R8Tjj+mCgh3YCmdDnBzBvb34x3zrkdd5MOC0myYe7bbq3UlWXUikcKZPX1w HErmshVqEkThN6/LnqR3l297lM7F+lnwBUwmYV+mkTs9WmCRUSkrfNBeF+iBG8k+mpwj 87COzpWkZraxnf+HvtSdAml7oYDWfEkNi8Suhh/h0jTImJwdFX/l0ESdkNp5i7FtYV9E /ZuyLtwvVsxz8pKBUvefgH+0/pnSGCHpUrMOcs0fdlVz3qeiGSLI4y0hc3vcWYMIFAvv NIKShm6clyx5sxSz76tnJd6MpTO777zDJYvoIJW4USn94mMMZcpUttVlYO1r42hIJMNI dIIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qleYw3DR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d3-20020a50ea83000000b0052fc6ed8003si770484edo.96.2023.09.13.23.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:53:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qleYw3DR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C660388203E for ; Thu, 14 Sep 2023 06:51:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C660388203E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674315; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qleYw3DRBq6me1jTvbBhDbbcGRADMb0iftWe5h2PYgMhoqFWOrg0a4uezOUzDfONc MSNAoROqDZSGIiygOhOO90bvVvsHy29jsHqTSSjedF1xF6Pf8mVIDlcNK2vgdYxS2l Wk+94mRHg0tSeqPt8yOyD2NdT4ryWmXBc8qDlh9s= 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 1B6783858418; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B6783858418 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 38E6mnlC022137; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n5v2gk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oq5d004227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupa027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 13/40] libstdc++: Optimize is_scoped_enum trait performance Date: Wed, 13 Sep 2023 23:42:52 -0700 Message-ID: <20230914064949.29787-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: md5YHuFs1qjvK6RNRlZs3ymNGpujzI0R X-Proofpoint-ORIG-GUID: md5YHuFs1qjvK6RNRlZs3ymNGpujzI0R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=896 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776994899316432234 X-GMAIL-MSGID: 1776994899316432234 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 Thu Sep 14 06:42: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: 139402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp173609vqi; Thu, 14 Sep 2023 00:33:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvroiTZD3hkPtZ87WvUpqfULbX5yStMDubGMz2dg5D1sVg+M3Hi3ssmMiuj94QMvuxTK8Y X-Received: by 2002:a17:907:762f:b0:9a9:d651:68f5 with SMTP id jy15-20020a170907762f00b009a9d65168f5mr3624846ejc.3.1694676820111; Thu, 14 Sep 2023 00:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676820; cv=none; d=google.com; s=arc-20160816; b=gEioPB0NB4bPuow9Y/1TONmLzA+9zC33OSZPUf15KfotAKxuPy5syiWi/OnOEBHZX9 LtYMBX3lAk0rnmQ9Yek6IS6RbCGo0oDxaJ4POzdEdPuu6zbL7DAbblADH/oMD4s5HPT7 BDD7UoYP0veSOj66/9XmMlTw8zRBhL7HjvxA1l66ghGMkY8kbwVtZAowtCI/64pxApKb VkCHAOjy5b77AMoYzX1kVzlFcPYOV6/Q9veRPBXEf0zBg68bHV6Nu/ro3POfY/2g5VKC 4q9uTtBCs1RBbiBZlQnj2ToRh3A8+V1BLT+TNboCgtC2uDAIiXeX67NM93JnX04aXbDv 9/Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ExL+Mkh9nnDfYNMvCtaM/7TbBcXFfQZ8XnImwz1E1Ko=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=DkNfOLgsZS97F/iaykSXUvJhk77h8SvjiJKQIK5wRYxUBoGNP29JbyZsBGE5lE6xpt dLwsv1kEZhANzoUUBWD9FqxDHaKbaIoaNriaahvz5zAGiyOXSOW/9AkHdhk/u/oPijeX HnClPv3IDlaL44ZSx7VDqZPyIqNZjOz34/KC0QMoYVDJQlId7FustF0bpH1t5xroTLBg yiJyZ8M1nK1lczJQRwuGOoEFCSetfh0Dv43cGRTyuu7/hW4Ptjr/RL8xOT8rGHEjzebF emzgtXcxOtSVxYDrDk6ys+XuInXirHFmj5RQinO+Y3Bxb+vhKpy//1scL5KsjXeV7ql0 UZ3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DFPj5OR7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h9-20020a170906718900b009a19f88af95si852347ejk.1042.2023.09.14.00.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DFPj5OR7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A80983830B60 for ; Thu, 14 Sep 2023 07:07:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A80983830B60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675237; bh=ExL+Mkh9nnDfYNMvCtaM/7TbBcXFfQZ8XnImwz1E1Ko=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DFPj5OR7BP20uLvMto7wWm9tkdAYIwJb4UBa04lXlHj4nYu1KeJgSQq4aiM3kqC0i 2GCsax4QxtLxejlsXjT/joI4EeM4X4/f4rg8i7uRim8KZnYR4oFtdHOH7ZU1IVv2TM jf2YHxkYisHsZ1VkT8/zppSQwyxa9jZTwZ6/m/6g= 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 57800385C6EA; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57800385C6EA 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 38E6eCsT032357; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3mfbaw71-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oq53026251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupb027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 14/40] c++: Implement __is_member_pointer built-in trait Date: Wed, 13 Sep 2023 23:42:53 -0700 Message-ID: <20230914064949.29787-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: LbwI_G3G_1WzoPWOpxNnw1H-hQif8Bu0 X-Proofpoint-ORIG-GUID: LbwI_G3G_1WzoPWOpxNnw1H-hQif8Bu0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=724 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1776997441180277793 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_member_pointer.C | 30 ++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 047307c95ce..7fed3483221 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7f89616aa03..84291d660ce 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12169,6 +12169,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); @@ -12378,6 +12381,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 Thu Sep 14 06:42: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: 139381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp166477vqi; Thu, 14 Sep 2023 00:15:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNtH1UQFXKScXF0cCbkaJHhUW8ktfvq+LXt+52FmZrc2KoImUFSr2aVWsglBQbHWn1uNBm X-Received: by 2002:a17:907:77c3:b0:9a2:24c8:4d82 with SMTP id kz3-20020a17090777c300b009a224c84d82mr3919310ejc.64.1694675738395; Thu, 14 Sep 2023 00:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675738; cv=none; d=google.com; s=arc-20160816; b=VyvuUNbvLQplaG5/BBLDrg6LhmCYLFwU8E1g+AkwPpSWV1lQEwRcCU2/B6HX7T9fqf +mWWXIexaLIYi8Tp8UJCmSG0JSbQqS1WnQ3NQajUmvaHskbe6KThBgOcb60oJQFo8PXH fzxorqh8bpIaLZxkuLcPJzkXKV5PMLsC8VtXmNfH5MjrzUAthwwqjNWIwz7Hyc0LZBuC 8wZjCmvdPsHMoG353W5pkkykHfYOVwQhg6/xY3fqRZ4b2ZjniSNSscXZ9mJSOqsv5Okx TsSVFfNSnnL3YZ7fo2mDzlD2XMmGJqmuOKc+nOm6kFAHEG3hPQ2DqqVKeUTc8lcYILym Jfyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cLKXHsaqBWn5LXQ8ve7Z+ojZgxjUXUI4brAsFme+Ev3cqCvg4tTZg/RWQI0PEudRIY TpYmlZ8o8iekBkJeBEYMO97qqgQeWWgYYu8DoJxH5VVr7KWYiAIK1cqH/N7JwDdTTKUK pERBeUnzO0yvchuhdPl+payjnO0I9+CeJ8n1dtST6dHpR8vrOPdMtsJCkBX1IbXqmlMe nuUtH1itj5XHgJx8nrp6+euuj3wtirekHnrWcYUKrnfiJcbwCEq/quHqyABDinNeYtb8 x4cRhlOuUOWsHECBTeYWhnJd3DvMfocon6TYkEkUxDZ3gOopE9XjBiPuR109jTOjXtcL eSdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NIDdnqeT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ss5-20020a170907038500b0099364d9f0e0si696911ejb.540.2023.09.14.00.15.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:15:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NIDdnqeT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C2B73894F6F for ; Thu, 14 Sep 2023 06:59:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C2B73894F6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674764; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NIDdnqeTVJ2+SOqO92s+Mu8BIqOdaXnSMMo+Z8Ebd6HJVnO+CpvJeZL/U2+hI/rSU qamEPZPVTVuntt8dUe2/TAZRYFEmokEDyIFivtoiZ+P3zE4mmpQ+tOumr0ShWUt8Q5 tcpb09F36gSIO4tlAYOGImigjAGBoMyrYkW2dRYs= 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 6A393385C6E0; Thu, 14 Sep 2023 06:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A393385C6E0 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 38E6kk1X027153; Thu, 14 Sep 2023 06:51:15 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n4xahre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oquu032284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupc027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 15/40] libstdc++: Optimize is_member_pointer trait performance Date: Wed, 13 Sep 2023 23:42:54 -0700 Message-ID: <20230914064949.29787-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 8QSRz1X1Ts3MUhNcHXNpbMqWXZ9683cQ X-Proofpoint-ORIG-GUID: 8QSRz1X1Ts3MUhNcHXNpbMqWXZ9683cQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 bulkscore=0 mlxlogscore=456 spamscore=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996307296308519 X-GMAIL-MSGID: 1776996307296308519 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 Thu Sep 14 06:42:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp172010vqi; Thu, 14 Sep 2023 00:30:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsfQTY/vPC+StcX1EKfO940p3LOH1hP0ocx2Jiy0T1wuk3G1IR6rUVleWW9baPPFGk3JJ9 X-Received: by 2002:a05:6512:2394:b0:4f8:71cc:2b6e with SMTP id c20-20020a056512239400b004f871cc2b6emr4796433lfv.33.1694676611319; Thu, 14 Sep 2023 00:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676611; cv=none; d=google.com; s=arc-20160816; b=LPsWe4eJin9PKGtpHZIxrFed6+GKXOeVY0l5/yPrDS6INjy7ItMDcParO0RIdQ3Y8Q 2C6YpYeRuR4abiX5zyi7jSHUpVwr70uhVOhK+ami9Z6Wy5Ig0oZ7lR4I+qjQY8Gj7zLh w1WkULIsKeJULXiXsugaML3Mo5NT9jhBbb442lHyKKzYYKUbpYZLIpe8Uipe43Rv6oRm 5puacveRCH3imFusRRqoomXjRgsbq9VrGeuaDyqJam2D7ToKomObazcjbFdR5WvwpiQ6 lNR9HAx95b35dkVmS0WtsMoFEgk5bVKGPgQcDU/jb+Qo8484C0JNW9tSjxhovSwLjL5c SQ+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=FCLu+mz9+J3/O0l2Rv6Qn826fchOnhHPrSUlDMBpo7Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=w8Z3JTM05gPTfXCw3oBOuhso+9F7+N2BUBuLJS/uUe+P6jGsLTfl5eDvW40z84f2/z l0D4iUKjRpNqoU+bWTbwNcVAC8DfcKIx8lYif6U1updk5Z7HxXcJ2pKlLWoXDq3R24FP Bx66cB3uwb6O4PQgisvF4o6wD1+ikqwSzIsvAUUDchTcsRMFHh8O7oqtqxL3d1ZqUOuY by65gP41JOkN6KUXcZOHwkKyKUOpvQSPnQV3+zofR0nYcVrSCqubaIc9YGt/cLbMMB51 94mCHseIpnuVS/VAnasdVBA0WT3ySKJsEYtYAiEoVH0wRLZkwFm03zr9q8DnzNvOy0aL xqlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pdsLHhmU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d15-20020a056402516f00b0052545f962cbsi916776ede.640.2023.09.14.00.30.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:30:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pdsLHhmU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 272053959E46 for ; Thu, 14 Sep 2023 07:04:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 272053959E46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675095; bh=FCLu+mz9+J3/O0l2Rv6Qn826fchOnhHPrSUlDMBpo7Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pdsLHhmUDgBSctVm5BfHoLWVGsZnojT4c8Zphv3L1jaTHyxbS8gsNqxbCabaZlM+X /g977faI3oV7skdemAdEbRU7HS2N+hx4asmLO043puo/giJvCQwAJ7m6xza/+l+xYO RXsAKD+IYIMniP62Vt7wkXco6BNYFNSmbutvPOXo= 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 A89813856263; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A89813856263 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 38E6dCF2027958; Thu, 14 Sep 2023 06:51: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 3t3ner2ba0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqWD006961 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupd027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 16/40] c, c++: Use 16 bits for all use of enum rid for more keyword space Date: Wed, 13 Sep 2023 23:42:55 -0700 Message-ID: <20230914064949.29787-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: cN3LZI3fYrtMbkoG4JHZQ4NrXasmOzV4 X-Proofpoint-ORIG-GUID: cN3LZI3fYrtMbkoG4JHZQ4NrXasmOzV4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=910 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997222224492547 X-GMAIL-MSGID: 1776997222224492547 Now that RID_MAX has reached 255, we need to update the bit sizes of every use of the enum rid from 8 to 16 to support more keywords. gcc/c-family/ChangeLog: * c-indentation.h (struct token_indent_info): Make keyword 16 bits and move this upward to minimize memory fragmentation. gcc/c/ChangeLog: * c-parser.cc (c_parse_init): Handle RID_MAX not to exceed the max value of 16 bits. * c-parser.h (struct c_token): Make keyword 16 bits and move this upward to minimize memory fragmentation. gcc/cp/ChangeLog: * parser.h (struct cp_token): Make keyword 16 bits and move this upward to minimize memory fragmentation. (struct cp_lexer): Likewise, for saved_keyword. libcpp/ChangeLog: * include/cpplib.h (struct cpp_hashnode): Make rid_code 16 bits. Signed-off-by: Ken Matsui --- gcc/c-family/c-indentation.h | 2 +- gcc/c/c-parser.cc | 6 +++--- gcc/c/c-parser.h | 6 +++--- gcc/cp/parser.h | 8 ++++---- libcpp/include/cpplib.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gcc/c-family/c-indentation.h b/gcc/c-family/c-indentation.h index c0e07bf49f1..1ce8753813a 100644 --- a/gcc/c-family/c-indentation.h +++ b/gcc/c-family/c-indentation.h @@ -25,8 +25,8 @@ along with GCC; see the file COPYING3. If not see struct token_indent_info { location_t location; + ENUM_BITFIELD (rid) keyword : 16; ENUM_BITFIELD (cpp_ttype) type : 8; - ENUM_BITFIELD (rid) keyword : 8; }; /* Extract token information from TOKEN, which ought to either be a diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index b9a1b75ca43..2086f253923 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -115,9 +115,9 @@ c_parse_init (void) tree id; int mask = 0; - /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in - the c_token structure. */ - gcc_assert (RID_MAX <= 255); + /* Make sure RID_MAX hasn't grown past the 16 bits used to hold the keyword + in the c_token structure. */ + gcc_assert (RID_MAX <= 65535); mask |= D_CXXONLY; if (!flag_isoc99) diff --git a/gcc/c/c-parser.h b/gcc/c/c-parser.h index 545f0f4d9eb..eed6deaf0f8 100644 --- a/gcc/c/c-parser.h +++ b/gcc/c/c-parser.h @@ -51,14 +51,14 @@ enum c_id_kind { /* A single C token after string literal concatenation and conversion of preprocessing tokens to tokens. */ struct GTY (()) c_token { + /* If this token is a keyword, this value indicates which keyword. + Otherwise, this value is RID_MAX. */ + ENUM_BITFIELD (rid) keyword : 16; /* The kind of token. */ ENUM_BITFIELD (cpp_ttype) type : 8; /* If this token is a CPP_NAME, this value indicates whether also declared as some kind of type. Otherwise, it is C_ID_NONE. */ ENUM_BITFIELD (c_id_kind) id_kind : 8; - /* If this token is a keyword, this value indicates which keyword. - Otherwise, this value is RID_MAX. */ - ENUM_BITFIELD (rid) keyword : 8; /* If this token is a CPP_PRAGMA, this indicates the pragma that was seen. Otherwise it is PRAGMA_NONE. */ ENUM_BITFIELD (pragma_kind) pragma_kind : 8; diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h index 6cbb9a8e031..3c3c482c6ce 100644 --- a/gcc/cp/parser.h +++ b/gcc/cp/parser.h @@ -40,11 +40,11 @@ struct GTY(()) tree_check { /* A C++ token. */ struct GTY (()) cp_token { - /* The kind of token. */ - enum cpp_ttype type : 8; /* If this token is a keyword, this value indicates which keyword. Otherwise, this value is RID_MAX. */ - enum rid keyword : 8; + enum rid keyword : 16; + /* The kind of token. */ + enum cpp_ttype type : 8; /* Token flags. */ unsigned char flags; /* True if this token is from a context where it is implicitly extern "C" */ @@ -101,8 +101,8 @@ struct GTY (()) cp_lexer { vec GTY ((skip)) saved_tokens; /* Saved pieces of end token we replaced with the eof token. */ + enum rid saved_keyword : 16; enum cpp_ttype saved_type : 8; - enum rid saved_keyword : 8; /* The next lexer in a linked list of lexers. */ struct cp_lexer *next; diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index fcdaf082b09..b93899cd364 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -988,7 +988,7 @@ struct GTY(()) cpp_hashnode { unsigned int directive_index : 7; /* If is_directive, then index into directive table. Otherwise, a NODE_OPERATOR. */ - unsigned int rid_code : 8; /* Rid code - for front ends. */ + unsigned int rid_code : 16; /* Rid code - for front ends. */ unsigned int flags : 9; /* CPP flags. */ ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */ From patchwork Thu Sep 14 06:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp161596vqi; Thu, 14 Sep 2023 00:04:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTyrCeW408mnhWK5ztU7Hy6N3XFYWLxOQHnILosHu8WtaEb7FWBOecsAekOB88FrxiBvJr X-Received: by 2002:a17:906:2929:b0:9ad:7d5c:3d4b with SMTP id v9-20020a170906292900b009ad7d5c3d4bmr3713047ejd.35.1694675059023; Thu, 14 Sep 2023 00:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675059; cv=none; d=google.com; s=arc-20160816; b=VhCRipQJMkt1Ujl3spWjeb5jSZWJkF3uddtfqXUe8QMV/ZyhrYDuSG7Tngafe9BAUc xCA/RO6I8jcWNsFSt3Ja4t4ttZyNUhMt8i884IkDV+MrNxlKW3hazMvv974mBRKw2Xxl zH/g4PUBH8dxTd+x9NwdHMRj7vYPy+0fK6iP+IH3nUN/sCiOtFuOtUBkrVTm3z5x5Jw7 YcQPleNpB1o4nxz9+KJXEe9nbfTNuJZaLmy+fxV5ukhbTVIb7m6nE6Qof1q3TbFbjx0R 0HUJxPAQMg2rY9pOPNYxXaBQhGRyEC1YRn2JwISOySuzcA9DNx/3jhxAzHFaDTWP8Fiy Z2gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=TWD7LPo7kKSv7u0FTAmyPA2YAPTsXGHa8lOzBLlWbg8=; fh=mVK+uW/lWosGIt4Y7BqhrwxmiotWo55P+1ct+GOmHg4=; b=PelX12U0ZcQh823YJQb/JuGKvcdaK9wy0GVYweAbWAWbLhqC3g58f4tL7NNydpJu2j xgp2K6VtP+zpm1cvjjPx6tmlJLzo+Qyn7kpJle/gl3tgmj/M0cOI/KrjpZU8CSTsNwcs PBlYJx3F7VxQKkR6db8Cza33SsVv5regTUdBUS4DaciOY6OMCzMINukSkFQQwPbHtizr 8WWwJXZHPGc2mdkQSh11UziNxzYO0g131pT/w9cwI++Z0YPTnASGewwyr2rnAv6I6aIB hwpXdCEUYMZ2FdzIwIZODZxklo/3YwF+tmC0BYEGEWsSsnarodVNCGy+VuhTCs0cq2nt UR+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oeWdzUL9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w7-20020a170906130700b0099c49a11e74si736232ejb.972.2023.09.14.00.04.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oeWdzUL9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB2B43830B67 for ; Thu, 14 Sep 2023 06:55:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB2B43830B67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674555; bh=TWD7LPo7kKSv7u0FTAmyPA2YAPTsXGHa8lOzBLlWbg8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=oeWdzUL9ZyYftZajmSREJK+YMpZWKiN+z02ZcNAMJrNYZd1UB4TEi1pfrSIeIwweF o6QSI+UcrwiUkuZlKKnqc61biTp2kwBRRCsZR/b7vSE3FSTajfb8PAwNyjnXO/IggZ eOdsbBZHZb77h/AVoV96EWxl6FIrBVMNh3RklY68= 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 296C8385558F; Thu, 14 Sep 2023 06:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 296C8385558F 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 38E6dIe0030173; Thu, 14 Sep 2023 06:51:11 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n8djeqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqTV020554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupe027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Andrew Pinski Subject: [PATCH v11 17/40] c-family: Fix C_SET_RID_CODE to handle 16-bit rid code correctly Date: Wed, 13 Sep 2023 23:42:56 -0700 Message-ID: <20230914064949.29787-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 9AJb5AX5GVn3UruV8ZPOjQi4RSYrfZOH X-Proofpoint-GUID: 9AJb5AX5GVn3UruV8ZPOjQi4RSYrfZOH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_03,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 bulkscore=0 mlxlogscore=942 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995594649497470 X-GMAIL-MSGID: 1776995594649497470 This patch fixes incorrect handling for the new 16-bit rid code. Unsigned char was previously used for the 8-bit rid code, but unsigned short is now required. gcc/c-family/ChangeLog: * c-common.h (C_SET_RID_CODE): Use unsigned short instead of unsigned char. Ref: Initial discussion: https://gcc.gnu.org/pipermail/gcc/2023-September/242460.html Code provided by Andrew: https://gcc.gnu.org/pipermail/gcc/2023-September/242461.html Co-authored-by: Andrew Pinski Signed-off-by: Ken Matsui --- gcc/c-family/c-common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..73bc23fa49f 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -382,7 +382,7 @@ enum c_tree_index #define C_RID_CODE(id) \ ((enum rid) (((struct c_common_identifier *) (id))->node.rid_code)) #define C_SET_RID_CODE(id, code) \ - (((struct c_common_identifier *) (id))->node.rid_code = (unsigned char) code) + (((struct c_common_identifier *) (id))->node.rid_code = (unsigned short) code) /* Identifier part common to the C front ends. Inherits from tree_identifier, despite appearances. */ From patchwork Thu Sep 14 06:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp160731vqi; Thu, 14 Sep 2023 00:02:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgf/np/qKRrm3ps1IfN/ga4/jX/aOY7NgKfNZnwwXx11KRBzaQ6D8fyNAWv70W/KDBSa7Y X-Received: by 2002:aa7:d7c9:0:b0:51e:3558:5eb6 with SMTP id e9-20020aa7d7c9000000b0051e35585eb6mr3872638eds.3.1694674960432; Thu, 14 Sep 2023 00:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674960; cv=none; d=google.com; s=arc-20160816; b=r9VjCmH5nLN6D5syZKA0dPRKk11kOJ+UP4lk7hmLrjSJs2lbeRd1WwRoiTZrk39vs9 l2DaGJll4XizSO9hBg3tgFB9D+28RL3Rto/exm3nVzpDhOcG6sZkTgvj+usagU6oduCD iXcd4INoYBNZMWVx7UOiH0Ng2HnVlbYBexnJu6di7b2XncWCVcTIqU1CvFJRjXLQJDws 66E2Oz/gPEI7lRdk0otxF+BP7AuD7NCdyuw091ioWf2subrkAG3EHdPY0aC9se8UJISi mcjMqwPKtdiNQul35T3Pc1j4h3VHzf96Pmp9JeI6M1utiWpUO1Mf/4rcE6R0kc9Woiji 1y7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=LI+zQJ59a3r0B6jxu7EBQvhSavJoRe/zfRfhNXr3rPU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jHupYuc7Ux/XacMLytFushtrTHODVVuPPrTIeQpWEDcj0NVRJP/2Ydzg+NLA/2nD3+ 5y4dJrkLoYex30N5kptFicwm2KHmFpfnu7iYpybomyO9mXeE5gy8gC5hxr6p2WXpACfP BhAbonjGsdLKKfL3EdymE+tGaedouT3YUkQlvyn0b+lp2Og6VyqonyVLZHtwUhE/K+jo G1Gu50v/LHXmxcWbkxNyJfemNq88dF0XLA0ifdHdEFCaYKhCPAm0SU8s6OoV+lOjEjIq d0keHDH4ykXEaA1yv/di7dqJubrA7TobwJjltpf0K634FV/Sz4p+V/6XnRiHBqHwwhdG vtqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e505Orv4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k19-20020aa7d8d3000000b0052ca742b52esi765515eds.130.2023.09.14.00.02.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e505Orv4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C36C63953821 for ; Thu, 14 Sep 2023 06:55:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C36C63953821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674525; bh=LI+zQJ59a3r0B6jxu7EBQvhSavJoRe/zfRfhNXr3rPU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=e505Orv4GKwdKfMB3KOc9cgAlfFHSCAemLSgYFh8T1kvHBwCGQwmSzjTOguM9bFBV R15hLa5kFObPw95gAOVNa3lXJTZrW/TSfDA2sftFp+onRtbBzF+XpiYrERBDnM2Dxf +yyhDdfgfmEAvdhjb+0TIde7YtLDpTs59otpOnas= 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 2FD4D3858414; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2FD4D3858414 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 38E6TEPE018257; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n5v2gk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqLG004229 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupf027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 18/40] c++: Implement __is_member_function_pointer built-in trait Date: Wed, 13 Sep 2023 23:42:57 -0700 Message-ID: <20230914064949.29787-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: V4U-zPT4xdN6yNJVOnxut6ri5377OHYb X-Proofpoint-ORIG-GUID: V4U-zPT4xdN6yNJVOnxut6ri5377OHYb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=901 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1776995491422845008 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ .../g++.dg/ext/is_member_function_pointer.C | 31 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 7fed3483221..6ebe3984d17 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 84291d660ce..294bcf3dcca 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12169,6 +12169,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); @@ -12381,6 +12384,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 Thu Sep 14 06:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp160193vqi; Thu, 14 Sep 2023 00:01:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq5EwewFgnEFHAgqseqF1cMWX9wsvgSS6wPYc4k7DzhPSTZKTswHMuWhXQBbsazKAVyxG+ X-Received: by 2002:a05:6402:6d2:b0:51e:2e39:9003 with SMTP id n18-20020a05640206d200b0051e2e399003mr3438732edy.40.1694674895767; Thu, 14 Sep 2023 00:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674895; cv=none; d=google.com; s=arc-20160816; b=HbkynqleFCgIrAPtY2qPzvTncznS6PZHSSbLXTRaEVEcMUSMXbzMa1X+sXe+YIls3R N8nD3888vzD9VK0aAIT1uSzBYROSZZ1k8kCMAZE7V/w/itIljXZOsKDvEYNjmU425ZxO O+OaiRDa3JaO3AMynKKVAyeNXBGwGmqQDM4mN9EkLzsMQLN45D7TTnNLiYu8tm+nIako C+7TdhbM4YkGHOXeuoCIOx0SufDBo1DMVQ7T/+Uj5QEp2XDDmzrGFJubejLf2OFSWEg+ A7IzP+nTw/U1pMnD0UeuzwrvJv/URgb0TiozTIdwoyzzidDMGCNBbZHN9tcGzoBDpEkg 3RAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yQrEP3vtkaErFFHMpxRVvlqHQlVao04LcGu+fkGamFWGWRZkYHHGrwry3Qh0q8sMO3 KlGC8rn1YnTMjdwGrou6RxOXPUO5q2N2TBy+wLLgECYH8TFBRehV71wJwzpnYJE4a0/6 rWp9nzbJ1ZOP6pMDjJrWRxKhXlQqZce95joVrr6Bn6OcoLsa21Qj3todk3+hdAl0hudf jg9tXbTGoMAdOVVhd4NNYi638+4GAMNOnRYxv+N/aQprnWLOep6f18Rz9TzHx8dCVH2b 3HdWfpcDZgwxw2d0M/xkiYNNGcHFvibqPKqRiJ9/gy3/OXZJWDN/pzpoGTLmvn/JMCfH UfcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CZvUDSz1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c16-20020aa7df10000000b005253f116480si774780edy.613.2023.09.14.00.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CZvUDSz1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41787394D8C6 for ; Thu, 14 Sep 2023 06:55:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41787394D8C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674504; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CZvUDSz1LYtZH8eOuznvv7Y8DcWvfvDactI0eY0sp2qWoxKEJKLTiut9sPpzgZ2Us ph01EIRgbDoRILi+mXDLZdU9C7fsoWXQVCok5XyRC/7r4N0zybYMjXzq3SiHwxlRpT bB6vtifHsv9pz8n2lV7Lbq4cDKAmwSinpHUTfYy4= 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 7BCB93856DDF; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BCB93856DDF 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 38E6SPdc009508; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3ner2b8x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqo0004230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:52 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupg027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 19/40] libstdc++: Optimize is_member_function_pointer trait performance Date: Wed, 13 Sep 2023 23:42:58 -0700 Message-ID: <20230914064949.29787-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: d0S6hvl1khFuwWhmd5IWGNCYvqzcWNm6 X-Proofpoint-ORIG-GUID: d0S6hvl1khFuwWhmd5IWGNCYvqzcWNm6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=670 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995423218726551 X-GMAIL-MSGID: 1776995423218726551 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 Thu Sep 14 06:42:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp174192vqi; Thu, 14 Sep 2023 00:35:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDWthsJL0n938SJMWpElKlwI2OG/yjRihhiYj3hmn5nItsPUhzg6XyVTK87CV9Vb7rKEwd X-Received: by 2002:a05:6402:2050:b0:51e:362d:b172 with SMTP id bc16-20020a056402205000b0051e362db172mr4011799edb.32.1694676913362; Thu, 14 Sep 2023 00:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676913; cv=none; d=google.com; s=arc-20160816; b=qnaiRK5wROex18HpTJNvo/labgZM/zFQ9GTFiCwaid1UY7yIpPQb6TBe9zjDJehTrh 17Q7MtyZTPNjc6s0/9C5gHP3jZjW4Uu4EDpOb9TW8C+jn0PGZiP4i80oKG3/YMUf1eLy gyTWk1L68drOZOCRiFykdLoA7YVzxE3l/is9QecmnflVSUYg6nBawaou5LT6ZoG+6BJ7 8LH04z5b7LHeBCt256wI/eRD0LVo/SQkBAiYczOFtROQgyk+RCkEIrQ+vhhJswYraX95 91kaUFRhMwsG0XB7iYCdSrzszvY0CMK8GA1nYNLDAPD/uCakWs8w6w3rLFh9tC7VSck5 BiRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=W/n9izL5opsBzGcLfc2usWRrLCdjJP83r46NC+Phlt0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=WeyHqQGJFVh+3oQ5kZpGC5jWwQhTiCBaJNpRSGx7OmuzFZOPogbC0Sh4pK/nRu2p4C x4JEXtNKgkyhKH+m+Y5tSFkftoh7kQZpNsoMpRK8XRbcg3/pORnwjctRPD4qUjg3ksU7 XEvE5koI1jNojqT62E8lzLyIItIiUnA/s1QpsjBkTQZThB/Xn/eDlOX43W/2krWpPsnk 3uD3SjhjVJRBi6NYSMqzXBbculdbOUXmAtwQa8uC3Wh+ThXIOlQLB4Hmrvk29UCO8M/H DPcvrEII7m9bZ4Tza3CNBihA5yS9aB6j6BqPO/Z2NhwShDGMCbQKGiXAaKbIOX71vxgz lz3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fqj7YPY4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c8-20020aa7c748000000b00523c6fa871csi891193eds.409.2023.09.14.00.35.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:35:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fqj7YPY4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D33693986432 for ; Thu, 14 Sep 2023 07:08:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D33693986432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675312; bh=W/n9izL5opsBzGcLfc2usWRrLCdjJP83r46NC+Phlt0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fqj7YPY4V4RWAkk3neASzgLjqXc7cWOSPgdsEnFPnt9VXlbPD0znyW9tOAzex0bvX KBr2moZTWd4rumIl0BUAsFs6BuhvWG+DlntOa3JKjzNouJvi1ciptP3Nr1W82zbQs0 VMcIWDYzUgWJMPCjPkcRSGBO2n9gRGhaHEvNFtzc= 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 617693853D09; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 617693853D09 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 38E6p99P017440; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3ner2baa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oqb2026252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nuph027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 20/40] c++: Implement __is_member_object_pointer built-in trait Date: Wed, 13 Sep 2023 23:42:59 -0700 Message-ID: <20230914064949.29787-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: OtxrNW_xEXvfauoApd81M3hSLnBirPMg X-Proofpoint-ORIG-GUID: OtxrNW_xEXvfauoApd81M3hSLnBirPMg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=923 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1776997539192739394 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_object_pointer. * g++.dg/ext/is_member_object_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_object_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 6ebe3984d17..47649150ab5 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 294bcf3dcca..534f24a1f9c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12172,6 +12172,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); @@ -12385,6 +12388,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 Thu Sep 14 06:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp167747vqi; Thu, 14 Sep 2023 00:19:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5GnmSWrWrijUbReK/kMA8r9mMCc0jwbXtKguFHqbjqTTwbo7Fp7ilLxS+HftSo9Nhc09/ X-Received: by 2002:aa7:c859:0:b0:52f:2a38:1f3 with SMTP id g25-20020aa7c859000000b0052f2a3801f3mr3788208edt.2.1694675943941; Thu, 14 Sep 2023 00:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675943; cv=none; d=google.com; s=arc-20160816; b=s35iMP13EzlT3mV0Uc4tYlnJYyhFsjKm12KxwWioCgrK0wGMFlXtyMGDkomIt/6H16 BZei4xvmWg6tZGubOwFu/1mDPm5sAYWFIVzXDoZ8mtAt8JTAb+HZUBvaAb7pON6PRAcw /pwoLTdljfCB5jIwMO34gJaYonERbNgRyQObJQruapMiN8/HP5yRAA3fFpYUVycyInAr zu0iYRMcH5ZQ9bkaJzX1jUAC9uisoBG4WV2BW0c2nNoY4fC8otweuusePfz/YqXIcqw0 1yeabl4hPXDRVWLAOcua2LbPFzdPnmzAe/cQQtU9rXpLb0FK+E+VjRxmO/X2aLS3WTZE w90Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Mt4MiwZW0u1/bkVOtJdJdwcrjpzpCAZIkn8gSvL1RLWHK4jopq/GSq8/r+d5ICN1q6 QTDyKfqXlOLAqlJhdvRkNe8ed4GOu7OAeOJuljxFOml+xNC6rIrKBL99t5FVoK3yBU8M CCWWfsIdlAJ6y99TlV6eGUDNElZl+jy/eMsb+FD3QC5CYHCcnsOsRds1XvhjuHne2zTg NLIGha92LqV0fYOobtHOHZ8i/KMBVqsiZDEKkd91P4ZPQl+zNRbN9mdDUaHFm4gLhiMw hhzIMwl/DSHTC5fV1CMa4kNUO4jyIXDw7x6ZqzKP7kKljPBeNXWzBzv3uCDMs8AveRts pcLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3bcJeWb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c14-20020aa7c98e000000b0052c9823ebf8si774398edt.428.2023.09.14.00.19.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:19:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=y3bcJeWb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 708E1394847B for ; Thu, 14 Sep 2023 07:00:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 708E1394847B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674835; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=y3bcJeWbstYjHJ9fcJ59C3jKcqwjqJEBfExNom53U8yjQ51uVy76bM36Rq4Ms/qle Y4c5DMWOX9J3tKlgaLp6BduikftXAcu/xC+S3JMGr1HjOWjD0eZFZJR2+b/fEg6Jb5 GzpbMivCI3HZcscaWsyrprrZJlpE0Ci2CWiIBBG8= 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 7664B385DC3B; Thu, 14 Sep 2023 06:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7664B385DC3B 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 38E6fVIl014102; Thu, 14 Sep 2023 06:51:16 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3rxxgvfd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oquE032285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupi027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 21/40] libstdc++: Optimize is_member_object_pointer trait performance Date: Wed, 13 Sep 2023 23:43:00 -0700 Message-ID: <20230914064949.29787-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: EO56DN9MQAmseVAh8KXULKhPLMlh_pe1 X-Proofpoint-GUID: EO56DN9MQAmseVAh8KXULKhPLMlh_pe1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 mlxlogscore=592 malwarescore=0 bulkscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996522370919550 X-GMAIL-MSGID: 1776996522370919550 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 Thu Sep 14 06:43:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp164973vqi; Thu, 14 Sep 2023 00:12:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTeZoeRU48cXpRrmNdjv2KZOJ+3DdOe0fpiB4T6Hxt5xxO4gNK13gJHJf25lcFeKgvDHID X-Received: by 2002:a05:6402:2028:b0:523:1410:b611 with SMTP id ay8-20020a056402202800b005231410b611mr4072106edb.25.1694675523515; Thu, 14 Sep 2023 00:12:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675523; cv=none; d=google.com; s=arc-20160816; b=anWunEl7t2mNDzr7w1Zf8oe01wWWTUx5tyL4iEg8UU9JP8woV1ypIloF5b75U9CW0r SJ3iT6fwCBNVEMK/2HOA8G0YDHSkcQ6GxmA26ab2WaVo5xARaNdGr0D/ocZWae1pGsPL KJFzadYUcvvP/zdjPgjrknTMLz2l6j03FlkRza1VNg9Nl1Ruc8iqieu6VLcblhglkvC+ YOiVhpz3vADHgGO2cClRDiibcbWX8McHdxX/DjFKhhcqwsXB7Rj6CiCLuMCkuJSSEV1k DIWVztTe4elmn2a4z+DW+WqT/ZMBWrn7SzSGmDbQRItCTC7Ivom4CL3HPwZ6IieaG1Ly Xm2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=CfnoXXtZ+ISN1bP400AKWaUEvRCfWpeplSqpBjSTtaw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xieOehA/U4Mkj3D/JBvfZScLFcI8atDefR6xIWAiAefhRpj8usYAZjqo6ktYW8upvy 1DnxPBNLmLDGWvTD2WnQko4hTcOeCJs7cvA/GSXF3wQZGR1xfIetlklpHjpql21BH4K0 iVZMAj5m4hZnw4tG8EusDToJ3z3P/8q2sR+RFbcJ9DLOKvJIEb1wLWEc3K+TT1igHSZS IibFzct1mms8Z3fspg0odkJm+PUgpqxtibHiHSRS6wvaZ8m1W6K/5/jJA0HlE1Vs/KmH oTr1r7kmsvepR3hMUy79aWdzKZGIpuZDbYYAerhRzGhGwGb4UA/mBN+DWbcZu9LJ21lE 1Leg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="HdF/xBUa"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r13-20020aa7d58d000000b0052e9e089a0dsi754954edq.253.2023.09.14.00.12.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:12:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="HdF/xBUa"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 051F53831C56 for ; Thu, 14 Sep 2023 06:58:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 051F53831C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674695; bh=CfnoXXtZ+ISN1bP400AKWaUEvRCfWpeplSqpBjSTtaw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=HdF/xBUaK/l+kr20CV4v2Xva3vbLbNbUlO/MacISSE/qgkWQKIuVrI0ujDl8EeCg1 JdpGIVlQzIZUdkW0X81CiRJf7DiNsKbnFMwmQKRWvIrBkK2MKvWlTY5pDMdYERZWwb cQVRD6gQK/7pkBEeYU+NAyWYIjtaU6v1Bw2kwX/w= 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 774D63856DC6; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 774D63856DC6 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 38E6mLde014011; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3mfbaw5n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6or3n004232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupj027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 22/40] c++: Implement __is_reference built-in trait Date: Wed, 13 Sep 2023 23:43:01 -0700 Message-ID: <20230914064949.29787-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hMZjlBd_RvWd4Cr_3y7EsgnjFji75MNu X-Proofpoint-ORIG-GUID: hMZjlBd_RvWd4Cr_3y7EsgnjFji75MNu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=735 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1776996081559193793 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_reference.C | 34 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 47649150ab5..ac9fa026b4e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 534f24a1f9c..97ec53a7606 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12196,6 +12196,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); @@ -12390,6 +12393,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 Thu Sep 14 06:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp173957vqi; Thu, 14 Sep 2023 00:34:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjs64Qps08eQdh0UmC6B5vwyQiuTE5I1L6aeRpQXXz2BuiAx3njW7gT0ttk2e+pMIERyT2 X-Received: by 2002:ac2:5e30:0:b0:500:9f03:9157 with SMTP id o16-20020ac25e30000000b005009f039157mr3770283lfg.65.1694676876293; Thu, 14 Sep 2023 00:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676876; cv=none; d=google.com; s=arc-20160816; b=xBWNAuQmCZr22whinNAavdHrkfSjiyywslSdibKPnuBDd6Vsi6ABqPzqQnYZNhABno lIMXR8kq37vEqHlQP4fVRpMQy8Ws9eCjwYeJLUhLwPOraE5meeuuNo91sY+cltZ+Gg9n ltOHpJCy/lA8pqfs44pMAXMVy1I5ODOKLvvjThZ9CtqYM1ut1AhZMNevODsJQ/Xjux8O /ZAYBx2z0jBJdkc077Xop1rUysGDRu7/8PxNiO2hEHO6OeNmPuis1f7Xm+fHyLk5K0zQ 7KqJszOTWSiKkGW5bh2w3SuyedEcLd8Rux5fVI15N3E71s8mLCSOgu7Ik5UiJ6ARyCRr +3OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=bXs9BXyBm63+Zhqcz0QqT4P4t+2j6wByU7zylQbbGPpo7KLLZ+ny/1FiXulp1EQZKA F/tFvFC47bNo9e1/0I+WVSicw89tIoVGqbFh4gTTAn1EYtEULydL/HH5TuEspb1QIv1R kRGapu0TR3HJLN3Dc/8AFxnjol4HarsxoZo3A9wiGiV3o8oWPahUoxIWIOjSWNGXDI5Q Vz0AhyQfsQoOXEGAM1JiI3ZAnXHEDjb+XVA1dDIqnedXAORnWRq4AyZoyEkx2gbRuAjW x2rKKu5W41M0MinqhoUoaVOaYX9wig9s0Y1+APF2F4nxweF9ZZQsn7AKDs/620mqicUe ogoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=phWh+NRs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h8-20020aa7de08000000b0052e59011321si795767edv.419.2023.09.14.00.34.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:34:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=phWh+NRs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E3F5398241D for ; Thu, 14 Sep 2023 07:07:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E3F5398241D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675274; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=phWh+NRsplYY0B0v8tGM9JIX6LlX+I+XX8KzOEt84Q1MdueSqoKCfO1JRyDjCezD6 9tDeAqMTOQXHxAciOBDTMO2pJiePO0HefUwc3RIgphfy1Bk8/7f9M0FNBIwobeYBYY BlrMom6c1QB0V2rUNTPsJD45PB5xZcUFNU9QEwZQ= 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 9A8C03853D26; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A8C03853D26 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 38E6osww019272; Thu, 14 Sep 2023 06:51: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 3t3n53tf83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orhF006962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupk027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 23/40] libstdc++: Optimize is_reference trait performance Date: Wed, 13 Sep 2023 23:43:02 -0700 Message-ID: <20230914064949.29787-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vy78zrakaaXGlXumV-XkgGHaVmXwtKLQ X-Proofpoint-ORIG-GUID: vy78zrakaaXGlXumV-XkgGHaVmXwtKLQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 priorityscore=1501 suspectscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 impostorscore=0 mlxlogscore=786 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997499735714658 X-GMAIL-MSGID: 1776997499735714658 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 Thu Sep 14 06:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp159218vqi; Wed, 13 Sep 2023 23:59:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZwtQt5ZaqGfXX835e/eL7p3qWXQs4vjhKm9/4xFy28pgM5iR6lLnlYzoSjXD2m+SVpoyV X-Received: by 2002:a17:907:1c8b:b0:9a9:f6e7:43fe with SMTP id nb11-20020a1709071c8b00b009a9f6e743femr1388909ejc.24.1694674796937; Wed, 13 Sep 2023 23:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674796; cv=none; d=google.com; s=arc-20160816; b=UFeOiQgGJFVIZUDTRYBQAoYfuA/k+DL4pk4Ri73OxbEo/vb/sNQJV2I84+Mm/1r710 qXbgp+eHg/e4sfL0UyuuWPJGBoRuLg31JgZn1PK/ILD8YQ8txgkbB2K0HUA+K8z4yuhi YCrZKz85iCqORopa32IW6rkG7oeEi5oSRoabLB0e8ZYwouZvXiSKKDP72AHI5MmEBG9b LsA0vOnmocz/CpP/FK1Mjozo23Hjd4/rq3A5OR7TdMYheS3z9omPQ7NuGnM8OZQChd+u ybqVAU3PIGy+90G4FBfaXAjD0uGF2K7LgpZorjvtqrZwD+EYG2jgev2mbG4l6OieYQKc HRng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ONFpUsslxAl9U0hFZfxVrFfeEUAyNNW0o3aOGh3JasQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cyCbNCzMaeahtUtJnBJrZe3ipe7fKuoOgTUmjEv0sBRIVk6bOqIv/0lRxo0/AtmUX0 f3uFZYg9gGAdk3nS6pG0rVhUmVL3GLs7ofTjPJU+xyPeM5MWJTyV5o9wuWESZCEiur/I Cb4VyX9fFPBhJuGtGhX/IZCtshc1BbaOmNHMBi1c4Tev+K3/I8CdaBVWXshxRfaO6Vqf lNzvY5Q1SG5F5f837zs+vtS3pabUaKjpy/OU9ev7NCV1yZ7Ix9ZbJ6nm3pQB7usVvAUj W+DRpOsXibyllitvdYYCzpLxQnwy2sVPdrkB7p/eRmr+WmC58/g03xLn79PDjdOgWRYV 6UaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RzqW0BRE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n22-20020a170906841600b0099207b3bc46si786822ejx.322.2023.09.13.23.59.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:59:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RzqW0BRE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24E0A3940CF1 for ; Thu, 14 Sep 2023 06:54:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24E0A3940CF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674466; bh=ONFpUsslxAl9U0hFZfxVrFfeEUAyNNW0o3aOGh3JasQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RzqW0BRECE+JAIIuveTI5ZzoCV6ACM7yNSimTkHEUmAlbMEqE81qs30y/BHS3cuPJ FTTaFQBilUAyHhE+UgkdzGR6Dd5Ndrkm4Cr7QogzXK0aMIkRBM1uVhAfzlMS3gYosq 5q+SZS96yqoVXcF2OFV/balH5rp8rl/FgiBJbTlY= 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 971EB3856DC2; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 971EB3856DC2 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 38E6jCxk005501; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3ner2b8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6or5B004234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupl027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 24/40] c++: Implement __is_function built-in trait Date: Wed, 13 Sep 2023 23:43:03 -0700 Message-ID: <20230914064949.29787-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -O56_rtR931wn6HxICyMXn3zMKWgBwTw X-Proofpoint-ORIG-GUID: -O56_rtR931wn6HxICyMXn3zMKWgBwTw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995319714743541 X-GMAIL-MSGID: 1776995319714743541 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_function.C | 58 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 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 ac9fa026b4e..3bb33a3d5c0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 97ec53a7606..7457475f646 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12163,6 +12163,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); @@ -12390,6 +12393,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 Thu Sep 14 06:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp173276vqi; Thu, 14 Sep 2023 00:32:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIRQ2NHcRJJrunjMT/AoIC/oUcXeUUmQ/Gbno2TWTd6/4F6Ta3WngBDUZ6Wy7j6WjScO8A X-Received: by 2002:ac2:58c5:0:b0:4fb:9772:6639 with SMTP id u5-20020ac258c5000000b004fb97726639mr3449883lfo.6.1694676773720; Thu, 14 Sep 2023 00:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676773; cv=none; d=google.com; s=arc-20160816; b=ZzU+hW51U/nz2QNdLD9uSpc554GkVRFffozAIqCPuu8CVoxwAgj+w4CIBNy4emW3LW u9AzZQ5IKVLPJCQa7azmexnFUA3EW01AgV3goHRZBcT9dIcfbXhZcK0HM0R8roWPFqs+ YtVy/y/tQFrwqTqZBbagkxAApu80aZqm2m40DZDjkLlkqg6Wz/WeTFyNYiRNclcJ4Gy+ qMntpAq09gDzJAvwlZ7BIhp2IBE8p3jPL0btSN59ZG48TSv8N+fzLKKl/11RzBo5pMP3 R89OF11YM/5nNAqNYLgD6/eFrEWc+A3dOZ2TucgO4WlDB0kWwdh6YdNaTcBNH4jLGj+h Wzvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TPcbKdqBlZ9haTg3P5x0osG+MGefBvdMyDlZPWLjopbuUSaQ38SBIm1lpNdIy2At9+ 8/wNXYQwARna7UjE65cEnYhgI4/Ev+yZQVLRunKNczGNCpmMNiU2Nu6pNHSlRGhL+dml XELsKMz1QG5lAoEln3n851dtg9EIHhUsMp8uBwG2tYPVuBO4SzFt/rHJ1/12GYKYNeIo XxFmR47x4VcMxe0bc9HFen99bmpNbkQhfw60B3ufwxKn7WP7qrBe6LlagO+QXSEmJWAR /EOXOzIMTWt+bjvvqQT1MgX6lxaT2KD8b2nMPES1AAFv19XK0MT4/oc9JFoOj6pVT4b8 2s+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=B8Culj0V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r1-20020a056402034100b0052a1a5d72c7si847476edw.178.2023.09.14.00.32.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:32:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=B8Culj0V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE0463AB87E5 for ; Thu, 14 Sep 2023 07:06:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE0463AB87E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675204; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=B8Culj0V6nnyPaLnO5VA0U4fnzOY9gd45ekD2XjOuxiIGiHSr2Odd227OqwNE+YcV UMHkHPEsW5WAaJwAjRQFYAZ+9eCkFFwwmtaHNKG84j5ILf4UqpEdMvITwwt282hbzQ /aqjZjYHf0AoWksNwkZ/sxoTNzow2yyd2hzHLzaQ= 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 8075F385841E; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8075F385841E 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 38E6cHjD009192; Thu, 14 Sep 2023 06:51: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 3t3rxxgvfg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orOS006963 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupm027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 25/40] libstdc++: Optimize is_function trait performance Date: Wed, 13 Sep 2023 23:43:04 -0700 Message-ID: <20230914064949.29787-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: qmooq5iNSm8xlXtEzQDg7aBfE39U8qyH X-Proofpoint-GUID: qmooq5iNSm8xlXtEzQDg7aBfE39U8qyH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 mlxlogscore=588 malwarescore=0 bulkscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997392552534413 X-GMAIL-MSGID: 1776997392552534413 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 Thu Sep 14 06:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp164072vqi; Thu, 14 Sep 2023 00:09:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsG+vFJx4KriWH4eT+x3UTp+RXVfGkjhml4E852qCKFPfrnsyXYln/uryOkudK/FT2PSjI X-Received: by 2002:a17:906:2cf:b0:9a1:c0e9:58ff with SMTP id 15-20020a17090602cf00b009a1c0e958ffmr3619300ejk.11.1694675393307; Thu, 14 Sep 2023 00:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675393; cv=none; d=google.com; s=arc-20160816; b=O/mDJ9SEWMstMucv61+SLloTnnc+ArUQlOim5/QzWlZqel2uckuu0uorTkLBdzZxJu tsa2XCZmquJ4V17JmLY/cRfK6ZodAj/xn22pmKldDPzwvG6vcusKbLFTWuTCEleQ9fdZ 2mUu0c1iCHavuprnpPncES1j7XlE8d5K0pmJtoadWXuzZDlXRYQWVUN3oJxGJPM38Myi KMKmMBztyjnCAv9SXaJPWX9EGlSIFEgEYjRXElXtZpvcPpQW+teUW4zIhuthbgOPjzGr KNgWb7Tp5vRJuY7NXOx/AMfzexi5/UZMWB8BNfPHLZAWJkfh5r91d9a6T/aMQI5Jjobc dkNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=SReZ/PSKj30d921szCO3KVloYESNrsMMGhr+Vo9GvPMyc4n+YtEJEXrtyJByRE3PBM cW27QJPJtVm3Wrc/SHJwY5EtX5Xkdi/zYxC3T/6X9wK1/l4boC7Pt4xNWw5qcmMbqp36 X7sayS83VOhMr0zEtqprGuIgoZS7wWRhpniQv7z2S/SVUr7xKlPhCRevKW2dtL6O8eI7 bMs6DktMofq1Rpzxe5yWrFv9bUu9n+dDlcMCrqMdpSTfh7IVIzbi4mhqEJRUcfx7gpyF sJ2ruYtA959i515m+fpR37ZDW/XxCMTxh6sQIBIppIu/sZB35RvXcRBEt2U9+SxQ4lJW W9Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e0eNTqsw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dk24-20020a170906f0d800b009a9cd0f5710si756360ejb.977.2023.09.14.00.09.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:09:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=e0eNTqsw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FAE23AA9C7B for ; Thu, 14 Sep 2023 06:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FAE23AA9C7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674650; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=e0eNTqswTCUN5+Jzsi5sdSPBSavo89sSrEjeOFKqloqjn/p0VYCpyWKKUHDkjXa67 f9VBa/7TUTilX0HMVr8zf1V9yY7MQorMlziv3FllpsJ2LKQEqctNg44PPQVF8ylz11 JVG/Mxvv8FbsGhw85xBmOoF7uCY67Rkhd6wyz+J8= 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 85B363856DFB; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85B363856DFB 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 38E6ahM8025249; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwafk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orjH004235 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupn027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 26/40] libstdc++: Optimize is_object trait performance Date: Wed, 13 Sep 2023 23:43:05 -0700 Message-ID: <20230914064949.29787-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: JSTL43Y7iLD9tKImYkYd4ikEJGEPRnRn X-Proofpoint-ORIG-GUID: JSTL43Y7iLD9tKImYkYd4ikEJGEPRnRn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=797 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995944979792207 X-GMAIL-MSGID: 1776995944979792207 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 Thu Sep 14 06:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp171588vqi; Thu, 14 Sep 2023 00:29:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLndU0FfIZicbSGHpkhS+Bpony29ih+WusfqQbmHnVBi1qE3HD4wCXAXpEW1k77+KAdE+1 X-Received: by 2002:a05:6512:1283:b0:502:d302:e025 with SMTP id u3-20020a056512128300b00502d302e025mr4613106lfs.2.1694676541292; Thu, 14 Sep 2023 00:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676541; cv=none; d=google.com; s=arc-20160816; b=vRu8kVWt8WIvOzgNf8o4v1mqFq9iM0fpcO8V6sTrW42CwHCqAX/Lv6WpTbJU6goJmk dgktmFBqkfo2ZuhY1msKTceD1ybP7G1+YsmpF/USJ2IaLE/WpwQ0bbAkje28OkFMG8Ti 2j6xAmx0BBKGnT9ojWfLy6MbogQGvOvxCTk2c9VGrgXOQxRdibP9sz8X0a13UitqgSCi cdu7vZhuu2SN+frND6Y644hY5SzdsrEo8AQS+Matplzg5yFK54SHXgCDOU4YMpINIb+O 50nkCIdKirOMLwNOr0MbLhiczCjK7o3QL3ctas/55Zjd/kKnkRR+X3btzXzfFlnPy/BJ xP7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=y7mpep/7O/Mfq4JM2Iu2cC+4psUa8GZioDRb1GtaH6c=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PTlFMQM7W2od7zFWltjtN+/Z8tOogYMjdKqcKAJKaYtv96vJsVtvXdTI9C8mk7yGa9 EgqaflAnoQeezzyHXJX4AuwxGIDXzAR/XIXRIGt3VGKFzm5KiI6QJdofI12WPjal2yQo UOFhFfuc+R1N3RsL2q+ey/zpPbGQBS/ws6PBjUT1KZ91uJkTjSb3z7eOdpWLs5yMWpDc xgvNkmf/G5JQzUtU06AMvhhv3xQ2vD9hq3sFc1MxHEonVV8ysFA9alu4muo0TsaJVSTI 3Om1AINtwmZjTfNqew90fITINbgHKlTnqxv2iUiLAmgv2FufUifGMoL1sgqpJkAB1cX5 UnuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=raQqIMxH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d12-20020a056402078c00b005288947eebasi854871edy.171.2023.09.14.00.29.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=raQqIMxH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06A783955CB6 for ; Thu, 14 Sep 2023 07:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06A783955CB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675048; bh=y7mpep/7O/Mfq4JM2Iu2cC+4psUa8GZioDRb1GtaH6c=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=raQqIMxHDxbo+P9AS43QleDEs6854B6A2pBIU0poJb8GCESLL9CPveA+TRx805A4K XvTp8ko7I99V1tYsvNjAj4M6HFFIYwBlmV9wpqAhy+uqz3mO+2VYKQRqzXl893Rp45 +4Gm6x8lc5heHw1pTPpAojZlsIaQ83OSUh/v2pm0= 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 4105C3855598; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4105C3855598 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 38E6juPF016748; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n5v2gme-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6or6Q026255 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupo027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 27/40] c++: Implement __remove_pointer built-in trait Date: Wed, 13 Sep 2023 23:43:06 -0700 Message-ID: <20230914064949.29787-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: VYHGHdEe9hDlJKvcfrLizPpqthHVG-GC X-Proofpoint-ORIG-GUID: VYHGHdEe9hDlJKvcfrLizPpqthHVG-GC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=498 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1776997148879891783 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 3bb33a3d5c0..07cd14b6e85 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/semantics.cc b/gcc/cp/semantics.cc index 7457475f646..4de2dbbf603 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12473,6 +12473,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 Thu Sep 14 06:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp172494vqi; Thu, 14 Sep 2023 00:31:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkBXl4HhAXko44aW0eFogIWhxU+JikxxjfsBGicZnQ7QDWik5OahSYTl3QNuvRi627PSbq X-Received: by 2002:a17:906:5a59:b0:9ad:7f13:4db8 with SMTP id my25-20020a1709065a5900b009ad7f134db8mr3989524ejc.36.1694676672688; Thu, 14 Sep 2023 00:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676672; cv=none; d=google.com; s=arc-20160816; b=VRBVhyLVNx59iqqF/kIuhInWXcJFQoQXqXrET7hUpwYd36URMeuE5jAZkTcg0jDRAl xJybseU2Ruq3HEuvqgPmArgCWwyUZdJ/fCIN/OEoXTnpSYSjbpoPpme4yvkCxaWiybZf 4waxNAenx9p7OsrO+242StDzmoUz779OoxEYfEy5IU+EsSVLOWMAcRHL+8b4AyPeFU+V 2VHQ14G99LC06tsw9ZVWfx1bRqAw+vMApadoeQ97h8GfX+ZxVJL41DmQ77rjknS/ZJ3+ Nk8N8kAaplZgI/vpoYNk2HUC6LNPFw0qCTvCvlSonEHZqKV0evTl0748ZiMyT1CjHvN9 xQhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=QIs7lTU6x2HsNq/lBxP8R9/+NJkKXzSBDQ16JMHKFeMc7enel5Fahld40pqaDtz3pU J6FBCKE7ZLwvOPEFZv7IvAMOrjNjlsMujMxujzLj7XRSBCNfpwphGgE4/3bltRareNhr t9JJkAZShTeiDkLE2Yplu3RvG0Ovbwn+0ewA3eKyL6KP5DLgb49OMl6U4Gd4RHCXmS0r RsCD2IgZFrRYWbBHoSGGpcKBQGWLpwzZafRULzHG7oSaBfkJ4TKLRctc4/8Q9E1shmvS epIq/GKEEZIou8j09Ijg2aSeRVIhXRZTYmBXfKJR+UZ8eltfdj9tiJ6ApSKZN3+PkMdZ Iv+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ngi9W8zu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qc19-20020a170906d8b300b009a1b2ec439dsi750807ejb.622.2023.09.14.00.31.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ngi9W8zu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF9D038883C6 for ; Thu, 14 Sep 2023 07:05:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF9D038883C6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675139; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ngi9W8zuVPwoXmPO4l6ZTZ1YsHbIuf9BP0dYi0lKskGa0NUMDCnXEgsPInsH86QoC FAqGZZ6nRqSxpxvPG3dVK6Vqm48u7HQVL34eeSvWGGKFgWGP86R0VGm+bQbN2haEa2 Xpu5UM2cFUQo7bY2qpjAduiL+Mt7UrhibYIf4kxg= 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 6A1A7385DC1D; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A1A7385DC1D 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 38E6lk9A011656; Thu, 14 Sep 2023 06:51: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 3t3p4h9yxn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6ori8006965 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupp027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 28/40] libstdc++: Optimize remove_pointer trait performance Date: Wed, 13 Sep 2023 23:43:07 -0700 Message-ID: <20230914064949.29787-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: NG8GzzQ5vL5VTDr80y-8We44zyS6flZS X-Proofpoint-GUID: NG8GzzQ5vL5VTDr80y-8We44zyS6flZS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_03,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=667 impostorscore=0 suspectscore=0 clxscore=1034 phishscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997286578618893 X-GMAIL-MSGID: 1776997286578618893 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 Thu Sep 14 06:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp162514vqi; Thu, 14 Sep 2023 00:06:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIRqFKR/jHjHogS//Hn2AwH7ertOxo+oQXQC7ekRJkZY/tSUwVI3tri7yfXVHFjhYL1lof X-Received: by 2002:a05:6512:31cc:b0:501:c17c:fdae with SMTP id j12-20020a05651231cc00b00501c17cfdaemr4790645lfe.31.1694675171497; Thu, 14 Sep 2023 00:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675171; cv=none; d=google.com; s=arc-20160816; b=YhUb7rs4s0hWxaardSOYBXKPMMYA6t/tUODEhfWl9dbJ7KI+VGYHOabfvCcdtUeQD2 6K6lwOmWnoeX7QuUiTNiGIQlT6p+mPxd1N2Daqgbktmi27GVDxI3HztTJ0s8IKAtdla6 Kul0G56Cnio/RCMcF8c9LflOo0fu+8q3wvwClU0/HdethUsliSTzuXxjpDOtbR6/1+tz 4YKZHqhUg+kRCgQpbSvsLdJidS6nrEL4EapJZB8QEEa+4vIKyNJu9wck4TWxJUako89Z kb9Lv4KQAVtePuG7KrL/HCjyhfMKZEFGcbU1PP9kVqucpKit1wtHbrhx2qdZ8uYuZwBy v7xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=X5vgc70DVB2g0SDtnTk5rTPLlu9+cmEzOYq9e7R/cmM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mQOZZpsSsqjvp/5/jGN249P+1W0H34CoVPLcaYoUJq3BT/uudle/KEYk4OmD0i8nGA ryRrVD3CbcUX/DH1LSxbHrjJBncBqNvkkGwYe7pabLJ2OPYIq/KIevpNE3p2wdONGs/0 vk9/UjzqVHru3JUOvWtDGXGXhxmFHI7DUH1eXgeoR93LIXYI7S5ZBiASp+CnYHVzQLUs 5/Fc5X9nkTmbWP6pjgZKq4M06ZmHFchJWFN6kaxtW5uE1gfEfjZ2qA1AmmTdeVLTQrJ7 A6w5V7lI5VVjDAEPehpywajqvJVsJ2nqV38/bShu+sMIW37XbkMYDreozO0E/xeBsxwU raRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3SmtWPO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r20-20020aa7da14000000b0052e95776ee9si791171eds.137.2023.09.14.00.06.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3SmtWPO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B3AB395C064 for ; Thu, 14 Sep 2023 06:56:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B3AB395C064 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674587; bh=X5vgc70DVB2g0SDtnTk5rTPLlu9+cmEzOYq9e7R/cmM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Q3SmtWPOGZDXvprWEl2W/oE32ohsJtY8RHS2Qes4lmhTvSBrfudbPvnJJJdOnSprl KMiBHMCLXWVigMPdjzPh4NTHUEoxTS8lMgE8M3q1bg7vQ7J5Oye+HUHOwG2x6Ip/8R ceK7LgWI0jcpV9x1LcvCkBgLV6yjjGKSZJn6vSSM= 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 3469D3857730; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3469D3857730 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 38E6ghvT009870; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n5v2gk8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orV1004236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupq027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 29/40] c++, libstdc++: Implement __is_pointer built-in trait Date: Wed, 13 Sep 2023 23:43:08 -0700 Message-ID: <20230914064949.29787-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: zP6nJueYcLQPksVi53zHU3o5UFtxwRw_ X-Proofpoint-ORIG-GUID: zP6nJueYcLQPksVi53zHU3o5UFtxwRw_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995712601902354 X-GMAIL-MSGID: 1776995712601902354 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. * g++.dg/tm/pr46567.C (__is_pointer): Rename to ... (__is_ptr): ... this. * g++.dg/torture/20070621-1.C: Likewise. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Rename to ... (__is_ptr): ... this. * include/bits/deque.tcc: Use __is_ptr instead. * include/bits/stl_algobase.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 +++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 22 ++++----- gcc/testsuite/g++.dg/torture/20070621-1.C | 4 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 6 +-- libstdc++-v3/include/bits/deque.tcc | 6 +-- libstdc++-v3/include/bits/stl_algobase.h | 6 +-- 11 files changed, 86 insertions(+), 24 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 07cd14b6e85..bc2bb5e5abb 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/semantics.cc b/gcc/cp/semantics.cc index 4de2dbbf603..4b73863ec77 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12196,6 +12196,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); @@ -12397,6 +12400,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcab0599d1a..efce04fd09d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..f08bbf6fd7b 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -192,13 +192,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -226,7 +226,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char @@ -1202,8 +1202,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; const bool __simple = (__is_pod(_ValueTypeI) - && __is_pointer<_II>::__value - && __is_pointer<_OI>::__value + && __is_ptr<_II>::__value + && __is_ptr<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); return std::__copy_move<_IsMove, __simple, _Category>::__copy_m(__first, __last, __result); @@ -1294,8 +1294,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; const bool __simple = (__is_pod(_ValueType1) - && __is_pointer<_BI1>::__value - && __is_pointer<_BI2>::__value + && __is_ptr<_BI1>::__value + && __is_ptr<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__copy_move_backward<_IsMove, __simple, _Category>::__copy_move_b(__first, @@ -1426,8 +1426,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_integer<_ValueType1>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1515,8 +1515,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value); + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, __first2, __last2); } diff --git a/gcc/testsuite/g++.dg/torture/20070621-1.C b/gcc/testsuite/g++.dg/torture/20070621-1.C index d8a6a76b6b0..b05136163e8 100644 --- a/gcc/testsuite/g++.dg/torture/20070621-1.C +++ b/gcc/testsuite/g++.dg/torture/20070621-1.C @@ -18,7 +18,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -49,7 +49,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { template inline bool __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); + const bool __simple = (__is_integer<_ValueType1>::__value && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } template inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..be0689096fb 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -17,7 +17,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { + template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..3711e4be526 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -364,14 +364,14 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // Pointer types // template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -390,7 +390,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index a212b8a6940..08d888ee8af 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1273,7 +1273,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr>::__value + && __is_ptr<_Ptr>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with @@ -1329,8 +1329,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr1>::__value - && __is_pointer<_Ptr2>::__value + && __is_ptr<_Ptr1>::__value + && __is_ptr<_Ptr2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 2f5a4bd4fd4..d1438429487 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1217,7 +1217,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple = ((__is_integer<_ValueType1>::__value - || __is_pointer<_ValueType1>::__value) + || __is_ptr<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1380,8 +1380,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with From patchwork Thu Sep 14 06:43:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp173142vqi; Thu, 14 Sep 2023 00:32:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECuhziXV3rl6U3GwR+itp5TcaVFdc7uSwdKZdDR/1BnyhjPGWWuOX6gMT963sRZGPkEuXB X-Received: by 2002:aa7:da04:0:b0:522:3ef1:b1d with SMTP id r4-20020aa7da04000000b005223ef10b1dmr3598093eds.6.1694676753744; Thu, 14 Sep 2023 00:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676753; cv=none; d=google.com; s=arc-20160816; b=Tz2l88LFszYw3YxXLiLlqHqVDgu5Rx8BI3CeyV9iaNOBN8BCzKgII2J2ItPrmg1KDf Xz8HJMFeXUAsTWJ3tK3ZOoHT+GkcXD5SImkBEUl3K6C2v3+5YsAHHOn46Mf1lqSHjQUR U+YT4EO/QfAJrOHUUoyyCzYVEic1E12ELiGZj3+EcfeElIOgxsMO6Kehfo3xZL25Kgrg i3axDEz+veLQU1tu5WqIxojOjG87Q246L9CmG+lDLhBZq/Wmbazn4I/6MmFkIS18LRHR n7ealEfiuq75HK1t8Aojn4uhrCtbuSoBRINQYVL+Oj2x58wsMkSzzHC8Yj3YEesHzKfc jY1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=yDZg+sY4Ri4j5bI7tZMr7PvbTgsN8H6ee37J/BJAw2REK4TCp09dGsZhIzmslOyEHL t7c+BjZa3qIXVsUAIPTJl4seA6rylKXAVyNcWNjIrnbzUgXi3ClnZ2GAgzZRQTDRWxvg y+MXgeGy90KY6WEcx0hjdcmmycoYvda2MljEMtTkeave8UrI3Si8tSC/xmhj08v7YQKl MO3LSXmi7PAimmqFHgc0RXsjB6yFOU8buf4B8aNnQy5pyTSt2dA/lfy9HWBn+1RtkfEH y3WCrYa9wmugO1oYF5rxzDxUgo9tKaqRAnl3bFqvzjhXxlZTV4pCgL9G/Fgm0EncI6mu ovmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BTkekFsK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g12-20020aa7c84c000000b0052fbb0b57c2si789229edt.64.2023.09.14.00.32.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:32:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BTkekFsK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 102BC396DC34 for ; Thu, 14 Sep 2023 07:06:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 102BC396DC34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675193; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=BTkekFsK3Lcb/wDtHVfRugrT5CdgSEW192ikRGPVVU+CnfVC8ih9RQXs7C/BBKu/c szLDJWltlJokDv8JdiZNXP+wiiWlnoRTyXtMTEIM989iJ+/t/ie4mAVN7mANfvs/Oo q9Lgv/QozmjNACIWL/G5uUtfL/tLYcrpKnleEXqE= 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 7373E385773A; Thu, 14 Sep 2023 06:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7373E385773A 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 38E6m1er029489; Thu, 14 Sep 2023 06:51:21 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n4xahrn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:21 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6or9m026256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupr027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v11 30/40] libstdc++: Optimize is_pointer trait performance Date: Wed, 13 Sep 2023 23:43:09 -0700 Message-ID: <20230914064949.29787-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: S07oUEjGbV5auGHziSwSWslyQfn9llnp X-Proofpoint-ORIG-GUID: S07oUEjGbV5auGHziSwSWslyQfn9llnp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 bulkscore=0 mlxlogscore=334 spamscore=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997371839653001 X-GMAIL-MSGID: 1776997371839653001 This patch optimizes the performance of the is_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_ptr): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 3711e4be526..4da1e7c407c 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_ptr : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_ptr { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9c56d15c0b7..3acd843f2f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3254,8 +3268,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Thu Sep 14 06:43:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp163326vqi; Thu, 14 Sep 2023 00:08:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMyMnAKCNy6s5J/tXMRHzjDuOkKUWFy2HxscmEv2rM0lYgrhxvSuOwjam6Q7WqtHirsd94 X-Received: by 2002:aa7:da8f:0:b0:52f:3e8c:84e8 with SMTP id q15-20020aa7da8f000000b0052f3e8c84e8mr4393300eds.16.1694675282664; Thu, 14 Sep 2023 00:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675282; cv=none; d=google.com; s=arc-20160816; b=r5QkYS60btuMSdOLPwqsX/Jqz1s1kvv8oyjnROz5uO8rocA4r2FdGfbf+SmevHV7zy h+JlgdzQPPe7b58FNqvzPtht7Dz8krBTv9DsL3JLzwHxcFMeJO21NSwlxETVKgWZqN1C 6B7LPIeMlDFHsSF65/ohDGk2eLlyp+sBXPvIUBMVSi3htNanBDqgf8J2Rc+A7cEGs6Fn iMdDKCPsTmc4Hq8QG1Iqs4/mPzQX3Ucs/+L1sl+5aOc0Lo5X+BpRPj/vXeEnRSxLKCtY roDW+h3I0lLIKIwt3R331qrIf0U+qXGQoXtQwL6v+U3FsAQL8pTGZ53ET9nnP7rkJRqw wThA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=8vRjhCpNePR7TEx6PiM/pQ8r5BWurLoHDzhylApP1dQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=pqV7tmA/exk0WUo4PhiosIKdhxtdUytJjC+sEvNiGx4+c5hZ9/HTZfpqGriEf5ya8L dFozJU606Q9ls3ArnRuYo73Bd059aogJ2nhcu/tH/qK8VDRAC3pxR2OtBp+HJmm025sH 7lf+jcYpWEGKzdzDM9oUXC/eF/434zgdQfnO+Xq8l3Q9RMJU7WorgQSg0JqlF7E5YfCP qranfRfk/eVcbQNbqiOjnPKuQUAO9TWu7pSUfKrdTHteUweyDxzmkEclf/DusRH/q/Kf A1Q3T9njb5RDk8duyAtk7CxIr5pAUvuhQrM2MrLWQ4d8abcHHCUBnW5Vuexx7TgfxTJ9 1l5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n4KW4G2F; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v17-20020aa7d811000000b0052e925193a1si733937edq.546.2023.09.14.00.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:08:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=n4KW4G2F; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6004039960C0 for ; Thu, 14 Sep 2023 06:56:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6004039960C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674619; bh=8vRjhCpNePR7TEx6PiM/pQ8r5BWurLoHDzhylApP1dQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=n4KW4G2FGiX/sKgxdY47SNPCx1lGPLSk5KnlDEVhUKPfLRQpIe5B6HPl6PB0dNAKl 9H0lVKVFw7/EoO95ehHLJZJbgTtQSJsZxVSuWJFnVD3BnBFjlf9qaELUcvUTmYibTM W8aikWj8K07FO9NGOLyJCtmexyIH/ovz2sduQ8p4= 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 7EE3D385E019; Thu, 14 Sep 2023 06:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EE3D385E019 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 38E6iWY9005674; Thu, 14 Sep 2023 06:51:16 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n8djeqx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orIP032287 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nups027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 31/40] c++, libstdc++: Implement __is_arithmetic built-in trait Date: Wed, 13 Sep 2023 23:43:10 -0700 Message-ID: <20230914064949.29787-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: hoCNRNKQ7S5SfS7UJtvPnd2rS4wh4Kc9 X-Proofpoint-GUID: hoCNRNKQ7S5SfS7UJtvPnd2rS4wh4Kc9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_03,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 bulkscore=0 mlxlogscore=959 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995829201979099 X-GMAIL-MSGID: 1776995829201979099 This patch implements built-in trait for std::is_arithmetic. gcc/cp/ChangeLog: * cp-trait.def: Define __is_arithmetic. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. * g++.dg/ext/is_arithmetic.C: New test. * g++.dg/tm/pr46567.C (__is_arithmetic): Rename to ... (__is_arith): ... this. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_arithmetic): Rename to ... (__is_arith): ... this. * include/c_global/cmath: Use __is_arith instead. * include/c_std/cmath: Likewise. * include/tr1/cmath: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_arithmetic.C | 33 ++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 6 +-- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 4 +- libstdc++-v3/include/c_global/cmath | 48 ++++++++++----------- libstdc++-v3/include/c_std/cmath | 24 +++++------ libstdc++-v3/include/tr1/cmath | 24 +++++------ 11 files changed, 99 insertions(+), 55 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 bc2bb5e5abb..06c203ce4de 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/semantics.cc b/gcc/cp/semantics.cc index 4b73863ec77..351f453356f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12128,6 +12128,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; @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index f08bbf6fd7b..79d304e0309 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -217,16 +217,16 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; template struct __is_fundamental - : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > + : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index be0689096fb..da592b9fd23 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -25,9 +25,9 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { + template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4da1e7c407c..51ed5b07716 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // An arithmetic type is an integer type or a floating point type // template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; @@ -398,7 +398,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index 6461c92ebfe..a0ddc1dbbeb 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -1259,8 +1259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1285,8 +1285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreaterequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1311,8 +1311,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isless(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1337,8 +1337,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1363,8 +1363,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1389,8 +1389,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isunordered(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1401,7 +1401,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -1411,7 +1411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -1420,7 +1420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -1429,7 +1429,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -1438,7 +1438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -1447,7 +1447,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -1456,7 +1456,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -1465,7 +1465,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -1474,7 +1474,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -1483,7 +1483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -1492,7 +1492,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -1501,7 +1501,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/c_std/cmath b/libstdc++-v3/include/c_std/cmath index 588ee1e6dc4..c1db699ecdb 100644 --- a/libstdc++-v3/include/c_std/cmath +++ b/libstdc++-v3/include/c_std/cmath @@ -467,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #undef isunordered template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -477,7 +477,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -486,7 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -495,7 +495,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -504,7 +504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -513,7 +513,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -522,7 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -531,7 +531,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -549,7 +549,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -558,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -567,7 +567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/tr1/cmath b/libstdc++-v3/include/tr1/cmath index ba1b60cc945..2e80f1d0d00 100644 --- a/libstdc++-v3/include/tr1/cmath +++ b/libstdc++-v3/include/tr1/cmath @@ -307,7 +307,7 @@ namespace tr1 /// Function template definitions [8.16.3]. template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -317,7 +317,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -326,7 +326,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -335,7 +335,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -344,7 +344,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -353,7 +353,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -362,7 +362,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -371,7 +371,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -380,7 +380,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -389,7 +389,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -398,7 +398,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -407,7 +407,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { From patchwork Thu Sep 14 06:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp167558vqi; Thu, 14 Sep 2023 00:18:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlzTO6w49nflhM50+U0pEwScNVop7z4SJ9rKCrN42xqCTZkOpgWBAULs0mifuUhRxtGYtQ X-Received: by 2002:ac2:5559:0:b0:4fb:9469:d659 with SMTP id l25-20020ac25559000000b004fb9469d659mr2976601lfk.23.1694675911312; Thu, 14 Sep 2023 00:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675911; cv=none; d=google.com; s=arc-20160816; b=enFFbZU5wE9gXzCXziyfpugnTSlRAuDzDRuwgWw70bURyQtWFoh9fYnPWK0M9QIwXx ZT6Wd7E1QSB0N0m2azXwGpbUG5iCNH1Ydftmi11jrXDB/Efr2HkjopDh2Bz6YtMkciyu Xb2oOljraOEIyemzoTRelLjnymAbDUIubm2Tw5yS7S3oNcQ2np+O+qU4zED27BV0eEKg cV8J9n3dHWIBbODea/tN/fTC6iyZ3VT+8qtv9Cyxym4bRn7pj4SVvcD9dcnFROagtTH0 dGHykONg+KVdpQ3Qg7F0wLxKr4KpirQTSJHM2HHy6UAlhbdaF5uBrA3b7+02fbvfBdEr aXqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ZMrWPcLdssxj4TFvVZB7FqS0yLbTeN+Z2NeTGBWNBHrWk1bqX9ZQQlAsUzqcfwWUQ8 OedAQzoxaKCAmQtt6VEV+T2DTDUcK6SjKyx1lhhRrS6JrVrK+uiNGgVM6KWkq+6xyC70 lrJ/hshKxa5TAbuXYLghmrcAjHeDzrjRHcMVX5ogyld0vc8t5Pr/47bJ/KD4namGTO1c 04FJER0OXAcGtOpIL+GPwJJ1yZao0aE023jNIzPrAZ0kTAgW759gAwNQzV0NJ61oyaG8 qpU5QdCQNQb+HmzOQ6bvoPlq+7NFt0Qh90DUd9XxvYjUKZ0svRCgVLaH4oG5pvCWJTf2 s6rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=clIGaDk3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bf15-20020a0564021a4f00b0052a4b8075cesi863864edb.402.2023.09.14.00.18.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=clIGaDk3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC2D5382E6B6 for ; Thu, 14 Sep 2023 07:00:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC2D5382E6B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674824; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=clIGaDk3EYeOhf9OBlEnDGuMQN1NSHtXxnGEOqrRfXI8UZBiGa8usC6SZgr7lQtSN 9XV5evUh05vIRfHoK425FIwe/bLe1MYZOo6xqYgA1ULtiuBLKb7lLwEpjcYUasFTk1 I0GWG1z9ZqeoN+9L2nU7w8mzhbYJQz4qLJjzsVkI= 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 83D3F385B81D; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83D3F385B81D 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 38E6iY4r007559; Thu, 14 Sep 2023 06:51: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 3t3mfbaw6p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6orD0006967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:53 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupt027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 32/40] libstdc++: Optimize is_arithmetic trait performance Date: Wed, 13 Sep 2023 23:43:11 -0700 Message-ID: <20230914064949.29787-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: _vgCS_7HUyieR3IIY7EeEeiIh94FWfgP X-Proofpoint-ORIG-GUID: _vgCS_7HUyieR3IIY7EeEeiIh94FWfgP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 impostorscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=652 priorityscore=1501 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996488688417878 X-GMAIL-MSGID: 1776996488688417878 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 Thu Sep 14 06:43:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp167509vqi; Thu, 14 Sep 2023 00:18:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpnBsE2oz6JGgmZOtgS9E1cVkXUzLTB40nt3oySbuHYYB5tlgkT/Ycq/XWWti+/MFD7xYf X-Received: by 2002:a05:6512:238a:b0:4ff:834b:e01b with SMTP id c10-20020a056512238a00b004ff834be01bmr4923468lfv.19.1694675900373; Thu, 14 Sep 2023 00:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675900; cv=none; d=google.com; s=arc-20160816; b=YZG7UmkER/kIrGlakIJFtAIdg6D2DBwZiNKbsQ+t4IrWx7BfZOvoeahEVTWSXt2UsQ +mkJ8MW9hQFcRwHgaRGyKgPxhmInBOgihDs/W4JXO5gYMxCfTN9pxz3bq9Bq/xScSlds Ygrx/X6RoYtONxwFjSJ25ubVjZHU1Rmg3IhXn18+Sf6kjE2xuZ3gSeeqNjzvPyXJlK5r +JNIIOZj2k8o2cdTJEtSW0Q/nwKwcGdjTpwFJFOBLykZ+6dQcev0AWgJ13hcDcEvC4c2 S56gXfYQW+pjSqdQD+iFy+vJHQDFUd3kXJe3ss2PfK7dQ7m+U3l97Iupwz/OK6CuvaDx eWpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jjEh17QN9AmSvCTND6kKg6obim0ZomAIQHcWdhDMGnQCzfYLR62zLCcNeGmOpUKtw8 y3iZiP7CMGrPHaCAFq9EoNWkOlrm7ZdDPHC2IX7HgAU9vmz/97cEktPJXgEJQW+xPuPu hNSf5QinwzkxTG9Y1X8bMalpt+Vm7JrvBkWMUK9SO6Dl7TSBNy9vo8l/dUZic4Kc5m6E AuHhtBC7NxOOctRRJQNAft+FsMquT6zOOHaVXC3Lp/B0IjwFLyQX+h6eHCyf0vxkLiGy uWOX6Hk1Vd2MKX5b17hWY0A4GoiC1W/HagDzI0TtcxSWCwjS9gTWyR8uvI3vHTa0wa7W M8Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HAvzzfdO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z14-20020aa7c64e000000b0052a1a79597esi776938edr.655.2023.09.14.00.18.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:18:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HAvzzfdO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52B3F3890970 for ; Thu, 14 Sep 2023 07:00:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52B3F3890970 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674820; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=HAvzzfdOjrhdQKFa6MBaKRsq8736rLqj+pEcf/DnhQBSQY+tFygSkeA9AO/BmW94B qiQ/EymCtHESuXN7ha0ZChc/uq5MUDkA/5kuCVT/DghX+f0SUUpcNZbT/fkVUuSrY8 VIDVN7vfXMeW9ng+mp8SR73ntKPbsJax4CF/UPmQ= 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 986DF385E03D; Thu, 14 Sep 2023 06:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 986DF385E03D 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 38E6fVIm014102; Thu, 14 Sep 2023 06:51:16 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3rxxgvfe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osi7032288 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupu027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:53 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 33/40] libstdc++: Optimize is_fundamental trait performance Date: Wed, 13 Sep 2023 23:43:12 -0700 Message-ID: <20230914064949.29787-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: odEQfv1y9_23-mPk-JOwVRoafDakND4D X-Proofpoint-GUID: odEQfv1y9_23-mPk-JOwVRoafDakND4D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 mlxlogscore=538 malwarescore=0 bulkscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996476757191546 X-GMAIL-MSGID: 1776996476757191546 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 Thu Sep 14 06:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp166400vqi; Thu, 14 Sep 2023 00:15:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHauRVlxeOA/UMF76OZuN03do6odwNRZMBA0FlNWIw1nFTp7a7v5A5Hxwl3bO9anA7mcAnC X-Received: by 2002:aa7:da04:0:b0:522:3ef1:b1d with SMTP id r4-20020aa7da04000000b005223ef10b1dmr3570270eds.6.1694675725617; Thu, 14 Sep 2023 00:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675725; cv=none; d=google.com; s=arc-20160816; b=guHU0J78txg9kKBQwMSdruLK+Ac8mKBwNn8vaH9dVUDsl2ieQJFMJJqnkr0VLMsYAH SqJh/kHYYw5lR3keKnI/6LbyuViLmZ8X3ZKSyqkk6Md1yZHnN+jLsthN6ZYzCrvwTvYg stGTmbqZpyuhHEgb1YyvazDk/ohF/BPvZ700bAoUX/+i/dHZbz/aqonW+DPrlSKjGUOI Co0mwOLGNX8GTqQDWSe7+r0FL62rl+JXut7oAV69zY3l+Jwwl5NdONJA38BcvUkWCF2N YM6pzqO/Xm6bBKSzY54OUOpWlCbEohN+2hh9LUeT+VWfgqepP6n/es9QpuKAQGzZuTZk cr3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Xhyx27fOo9ghJHTzSZCpuVSXSz0iAsaSZ+0cTk4QpAaAj3VNYEOXSsEyzAYd1K8V6p NrFN5IbMmRkcTs5em0ZYZ2q3WdAvTiMupk/2r/iA0rjIPJvLSRTEAw6BxaJ4wzB9e6/9 kgU4FjBNG+TolDQB3YjDUctlz/+A7btWyKzB2cE0LZF5NDaGKfmtd0An07cOi0ay8FIu RVd+htfDT7W5s9FpWDmgv68hYkWmCMMXlEMNjDf5mYFi2ZIOXD3TIps895KLKFtnTzLb e6JjQQkTu8i4hSksNkvkGn3RbDntCFbsj5nlbYV6cPGzJtT2uTc3urF225NeFUgCmQcN ohqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j0kbdkWY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u18-20020a056402111200b0052ed507d45esi819954edv.111.2023.09.14.00.15.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:15:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j0kbdkWY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5D1B3891134 for ; Thu, 14 Sep 2023 06:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5D1B3891134 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674759; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=j0kbdkWYrUSFfuZG0BmSrknF49ppEFvi2tBOVkhuscEea/y7BE2QcNVJo3Fw8s57t /Ab2XbpY1zO9h4GGSURK4OW3U16gPvaFi36kLOjZVXFznjyUEsGP3M0nIKx+Dw3O9H v75OZIMg4FrPRfjOu4QpwUctRNEnFUwHk91ztNMo= 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 9ED193857027; Thu, 14 Sep 2023 06:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9ED193857027 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 38E6iXoV031406; Thu, 14 Sep 2023 06:51: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 3t3hdbvwfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osUN006968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupv027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 34/40] libstdc++: Optimize is_compound trait performance Date: Wed, 13 Sep 2023 23:43:13 -0700 Message-ID: <20230914064949.29787-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jflKFUcSYfvuRrHj4lw6u0ZJk1yFZTdw X-Proofpoint-GUID: jflKFUcSYfvuRrHj4lw6u0ZJk1yFZTdw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=602 suspectscore=0 clxscore=1034 phishscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996293852351903 X-GMAIL-MSGID: 1776996293852351903 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 Thu Sep 14 06:43:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 139378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp166291vqi; Thu, 14 Sep 2023 00:15:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/J2dePl27mjfnWnhK+rZo+XyXDVYq9WUuSuG56KQj0n3XMgpITc8huCIGy0Qw2/bohbUN X-Received: by 2002:a17:906:3051:b0:99e:6a0:5f64 with SMTP id d17-20020a170906305100b0099e06a05f64mr3602515ejd.36.1694675711137; Thu, 14 Sep 2023 00:15:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675711; cv=none; d=google.com; s=arc-20160816; b=SSm3J1x2VWis4SC7RJNCVge5NUqTE6GseORezmSqR7o38KzPiRaHub27ver0i/xwS5 4g6yih3TmabydRxqMy2Xg33EOAtKmSFrWaDUH3zLOI+2y2Xhl+/VpHv21a0EDvoz2hZs p2E9yJ0QCPQUyciLu01ik0SzaWvys+h6GXLaOhcWvs5FNYT9MTgVxt2mgYDoSCxWY3/6 /Ih4wRW7S7oUIb+fK7A77j8orSa4qSGLvllQ6IQJ28BayHJ2U6P7kthQRiKgvii5CsQL kXUEhayc3slNLtmC8P/T3PViRW96j8e0tS5RCECeQtCbtieud/d0DEETT4TMNzP1Z4ZD Ckxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=QlxIOteGGBo0yXhidwh2L7+cweX7cSNcf1j4RuLqZt4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qygq2vYK9WWP4sMBitf1KI92n7gqmnnkIiLeXVdfM1mINcDts6lzzNg2R677DDsd9L YkSzdrIfPU1aNGGBa+9Qs6iYtm9MDQSo5g627G2ZfmWVPlrmpJbVaN1UWciAhUAj3OeO C1rg4riSaeU5IEV4qkCfNAljdmLkj0jRo3z6Afl246jD3ulN3M/FUfY+WdDcCV9zO06x 3yxjEC/ZA2bzjU55trs4MxRmDBzZhAZPRXPpR05b7cU8iJB0oQfV5tEfyC8RuJnqjplr GVO2eKB9wqm/NzJH3XU+ItcEp/qclbmUcL0RPHkLN/1rtjcm8NzaRI0ANNl347J6A3BA j86g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xLicfFF0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j14-20020a170906050e00b00993860a6d3fsi712465eja.281.2023.09.14.00.15.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:15:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xLicfFF0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32DA43883017 for ; Thu, 14 Sep 2023 06:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32DA43883017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674755; bh=QlxIOteGGBo0yXhidwh2L7+cweX7cSNcf1j4RuLqZt4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=xLicfFF0Gc4KMAJotgk0b6B/errIcFYsHoG/uTN36vwK+D1JKoskQ3x8WUfCLkL4G gDXKw8vblrxICn7VidxEa86lHRcnITdCBD1D/qBK/ZzbX6wu9JuULrjqd16eI9IdX/ hvB4wmGbogwN3MrEZc5TvmVZQtnxXe38XDJPgdf4= 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 2969F3858296; Thu, 14 Sep 2023 06:51:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2969F3858296 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 38E6pBUx022221; Thu, 14 Sep 2023 06:51:11 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3nrsj5v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:11 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osVK020555 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupw027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 35/40] c++: Implement __is_unsigned built-in trait Date: Wed, 13 Sep 2023 23:43:14 -0700 Message-ID: <20230914064949.29787-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2XQoL2fC6Z7vH7vRSfDa0wySUUGQfh6L X-Proofpoint-GUID: 2XQoL2fC6Z7vH7vRSfDa0wySUUGQfh6L X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=807 priorityscore=1501 impostorscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996278564175547 X-GMAIL-MSGID: 1776996278564175547 This patch implements built-in trait for std::is_unsigned. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unsigned. * 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/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unsigned.C | 47 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+) 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 06c203ce4de..611e84cbbfd 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/semantics.cc b/gcc/cp/semantics.cc index 351f453356f..74bfd5f0961 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12235,6 +12235,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); @@ -12410,6 +12413,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 Thu Sep 14 06:43: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: 139360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp157909vqi; Wed, 13 Sep 2023 23:55:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrSRXbnviBoJ/qyyUkxiSEEnFl5RwbZQYEcvNe0BIxWQfCUJKgt0Zn3GLpAU5R/U03b8eJ X-Received: by 2002:aa7:c04e:0:b0:52f:a763:aab4 with SMTP id k14-20020aa7c04e000000b0052fa763aab4mr1291376edo.5.1694674550543; Wed, 13 Sep 2023 23:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674550; cv=none; d=google.com; s=arc-20160816; b=F2M7UIQFl9swLsWlGRv+vKONBsp8uiFfmc3Ju7ohIOCoW+lrh2hMGUhsBdm/AewMMt 0jLA1JVgG7BVwhEEKtluKdTNOXb0W8RPJz97gbdKoRbt2w5wSAUdPCpOeuINwl8AIeel fti6xHGGLd6T2pcnH0RY8k7cN0zFtc2CyAY0RZkAGl7zGpJ2VBPsFZ9DoUgo0qvWTh48 L/QhBwjwTFuoJLGd2rws3p1zCaoLO2nXn4HTF9CJdfLppvRqA5c5MyNS9kbAUAG96VUy Ka3NUIU7gnBqRoir1YlVPIaOZoYum0/v88suKkAM6iswtSprFg/ETno/ggLR5u1l7Brw q+OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Wr+2wZpMUm3comJNWlmk/kzFgE4mJkGGOjdmxwL2WbArobpiZ/W1kiRmB68lsyyRv2 keXUcRnutYUJ7Rm3/Z+iwGXxOZBYZpL+u6C4gu2c6DPeUfszMVIOqXYq3ymDCZrE63xK RcTFqegkOnHbOwR8mIcrW82MlmoChP8V2GGwXtg+/qMeOfie1e1oab3USYJZ61GPPqVS t70vJ9u9lax8XxQb7AqzOMvaaUR2fPeeeQ9XZj/wEbaGBHoAup/0TVhGkMU6lE0Deq0L o9z5K2ij/eI6ClcHgHEvaomx818q/Aur59t/OVUsSBgRV+nUAYJLl2OFPUSuHx+oUKPx 3d2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LoTFjjcn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bm19-20020a0564020b1300b005233f1e68c0si786820edb.177.2023.09.13.23.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LoTFjjcn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F96D3889E2B for ; Thu, 14 Sep 2023 06:52:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F96D3889E2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674377; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LoTFjjcnmUCOOcQuQKCZtteUgOP80FZQ+i8gCXaGbN0W2aCWU12kTZkxqc+qjETiP LDGeGgqzvLjAsKhhU2myXNRABucEF10Jg+2x/oB6T2REXHHiC/HSU/lGh5gnqhQTOO hW40//ijUuofQAQnowCGad//9zUdscQodfEb59Sk= 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 18BA23858296; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18BA23858296 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 38E6o8bc025560; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n5v2gka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osPP004237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nupx027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 36/40] libstdc++: Optimize is_unsigned trait performance Date: Wed, 13 Sep 2023 23:43:15 -0700 Message-ID: <20230914064949.29787-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: TH_Ws_LsaxCbbsb2E33g0_uzz7cN58vt X-Proofpoint-ORIG-GUID: TH_Ws_LsaxCbbsb2E33g0_uzz7cN58vt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=757 suspectscore=0 adultscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1034 malwarescore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995061376064333 X-GMAIL-MSGID: 1776995061376064333 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 Thu Sep 14 06:43: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: 139362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp158659vqi; Wed, 13 Sep 2023 23:58:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4uD0+CdNo5d3TALdKyS6kNjL6GoHsJ94tv/TAgI7YMAAv3NJ4mN7elIJs1ODlyWdo5Kl0 X-Received: by 2002:a17:907:60ca:b0:9ad:a75b:cdd2 with SMTP id hv10-20020a17090760ca00b009ada75bcdd2mr1242593ejc.34.1694674692978; Wed, 13 Sep 2023 23:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674692; cv=none; d=google.com; s=arc-20160816; b=kjd1oUvnAroPKqw8sQt5ev14wmYMVbraHXvadlcEgA/paA1L1ulBWEv+ez/SWiTHWm qZxO4wehfVSIpxnwz4gT36/1QU3lj01FgndKGP6DYXyZFzp6Jt3SDy1ZMGLEnkvUf+pF LjcIvXNtZjxlk6utf8fXEyNJZYDC2v8BLNpcX3AXq6qdm2HSvwHfWWueNizuGuIcIMRB 0wYiz6PJnw5DiNHU4Z+1dHtNFFXH/5gv1mhHTPct2XdhTfHwkYIUZGffSrEq0Oj7hvvK N3t5bukAT9LVW/Mi3q0vTgueaXkH9+suIOPr7QZfCYk51xZsbgH9HFrD/oPu08AKpe7h D9Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=CQgWqZt1wnooXMXgOp4gYUTgHR++9FvPDNVWP+7VwK0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=liqJluVtR3GFagm35DCpOEzlc5KsncWnSv5Skc2vkcdRN0ZCcZzFzPEElEcVI45Tbt WeoYILqbhp4R06RU8lQguvPwz9nSPNOYqRkTbV6kbn55w1MmI6KZ/SLW+QfH9vdq+Zzv UhTCMFCT1pGtAoxlOT+tidd2jAYEltRTPiWEVQvfDTHMur4BM0fYBfPZabO0Kvp6wn7v VewLlE0fWXncmHI+500CKsDCVDwwrTv6di9Fej3H9t7oMdT7dIVULSIIiwpPwDYp7MHG lugkyhTX3/T2gL+Q7MXlNuSyk40O7Ag7G0S5XXBSrf1/pjPAu09omTiuMtP9198CzDz+ Sokw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="K4eI/Abc"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n2-20020aa7c682000000b0052257d9655bsi720722edq.304.2023.09.13.23.58.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="K4eI/Abc"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F5A23898516 for ; Thu, 14 Sep 2023 06:53:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F5A23898516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674436; bh=CQgWqZt1wnooXMXgOp4gYUTgHR++9FvPDNVWP+7VwK0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=K4eI/AbcLDACugE/Ehj7HdgIKRDQmGuglOYi0EPK11YIXY2BNaY7jikKdSF79bDeD Jp1YIoOd3hR4fWNeScpDEtij/qlpoD9VHSnNCQ6osdWgG/6UyMxgGHGnoVQ0WEm+sp xCiQ4bJdiytKrTECyaVNtPtfs8erzgFrSH8z4M8g= 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 7A1673856DDA; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A1673856DDA 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 38E6keKP010201; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwafm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osEp004238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nuq0027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 37/40] c++, libstdc++: Implement __is_signed built-in trait Date: Wed, 13 Sep 2023 23:43:16 -0700 Message-ID: <20230914064949.29787-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: eO1c_VCli6YRprMQVNHItftgG0dj5mnY X-Proofpoint-ORIG-GUID: eO1c_VCli6YRprMQVNHItftgG0dj5mnY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995210539754822 X-GMAIL-MSGID: 1776995210539754822 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. * g++.dg/tm/pr46567.C (__is_signed): Rename to ... (__is_signed_type): ... this. libstdc++-v3/ChangeLog: * include/ext/numeric_traits.h (__is_signed): Rename to ... (__is_signed_type): ... this. * include/bits/charconv.h: Use __is_signed_type instead. * include/bits/locale_facets.tcc: Likewise. * include/bits/uniform_int_dist.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_signed.C | 47 ++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 12 ++--- libstdc++-v3/include/bits/charconv.h | 2 +- libstdc++-v3/include/bits/locale_facets.tcc | 6 +-- libstdc++-v3/include/bits/uniform_int_dist.h | 4 +- libstdc++-v3/include/ext/numeric_traits.h | 18 ++++---- 10 files changed, 79 insertions(+), 21 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 611e84cbbfd..f0b5fe9cb3b 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/semantics.cc b/gcc/cp/semantics.cc index 74bfd5f0961..f5aa78adf16 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_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); @@ -12410,6 +12413,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 79d304e0309..c891aff20f4 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -403,7 +403,7 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { { static const _Value __min = (((_Value)(-1) < 0) ? (_Value)1 << (sizeof(_Value) * 8 - ((_Value)(-1) < 0)) : (_Value)0); static const _Value __max = (((_Value)(-1) < 0) ? (((((_Value)1 << ((sizeof(_Value) * 8 - ((_Value)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(_Value)0); - static const bool __is_signed = ((_Value)(-1) < 0); + static const bool __is_signed_type = ((_Value)(-1) < 0); static const int __digits = (sizeof(_Value) * 8 - ((_Value)(-1) < 0)); }; template @@ -411,21 +411,21 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { template const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; template struct __numeric_traits_floating { static const int __max_digits10 = (2 + (std::__are_same<_Value, float>::__value ? 24 : std::__are_same<_Value, double>::__value ? 53 : 64) * 3010 / 10000); - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = (std::__are_same<_Value, float>::__value ? 6 : std::__are_same<_Value, double>::__value ? 15 : 18); static const int __max_exponent10 = (std::__are_same<_Value, float>::__value ? 38 : std::__are_same<_Value, double>::__value ? 308 : 4932); }; template const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; template @@ -1513,8 +1513,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value - && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed - && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed_type + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed_type && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index 20da8303f7a..1acf1e46e4c 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -46,7 +46,7 @@ namespace __detail // This accepts 128-bit integers even in strict mode. template constexpr bool __integer_to_chars_is_unsigned - = ! __gnu_cxx::__int_traits<_Tp>::__is_signed; + = ! __gnu_cxx::__int_traits<_Tp>::__is_signed_type; #endif // Generic implementation for arbitrary bases. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6bfff7d6289..38a6920abe9 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -470,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL bool __testfail = false; bool __testoverflow = false; const __unsigned_type __max = - (__negative && __num_traits::__is_signed) + (__negative && __num_traits::__is_signed_type) ? -static_cast<__unsigned_type>(__num_traits::__min) : __num_traits::__max; const __unsigned_type __smax = __max / __base; @@ -573,7 +573,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL } else if (__testoverflow) { - if (__negative && __num_traits::__is_signed) + if (__negative && __num_traits::__is_signed_type) __v = __num_traits::__min; else __v = __num_traits::__max; @@ -914,7 +914,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL if (__v >= 0) { if (bool(__flags & ios_base::showpos) - && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) + && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed_type) *--__cs = __lit[__num_base::_S_oplus], ++__len; } else diff --git a/libstdc++-v3/include/bits/uniform_int_dist.h b/libstdc++-v3/include/bits/uniform_int_dist.h index 7ccf930a6d4..73b808e57f3 100644 --- a/libstdc++-v3/include/bits/uniform_int_dist.h +++ b/libstdc++-v3/include/bits/uniform_int_dist.h @@ -258,8 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using _Up_traits = __gnu_cxx::__int_traits<_Up>; using _Wp_traits = __gnu_cxx::__int_traits<_Wp>; - static_assert(!_Up_traits::__is_signed, "U must be unsigned"); - static_assert(!_Wp_traits::__is_signed, "W must be unsigned"); + static_assert(!_Up_traits::__is_signed_type, "U must be unsigned"); + static_assert(!_Wp_traits::__is_signed_type, "W must be unsigned"); static_assert(_Wp_traits::__digits == (2 * _Up_traits::__digits), "W must be twice as wide as U"); diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index dcbc2d12927..c618f211775 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -67,15 +67,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: these two are also available in std::numeric_limits as compile // time constants, but is big and we can avoid including it. - static const bool __is_signed = (_Value)(-1) < 0; + static const bool __is_signed_type = (_Value)(-1) < 0; static const int __digits - = __is_integer_nonstrict<_Value>::__width - __is_signed; + = __is_integer_nonstrict<_Value>::__width - __is_signed_type; // The initializers must be constants so that __max and __min are too. - static const _Value __max = __is_signed + static const _Value __max = __is_signed_type ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1) : ~(_Value)0; - static const _Value __min = __is_signed ? -__max - 1 : (_Value)0; + static const _Value __min = __is_signed_type ? -__max - 1 : (_Value)0; }; template @@ -85,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; @@ -161,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -170,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; @@ -210,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ibm128> { static const int __max_digits10 = 33; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 31; static const int __max_exponent10 = 308; }; @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ieee128> { static const int __max_digits10 = 36; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 33; static const int __max_exponent10 = 4932; }; From patchwork Thu Sep 14 06:43: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: 139370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp161074vqi; Thu, 14 Sep 2023 00:03:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEra0ysIORtC6rN+z1BM4uPfs8KmzRpdZPhXS9CW/qKLDvTGFspYRv6bLeieNwQvBKCs86D X-Received: by 2002:a17:906:846c:b0:9a5:d095:a8e1 with SMTP id hx12-20020a170906846c00b009a5d095a8e1mr3643354ejc.11.1694674995393; Thu, 14 Sep 2023 00:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694674995; cv=none; d=google.com; s=arc-20160816; b=buN+N7uaszywpKPnGGIvOn0s2R9o6JU/ExSN6AC8/YebYzxJ0v2yqBEYLufO0aQShH RHl7OjAa/JinAWDrtJsl1DIf/S34yf0UzukrllCJmWHXQ/KeiM0G4aMCSP50yteLwwYB j9OoxyFgNPtyeKZB6me+JR7Lbs3Mujc5N4Pbw4ctOs9fdcfW2uRidqjcsSaowUTx4GyA 9H55Eu5NqouBcaDJ3h9Vx6WUCnFl7dwJfpAzmk+x+lo27cTzo+GEq2+Tz0/34uxyJdvX Ren/kTIN9Rt+3WcEsc+KrZQZXtGs7mkj/c1LlR7tOUhisJ8l01PXYJCtJatsnvXLPXuk VPDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EGSYJECbToc1qLdI1Vh6iUTpjT38JENFWR3TnSSRPawGU8tW/9f+BI54JOjFUQAajl hPfFs/W/oCWVC5M02+oSgUd0SZo4mda60RNAqJQjAyEXAZaS2Fp4BCxyaidMEIsEqFZA iynwomPwFOKK5Ql7yvU+kDiisxJTUfTTpgznbmThr0vmjBJcMwqsCLBCM6VT1vUicXrG f0rKpAZrTwD2yNv0atWSu71Ns1D9LlV6d6deAZ7aWC2HFr/5eAuXrN6ZS1BLkTcsihzJ WppMmQ5dNuULZvfLaBRl+fWyi9i02MTJRLtjvZFNHLVryANMSnMWYgUDegNO8Legm+3y +aHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XMl6D/7p"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j14-20020a170906474e00b0098821ac27b7si768894ejs.39.2023.09.14.00.03.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:03:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XMl6D/7p"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DA08385DC2D for ; Thu, 14 Sep 2023 06:55:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DA08385DC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674536; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XMl6D/7pCfi06Let2jgJs0rPg2lclxqTiE24bLguzr6NKY1fc4ZYzx1iZVUOFSRao Uprvk39wuU+ixcgFZwvv0MEw0cU1zlEv0SB1wYGU9OaTYS91D8247VwICxC62GtO+u cub5fAbkh9X1Zke5Nq3cEKXck8nvxnJqW6eHw/Tw= 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 D27EB3857029; Thu, 14 Sep 2023 06:51:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D27EB3857029 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 38E6kMGE009453; Thu, 14 Sep 2023 06:51:11 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwagb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:10 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osNR020556 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nuq1027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 38/40] libstdc++: Optimize is_signed trait performance Date: Wed, 13 Sep 2023 23:43:17 -0700 Message-ID: <20230914064949.29787-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: h3d16UzpBcfvTmUIbIIOaeIxnA2m7_Mj X-Proofpoint-ORIG-GUID: h3d16UzpBcfvTmUIbIIOaeIxnA2m7_Mj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=736 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 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: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995527999111836 X-GMAIL-MSGID: 1776995527999111836 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 Thu Sep 14 06:43: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: 139374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp163327vqi; Thu, 14 Sep 2023 00:08:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGG3J0aOrJEkRlEC83FoBBJgxtUHoaLdEY8TrtOP1+rjndyLma5m1IFvlvBMzemzjMXswKx X-Received: by 2002:a2e:3814:0:b0:2b9:5fd2:763a with SMTP id f20-20020a2e3814000000b002b95fd2763amr3908006lja.35.1694675282654; Thu, 14 Sep 2023 00:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694675282; cv=none; d=google.com; s=arc-20160816; b=GmZ2ZZwsUK9cMvFOGmHmE5Fij0rVNRHiTn1eer0s6TLmzgFrGIE5texL3ln7Uk0pb8 SPcSt/y6x/iSUOr9w4zB4VOez4QlsL7izRJPwXBwTrx1pu5WgWo9PfGME8BEf2l4sjtU CvefC0r3oykSkNwthv3M1O7YOxKmLE/BdVDJhjnwQnMdHA/2LiNgBBl4jD6/wZ3Uf9D1 0HZmGMJvsC1kc989yanmXRdCT3fat9dDLWeQMIeD3swXnl5CFWwqiub3hpi4B99gwdn8 Uf/VYAVlZFFdHlAPrjYZLmzKfsUc35/1DwxLQh6fvJhlNFW/gcfhDO6cM5w1e9hhLE7j J4Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=JcEHdth5S5LQ0RWkaMv0lPc1SS6zte9qRozkGp2woZc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uOW784QLhaxwpMZbncF7CAaptLuEOh87vOS4By1EDP2fXxLL4PhXN4FQmsYXjo7w4Q 0+Y3p53LXLD60R6wLZlkt1VnDv82LGEpBnB3qgXW8c2ZKd0Lay8ofeg4Ujf06zwYqHol N3mW5bjCYSeCWbcQibhuP6Yse2VsmjO/hPpUEqxqBGzOiFRUVGHAaywj+nJLSLNoNJ1m retffApg7sS8tcRjohtIOXBKIwvCbdDt52k9g21brQ8U5O7TG+db0l/2OCYSl8GGC3NF t3hJdpy16EssR3fiYKn+Up06A9+jAIYv/N7FwgDqpXoGLReY9lcNGk3aQb1HdIlo1Ecb hcHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DRiYF+gL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e10-20020a17090681ca00b0099bd0683c1esi773890ejx.949.2023.09.14.00.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:08:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DRiYF+gL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49877388210C for ; Thu, 14 Sep 2023 06:56:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49877388210C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694674619; bh=JcEHdth5S5LQ0RWkaMv0lPc1SS6zte9qRozkGp2woZc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DRiYF+gLkHmMgSUUN/KXw0p30ZBtPZ2AvVwa/qk+ajfYJfWiI4j47YIoRUru9aN/E dFdWnyNRI2Uk6H4Lq5x79hSTdW5E8GmOF8QekYVCUmyM+Z1vLUStAQvV/eCFlrIDbQ I43H9Ech+G4KyATIblvH+yFlUtx9qz0XcYXYgD+c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 742723858031; Thu, 14 Sep 2023 06:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 742723858031 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 38E6M1xG017219; Thu, 14 Sep 2023 06:50:57 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3n4xahqq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:50:57 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6osdg004239 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nuq2027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 39/40] c++, libstdc++: Implement __is_scalar built-in trait Date: Wed, 13 Sep 2023 23:43:18 -0700 Message-ID: <20230914064949.29787-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: V7aUUpBgWy72W6aveUxeh32KBL7C0G1S X-Proofpoint-ORIG-GUID: V7aUUpBgWy72W6aveUxeh32KBL7C0G1S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 spamscore=0 lowpriorityscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 phishscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995829165627138 X-GMAIL-MSGID: 1776995829165627138 This patch implements built-in trait for std::is_scalar. The existent __is_scalar codes were replaced with __is_scalar_type to avoid unintentional macro replacement by the new built-in. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scalar. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar. * g++.dg/ext/is_scalar.C: New test. * g++.dg/tm/pr46567.C: Use __is_scalar_type instead. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_scalar): Rename to ... (__is_scalar_type): ... this. * include/bits/stl_algobase.h: Use __is_scalar_type instead. * include/bits/valarray_array.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_scalar.C | 31 +++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 10 +++---- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +-- libstdc++-v3/include/bits/cpp_type_traits.h | 2 +- libstdc++-v3/include/bits/stl_algobase.h | 8 +++--- libstdc++-v3/include/bits/valarray_array.h | 2 +- 10 files changed, 55 insertions(+), 13 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 f0b5fe9cb3b..4e220262020 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/semantics.cc b/gcc/cp/semantics.cc index f5aa78adf16..91631c211ab 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_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; @@ -12413,6 +12416,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index c891aff20f4..393f936ea72 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, ++__first) @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index da592b9fd23..4d2ef002e08 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template inline typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) { } - template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { + template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (__decltype(__n + 0) __niter = __n; __niter > 0; --__niter, ++__first) *__first = __value; diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 51ed5b07716..16980f5b356 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -397,7 +397,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // A scalar type is an arithmetic type or a pointer type // template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index d1438429487..4e334da0832 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -914,7 +914,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -925,7 +925,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1063,7 +1063,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, (void) ++__first) @@ -1074,7 +1074,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 222fd5fd900..558817329ce 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void __valarray_default_construct(_Tp* __b, _Tp* __e) { - _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e); + _Array_default_ctor<_Tp, __is_scalar_type<_Tp>::__value>::_S_do_it(__b, __e); } // Turn a raw-memory into an array of _Tp filled with __t From patchwork Thu Sep 14 06:43: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: 139403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp173840vqi; Thu, 14 Sep 2023 00:34:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZDsXPQwT8MHKxQULfJ0ebDmGKjOgbq0vqSsYiau3vl5+bZ443YI3MHYjcdFNbXXX9vsvd X-Received: by 2002:a2e:98d7:0:b0:2bd:124a:23d5 with SMTP id s23-20020a2e98d7000000b002bd124a23d5mr4210222ljj.11.1694676857564; Thu, 14 Sep 2023 00:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694676857; cv=none; d=google.com; s=arc-20160816; b=Gy9LEjpSY9nSBJulIWiFraj5767P1lWRBbj66NbxLqubKiVJe2p3deQl6ZSp3fjTAC OWgsW+vOGkF2bAAglDARFqlfJOipAo0cU1KLmufDdi0hGfToKw8ZW4Yy1C7wg/UDtOsv 4EIAlHo/VSB75HWomhTDtVQU5os0NUfFXg7cvrUrYXISk6scwmUovU2rSehVJr9neyFC inDlTmqixVF2lk8A0dZdO880HHdBmRSOPWqUWV4v6f7X3hYcpXeD75nIbKuU7TXy6TYw 3VPnmQVq1cGIyWLPvxbXrz+we6uqZk1mgv/oLfha/yFvC9WHIvMh/GfPz+9kffeYqimb YwuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PkxrU2jvYgAuvhkRabF+4UGqa2pnJpCqgLUnks8i9DjiI8dbBaOFsloQDxFelaSsxR ai/C4/1GYGDHLHZgkQPVJ0lg+UIdnp2UPUXsgjFFcisvCIPLHLd784qZ016oq/c+SLab SadzUpz13f9ZMIVEWBinnu0hu709OjAVrkQoTPflTsyqLB9pp29XIvG1DM+AAq19CHzn Ah0c71ELVnHmtRHaBRq71vRyvWF8g4dm3ylEiBLGchO/RL6Ygj9wvEw0CnxPvkz+SQe/ zG7YIuN+6XSx1oLiBbmibD2PFXF6Mb+UAZxarblEOKUTB+oNKDS6pZhw2wtVvIt0gFSh X+gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=V1qPLeQs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dv23-20020a170906b81700b0099bd00f8f73si755059ejb.742.2023.09.14.00.34.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:34:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=V1qPLeQs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 696093850DFA for ; Thu, 14 Sep 2023 07:07:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 696093850DFA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694675260; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=V1qPLeQsG9DywJtky6YfIamWrQdDfL6i3h2W2fLAMNU3pJVFG24txYgNtFj7QshL+ LVm7r4e7hbuOlQe196xw4lLkFYuCsIuwElyMOeK4kRYJs81zbhOqHs7SSnbSX9YzpO TosmLVGPybAS/zfPlHoXEEYFRWnjreCHYuvz5Gno= 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 62524385C6DA; Thu, 14 Sep 2023 06:51:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62524385C6DA 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 38E6pIh4018774; Thu, 14 Sep 2023 06:51:24 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3t3h2jwah0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 06:51:24 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 38E6oson029082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Sep 2023 23:50:54 -0700 X-Auth-Received: from localhost.localdomain ([10.154.75.179]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 38E6nuq3027316 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 13 Sep 2023 23:50:54 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v11 40/40] libstdc++: Optimize is_scalar trait performance Date: Wed, 13 Sep 2023 23:43:19 -0700 Message-ID: <20230914064949.29787-41-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914064949.29787-1-kmatsui@gcc.gnu.org> References: <20230914064949.29787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ESo8BqQ1ziFsuSPlW1aAsAMv0zXXjNGC X-Proofpoint-ORIG-GUID: ESo8BqQ1ziFsuSPlW1aAsAMv0zXXjNGC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_04,2023-09-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=657 spamscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309140060 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997480812710190 X-GMAIL-MSGID: 1776997480812710190 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>;