From patchwork Mon Oct 16 00:09: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: 153079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3156334vqb; Sun, 15 Oct 2023 17:14:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUfJ/8AqOuFTupwkKM6OJEUvWRTzxCS22TXpEIElPZB3RW3iqQ4CgURIUGYANAMbvn8sRk X-Received: by 2002:a81:4a86:0:b0:577:a46:26e5 with SMTP id x128-20020a814a86000000b005770a4626e5mr33125743ywa.31.1697415265791; Sun, 15 Oct 2023 17:14:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415265; cv=pass; d=google.com; s=arc-20160816; b=0sahhS2ENoUco1kM6g6jrg8KPnAgE4uQTKz4ZmPVVv0VYuhCGcxWB7w/bfIyH0StoU odI+q0GufSEtwTajXh7EHiA6Fg7Jfkp8IO/0Pp6xL5AvRHyGLGKaSubogP27WTqReXNE IEVrnj8QfwHuUMk1eDzlKrJvzCPcqMqCNJfMnR2NMZ5kh8ULbJE8gqjdwkmfshoWgu2C J6AWohQA9dzPFSdm1uX3l5kVj6Y/Gqvw0FH+jojQ4rCEoYGjNgIw2Fi2e+Ip1hpqZknl pqV6IexpiShiHDcY5VHLdED/M/8N9WQv7UY6MY3A6y72mRPviGbyv4k+/WmGjStUJIS6 0IJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=MKW1Ac2+4canAboK7rFTyrtkRq5Md4dhsl2QPGign68=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EUenf7Y3yUhIjNf6HS2B8UDCWV1fJThByE4PDz3yi5aH/2/jUHnZ7z9QgevYtELpag V+jo1CO3lx796odooYuXXj5tF4ZXRfzLDzdlrRVuggLmfCrJcF8NbjlAeQ5PJaDqpyXc qJnPW8XvxA59GQb+lBGBb8EgmFhQLLt9Pc9S2UdbouR5SNFHhWDLWIC2GHLO1W/nPGQ6 Os1eEPBOrooLf268IRnwFtYlqzlYFcgBdeH4Q36YMP0I+STEE/UzNXxQj8OxTTRFiK2A UF3qK6eCaiVXAPLFjnjz2rl3uBDqoTYJykPicg+cAMO/hsbFbuYaHmcSGO9bO5pAeqYf TVeA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EQY9NRBp; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id om33-20020a0562143da100b006561de71bfcsi4714036qvb.269.2023.10.15.17.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:14:25 -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=EQY9NRBp; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82C823858412 for ; Mon, 16 Oct 2023 00:14:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82C823858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415265; bh=MKW1Ac2+4canAboK7rFTyrtkRq5Md4dhsl2QPGign68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EQY9NRBpsovAxkE6knjYzPMUKpzQZtsXilCXOHLJl3VotYPyMEEIMO2lwmHAW878l xf/t/VZmfimxxHi1w2Klse6gljKmOQVt+FXHYhlgwOe/YEg+uRZ8bAKLsGU8s9UgiC J2W0yl1+F+TCLNmVqkbOU82mGitmS2b4WKg8N3xA= 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 47C073858D32; Mon, 16 Oct 2023 00:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47C073858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 47C073858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415177; cv=none; b=D3QEd/d3hipumGvavihJm8dXD/hRAAAxxo2AY92F9RmsaNQ+VZuq8mw1N9fRp3Gcpnk6Rb8W3hje5FFUTrBwDydpqrq42nryDv0a0ETH5RxVO7L4/cfA3YlTbsXZ30RJKjGGODmpYBLzYArioM1toAG8D8n4dpoDZwjvXTdqrKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415177; c=relaxed/simple; bh=ueEU7MagjimKlE470j5C66f9EXtFDtKqz5Vv0AXZdoI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=R8FE7yqeAe0tQ33iDaH/ovgYf48YVw9hUiwn9ZNVtKFrTuYn0kFqHJR3rDZyNa4i4LQfiE45RaQE3zVTiqKTxUal/locpqAHFZ2FW9fG0BTu3yxA5mLJvW0nKSb8OgtCduOCgZmkPhUkJNhszXB1pKnDkM5QF1I4aebnai+4oQE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G066fv000487; Mon, 16 Oct 2023 00:12:53 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dk4bra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:12:53 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0CokN000929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:12:50 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrp032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:12:50 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 01/40] c++: Sort built-in traits alphabetically Date: Sun, 15 Oct 2023 17:09:45 -0700 Message-ID: <20231016001227.2717180-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: WsSOdtByj0L49uRCQt5fdXi3Czc0QB4q X-Proofpoint-GUID: WsSOdtByj0L49uRCQt5fdXi3Czc0QB4q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779497639605776976 X-GMAIL-MSGID: 1779868909393225625 This patch sorts built-in traits alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in traits alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 68 ++++++++--------- gcc/cp/cp-trait.def | 10 +-- gcc/cp/semantics.cc | 94 ++++++++++++------------ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 70 +++++++++--------- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9e4e7043cd..722fc334e6f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3702,18 +3702,36 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_HAS_TRIVIAL_DESTRUCTOR: inform (loc, " %qT is not trivially destructible", t1); break; + case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: + inform (loc, " %qT does not have unique object representations", t1); + break; case CPTK_HAS_VIRTUAL_DESTRUCTOR: inform (loc, " %qT does not have a virtual destructor", t1); break; case CPTK_IS_ABSTRACT: inform (loc, " %qT is not an abstract class", t1); break; + case CPTK_IS_AGGREGATE: + inform (loc, " %qT is not an aggregate", t1); + break; + case CPTK_IS_ASSIGNABLE: + inform (loc, " %qT is not assignable from %qT", t1, t2); + break; case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not default constructible", t1); + else + inform (loc, " %qT is not constructible from %qE", t1, t2); + break; + case CPTK_IS_CONVERTIBLE: + inform (loc, " %qT is not convertible from %qE", t2, t1); + break; case CPTK_IS_EMPTY: inform (loc, " %qT is not an empty class", t1); break; @@ -3729,6 +3747,18 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_NOTHROW_ASSIGNABLE: + inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); + break; + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not nothrow default constructible", t1); + else + inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); + break; + case CPTK_IS_NOTHROW_CONVERTIBLE: + inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + break; case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: inform (loc, " %qT is not pointer-interconvertible base of %qT", t1, t2); @@ -3748,50 +3778,20 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIAL: inform (loc, " %qT is not a trivial type", t1); break; - case CPTK_IS_UNION: - inform (loc, " %qT is not a union", t1); - break; - case CPTK_IS_AGGREGATE: - inform (loc, " %qT is not an aggregate", t1); - break; - case CPTK_IS_TRIVIALLY_COPYABLE: - inform (loc, " %qT is not trivially copyable", t1); - break; - case CPTK_IS_ASSIGNABLE: - inform (loc, " %qT is not assignable from %qT", t1, t2); - break; case CPTK_IS_TRIVIALLY_ASSIGNABLE: inform (loc, " %qT is not trivially assignable from %qT", t1, t2); break; - case CPTK_IS_NOTHROW_ASSIGNABLE: - inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); - break; - case CPTK_IS_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not default constructible", t1); - else - inform (loc, " %qT is not constructible from %qE", t1, t2); - break; case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not trivially default constructible", t1); else inform (loc, " %qT is not trivially constructible from %qE", t1, t2); break; - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not nothrow default constructible", t1); - else - inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); - break; - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: - inform (loc, " %qT does not have unique object representations", t1); - break; - case CPTK_IS_CONVERTIBLE: - inform (loc, " %qT is not convertible from %qE", t2, t1); + case CPTK_IS_TRIVIALLY_COPYABLE: + inform (loc, " %qT is not trivially copyable", t1); break; - case CPTK_IS_NOTHROW_CONVERTIBLE: - inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + case CPTK_IS_UNION: + inform (loc, " %qT is not a union", t1); break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..0e48e64b8dd 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,14 +84,14 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) -/* FIXME Added space to avoid direct usage in GCC 13. */ -DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) - DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) -DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) -DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) +DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) +DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) + +/* FIXME Added space to avoid direct usage in GCC 13. */ +DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) /* These traits yield a type pack, not a type, and are represented by cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 80ef1364e33..782aa515da0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12090,15 +12090,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && classtype_has_nothrow_assign_or_copy_p (type1, true)))); - case CPTK_HAS_TRIVIAL_ASSIGN: - /* ??? The standard seems to be missing the "or array of such a class - type" wording for this trait. */ - type1 = strip_array_types (type1); - return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE - && (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) - && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); - case CPTK_HAS_NOTHROW_CONSTRUCTOR: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) @@ -12107,17 +12098,26 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && maybe_instantiate_noexcept (t) && TYPE_NOTHROW_P (TREE_TYPE (t)))); - case CPTK_HAS_TRIVIAL_CONSTRUCTOR: - type1 = strip_array_types (type1); - return (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); - case CPTK_HAS_NOTHROW_COPY: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) || (CLASS_TYPE_P (type1) && classtype_has_nothrow_assign_or_copy_p (type1, false))); + case CPTK_HAS_TRIVIAL_ASSIGN: + /* ??? The standard seems to be missing the "or array of such a class + type" wording for this trait. */ + type1 = strip_array_types (type1); + return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE + && (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) + && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); + + case CPTK_HAS_TRIVIAL_CONSTRUCTOR: + type1 = strip_array_types (type1); + return (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); + case CPTK_HAS_TRIVIAL_COPY: /* ??? The standard seems to be missing the "or array of such a class type" wording for this trait. */ @@ -12131,18 +12131,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); - case CPTK_HAS_VIRTUAL_DESTRUCTOR: - return type_has_virtual_destructor (type1); - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: return type_has_unique_obj_representations (type1); + case CPTK_HAS_VIRTUAL_DESTRUCTOR: + return type_has_virtual_destructor (type1); + case CPTK_IS_ABSTRACT: return ABSTRACT_CLASS_TYPE_P (type1); case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ASSIGNABLE: + return is_xible (MODIFY_EXPR, type1, type2); + case CPTK_IS_BASE_OF: return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) @@ -12151,6 +12154,12 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONSTRUCTIBLE: + return is_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_CONVERTIBLE: + return is_convertible (type1, type2); + case CPTK_IS_EMPTY: return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); @@ -12166,6 +12175,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: + return is_nothrow_xible (MODIFY_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + return is_nothrow_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONVERTIBLE: + return is_nothrow_convertible (type1, type2); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12196,24 +12214,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; - case CPTK_IS_ASSIGNABLE: - return is_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_CONSTRUCTIBLE: - return is_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_ASSIGNABLE: - return is_nothrow_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - return is_nothrow_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_CONVERTIBLE: - return is_convertible (type1, type2); - - case CPTK_IS_NOTHROW_CONVERTIBLE: - return is_nothrow_convertible (type1, type2); - case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12326,9 +12326,9 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ABSTRACT: case CPTK_IS_EMPTY: case CPTK_IS_POLYMORPHIC: - case CPTK_IS_ABSTRACT: case CPTK_HAS_VIRTUAL_DESTRUCTOR: if (!check_trait_type (type1, /* kind = */ 3)) return error_mark_node; @@ -12348,12 +12348,12 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - case CPTK_IS_TRIVIALLY_ASSIGNABLE: - case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_TRIVIALLY_ASSIGNABLE: + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: if (!check_trait_type (type1) @@ -12372,8 +12372,8 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: - case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_UNION: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12436,25 +12436,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { - case CPTK_UNDERLYING_TYPE: - return finish_underlying_type (type1); - case CPTK_REMOVE_CV: return cv_unqualified (type1); - case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return type1; + return cv_unqualified (type1); - case CPTK_REMOVE_CVREF: + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return cv_unqualified (type1); + return type1; case CPTK_TYPE_PACK_ELEMENT: return finish_type_pack_element (type1, type2, complain); + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..2223f08a628 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,9 +8,21 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif @@ -44,12 +56,21 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_convertible) +# error "__has_builtin (__is_convertible) failed" +#endif #if !__has_builtin (__is_empty) # error "__has_builtin (__is_empty) failed" #endif @@ -65,6 +86,15 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_convertible) +# error "__has_builtin (__is_nothrow_convertible) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif @@ -98,51 +128,21 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif -#if !__has_builtin (__underlying_type) -# error "__has_builtin (__underlying_type) failed" -#endif -#if !__has_builtin (__is_assignable) -# error "__has_builtin (__is_assignable) failed" -#endif -#if !__has_builtin (__is_constructible) -# error "__has_builtin (__is_constructible) failed" -#endif -#if !__has_builtin (__is_nothrow_assignable) -# error "__has_builtin (__is_nothrow_assignable) failed" -#endif -#if !__has_builtin (__is_nothrow_constructible) -# error "__has_builtin (__is_nothrow_constructible) failed" -#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif -#if !__has_builtin (__builtin_is_constant_evaluated) -# error "__has_builtin (__builtin_is_constant_evaluated) failed" -#endif -#if !__has_builtin (__builtin_source_location) -# error "__has_builtin (__builtin_source_location) failed" -#endif -#if !__has_builtin (__builtin_is_corresponding_member) -# error "__has_builtin (__builtin_is_corresponding_member) failed" -#endif -#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) -# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" -#endif -#if !__has_builtin (__is_convertible) -# error "__has_builtin (__is_convertible) failed" -#endif -#if !__has_builtin (__is_nothrow_convertible) -# error "__has_builtin (__is_nothrow_convertible) failed" -#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif -#if !__has_builtin (__remove_cvref) -# error "__has_builtin (__remove_cvref) failed" +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" #endif From patchwork Mon Oct 16 00:09: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: 153081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3156676vqb; Sun, 15 Oct 2023 17:15:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIjGCOpuUqm3eeks4rKGlrtEIiEDxvWiDBnbdIimACY+P3HADuCDNghKWyRz+pJO8RJr1O X-Received: by 2002:a0c:e445:0:b0:635:93fb:fc05 with SMTP id d5-20020a0ce445000000b0063593fbfc05mr26826697qvm.10.1697415332632; Sun, 15 Oct 2023 17:15:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415332; cv=pass; d=google.com; s=arc-20160816; b=RH3SFByPvOdsLCoJG+XxiliiQ4erKCQY5ths9XS8G1A/mmvQjLo6OF2baM8RK5Kj7h +Sat6uLGCsnzyAFpRZjXztzWdJ5zKV/JEsLyKrpXK7IQJy8LMz+Bu9+i+knNrfd5C0ON vkYwpVDYKeqLvEJoUb2PwPHvLYT4NRVTxpZDxHb3sZUjxxlEb6xNRrbkoOjeTF14HUmp i2swN3OpLr0fFkZgMeY3R4JrsnAo8pIVVGNkwF80BZ9bz/TyNLuY6fTrTNayYCbKl6gH xshcDfSwPS447dxpJBM23X62s0buhO+exeVTfaJIFdTU9pwyi6jqOq1U/xlNVYVgiUW+ 2TDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=5oj/RVlIaWtuuA0dgOkoJpKr7pfq9MSQmrmxMkGo0ZQ=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=ZYKiTwqY+hHPzO9YvPOYEwZb5ITuYKKpUysLKKQCdZYBHdP9sfrXutz7ooRDlU5MJq TL3yKhmrBwS3Z96WUspVNSpQVzMwuTAIHRArUgDM2yVkZD+BoLyCNpyS5ez3k1Cpek8m F91jC3uiPXf70RxZtBHjZJaHpXOuF6Og/BaVNtaWXaj9AIMcyvzFAYGoa5b4wTZHSSdC o7eC+lOjxk8upyS9yC4eFjT4meTCBBPcTzFNC0o3WXwWHAZ7/JrIS7WNIlZMcH1JdPBQ SBRGjOOcRAiGznFpgDnPBJuf0kCxZ/364q0m2hV8oEGRxp0gSeK3Zu0e9pZ5dpHehHU/ sxLw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EZbqU0TD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id em5-20020ad44f85000000b0065b22d4a84asi4585076qvb.514.2023.10.15.17.15.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:15:32 -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=EZbqU0TD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C9BD3856974 for ; Mon, 16 Oct 2023 00:15:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C9BD3856974 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415332; bh=5oj/RVlIaWtuuA0dgOkoJpKr7pfq9MSQmrmxMkGo0ZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EZbqU0TDiiMgtv0lmeAMG1yD2Z84kEUWAXY62yXVNY1cE167c5guS3UT0VuLv+WpQ j0B7GW1bD87XZM6vpVnGpSAXJt9Fpi0UxmZnrUdkdBLdLqewnu/Mw7rWguL6NpOMZh oQUq+aB7/HcySm2KSHdusrq6mySzIFGFcYjxos9Y= 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 705FC385842E; Mon, 16 Oct 2023 00:13:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 705FC385842E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 705FC385842E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415216; cv=none; b=rH5JztXkvUPNSO1n0zWYCseeYwU2U3DWFMy43Jf5/6gFfOzxt1baxF3+RM4Zl2GGkcTyXzx7Mu6w1zx1ACWk/3Rt2kYWhrqLtyY5Plyg3yv2QEVjfLvxTFOhER/qnojQCdlgln6COtwYQUeeNoIbL9BOlJQFQ9Q16LKx5a9GMxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415216; c=relaxed/simple; bh=HvOL8WMvT8yBlQmCXRbCRLG4khY+tLnZ/zScAUY3v3c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UKDQEE2A9itUpfvllQwx00tOpNIUNZYX8+mkm/2+z0ZVYQfHQKTVBAWqLoNxW9TzszUqPYbPioxZV7DKn+Wp0FhgnFMpnnpgpI/FZ6yMyXTshrTS/IhAOfzFWkffqwNhM31CFawPh24TlJvNvIe+bvV9qA1/hkI03mZlf8EQTRI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNxx34011785; Mon, 16 Oct 2023 00:13:33 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4fxch1k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:13:32 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0D5Lb005299 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:13:06 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrq032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:13:05 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Patrick Palka Subject: [PATCH v20 02/40] c-family, c++: Look up built-in traits via identifier node Date: Sun, 15 Oct 2023 17:09:46 -0700 Message-ID: <20231016001227.2717180-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8xGGdQ4UkaqgyE4lcCBGmcEiXr4WLBu7 X-Proofpoint-GUID: 8xGGdQ4UkaqgyE4lcCBGmcEiXr4WLBu7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779868979596920251 X-GMAIL-MSGID: 1779868979596920251 Since RID_MAX soon reaches 255 and all built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses the identifier node to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait kind. * cp-tree.h (enum cp_trait_kind): Set its underlying type to addr_space_t. (struct cp_trait): New struct to hold trait information. (cp_traits): New array to hold a mapping to all traits. (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (init_cp_traits): New function to set cik_trait for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_traits): Define its values, declared in cp-tree.h. (cp_lexer_lookup_trait): New function to look up a built-in trait by IDENTIFIER_CP_INDEX. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 -- gcc/c-family/c-common.h | 5 -- gcc/cp/cp-objcp-common.cc | 8 +-- gcc/cp/cp-tree.h | 31 ++++++--- gcc/cp/lex.cc | 21 ++++++ gcc/cp/parser.cc | 141 ++++++++++++++++++++++++-------------- 6 files changed, 139 insertions(+), 74 deletions(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..21fd333ef57 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,13 +508,6 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, - /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..051a442e0f4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..b1adacfec07 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -421,6 +421,10 @@ names_builtin_p (const char *name) } } + /* Check for built-in traits. */ + if (IDENTIFIER_TRAIT_P (id)) + return true; + /* Also detect common reserved C++ words that aren't strictly built-in functions. */ switch (C_RID_CODE (id)) @@ -434,10 +438,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6e34952da99..583abb2e79a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1226,7 +1226,7 @@ enum cp_identifier_kind { cik_simple_op = 4, /* Non-assignment operator name. */ cik_assign_op = 5, /* An assignment operator name. */ cik_conv_op = 6, /* Conversion operator name. */ - cik_reserved_for_udlit = 7, /* Not yet in use */ + cik_trait = 7, /* Built-in trait name. */ cik_max }; @@ -1271,9 +1271,9 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is for any operator name (including - conversions). Value 4, 5, 6 or 7. */ + conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE)) + (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ @@ -1286,12 +1286,18 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion - operator. Value 7. */ + operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ & (!IDENTIFIER_KIND_BIT_0 (NODE))) +/* True if this identifier is the name of a built-in trait. */ +#define IDENTIFIER_TRAIT_P(NODE) \ + (IDENTIFIER_KIND_BIT_0 (NODE) \ + && IDENTIFIER_KIND_BIT_1 (NODE) \ + && IDENTIFIER_KIND_BIT_2 (NODE)) + /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ (IDENTIFIER_OVL_OP_P (NODE) \ @@ -1375,16 +1381,25 @@ struct GTY (()) tree_argument_pack_select { int index; }; -/* The different kinds of traits that we encounter. */ - -enum cp_trait_kind -{ +/* The different kinds of traits that we encounter. The size is limited to + addr_space_t since a trait is looked up by IDENTIFIER_CP_INDEX. */ +enum cp_trait_kind : addr_space_t { #define DEFTRAIT(TCC, CODE, NAME, ARITY) \ CPTK_##CODE, #include "cp-trait.def" #undef DEFTRAIT }; +/* The trait type. */ +struct cp_trait { + short arity; + cp_trait_kind kind; + bool type; +}; + +/* The trait table. */ +extern const struct cp_trait cp_traits[]; + /* The types that we are processing. */ #define TRAIT_EXPR_TYPE1(NODE) \ (((struct tree_trait_expr *)TRAIT_EXPR_CHECK (NODE))->type1) diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..16a82a12a02 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" static int interface_strcmp (const char *); +static void init_cp_traits (void); static void init_cp_pragma (void); static tree parse_strconst_pragma (const char *, int); @@ -283,6 +284,25 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + id = get_identifier (NAME); \ + IDENTIFIER_CP_INDEX (id) = CPTK_##CODE; \ + set_identifier_kind (id, cik_trait); +#include "cp/cp-trait.def" +#undef DEFTRAIT + + /* An alias for __is_same. */ + id = get_identifier ("__is_same_as"); + IDENTIFIER_CP_INDEX (id) = CPTK_IS_SAME; + set_identifier_kind (id, cik_trait); +} + static void init_cp_pragma (void) { @@ -324,6 +344,7 @@ cxx_init (void) input_location = BUILTINS_LOCATION; init_reswords (); + init_cp_traits (); init_tree (); init_cp_semantics (); init_operators (); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f3abae716fe..eba5272be03 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,6 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -279,6 +285,19 @@ static FILE *cp_lexer_debug_stream; sizeof, typeof, or alignof. */ int cp_unevaluated_operand; +/* The trait table, declared in cp-tree.h. */ +const cp_trait cp_traits[] = +{ +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + { ARITY, CPTK_##CODE, (TCC == tcc_type) }, +#include "cp-trait.def" +#undef DEFTRAIT +}; +/* The trait table cannot have more than 255 (addr_space_t) entries since + the index is retrieved through IDENTIFIER_CP_INDEX. */ +static_assert(ARRAY_SIZE (cp_traits) <= 255, + "cp_traits array cannot have more than 255 entries"); + /* Dump up to NUM tokens in BUFFER to FILE starting with token START_TOKEN. If START_TOKEN is NULL, the dump starts with the first token in BUFFER. If NUM is 0, dump all the tokens. If @@ -1167,12 +1186,6 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_CONSTEVAL: return true; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - return true; - default: if (keyword >= RID_FIRST_INT_N && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS @@ -1182,6 +1195,48 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } +/* Look ups the corresponding built-in trait if a given token is + a built-in trait. Otherwise, returns nullptr. */ + +static const cp_trait * +cp_lexer_lookup_trait (const cp_token *token) +{ + tree id = token->u.value; + + if (token->type == CPP_NAME + && TREE_CODE (id) == IDENTIFIER_NODE + && IDENTIFIER_TRAIT_P (id)) + return &cp_traits[IDENTIFIER_CP_INDEX (id)]; + + return nullptr; +} + +/* Similarly, but only if the token is an expression-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_expr (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && !trait->type) + return trait; + + return nullptr; +} + +/* Similarly, but only if the token is a type-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_type (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && trait->type) + return trait; + + return nullptr; +} + /* Return true if the next token is a keyword for a decl-specifier. */ static bool @@ -1190,6 +1245,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); + if (cp_lexer_lookup_trait_type (token)) + return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -2854,7 +2911,7 @@ static void cp_parser_late_parsing_default_args static tree cp_parser_sizeof_operand (cp_parser *, enum rid); static cp_expr cp_parser_trait - (cp_parser *, enum rid); + (cp_parser *, const cp_trait *); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6021,12 +6078,6 @@ cp_parser_primary_expression (cp_parser *parser, case RID_OFFSETOF: return cp_parser_builtin_offsetof (parser); -#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_EXPR - return cp_parser_trait (parser, token->keyword); - // C++ concepts case RID_REQUIRES: return cp_parser_requires_expression (parser); @@ -6065,6 +6116,12 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: + { + const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + if (trait) + return cp_parser_trait (parser, trait); + } + /* FALLTHRU */ case CPP_SCOPE: case CPP_TEMPLATE_ID: case CPP_NESTED_NAME_SPECIFIER: @@ -11033,28 +11090,11 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, const cp_trait* trait) { - cp_trait_kind kind; tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; - - switch (keyword) - { -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: \ - kind = CPTK_##CODE; \ - binary = (ARITY == 2); \ - variadic = (ARITY == -1); \ - type = (TCC == tcc_type); \ - break; -#include "cp-trait.def" -#undef DEFTRAIT - default: - gcc_unreachable (); - } + const bool binary = (trait->arity == 2); + const bool variadic = (trait->arity == -1); /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11103,12 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) cp_lexer_consume_token (parser->lexer); matching_parens parens; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) cp_parser_require (parser, CPP_LESS, RT_LESS); else parens.require_open (parser); - if (kind == CPTK_IS_DEDUCIBLE) + if (trait->kind == CPTK_IS_DEDUCIBLE) { const cp_token* token = cp_lexer_peek_token (parser->lexer); type1 = cp_parser_id_expression (parser, @@ -11079,7 +11119,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /*optional_p=*/false); type1 = cp_parser_lookup_name_simple (parser, type1, token->location); } - else if (kind == CPTK_TYPE_PACK_ELEMENT) + else if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* __type_pack_element takes an expression as its first argument and uses template-id syntax instead of function call syntax (for consistency with Clang). We special case these properties of __type_pack_element @@ -11094,7 +11134,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type1 == error_mark_node) return error_mark_node; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); tree trailing = cp_parser_enclosed_template_argument_list (parser); @@ -11144,7 +11184,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) } location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* cp_parser_enclosed_template_argument_list above already took care of parsing the closing '>'. */; else @@ -11158,17 +11198,17 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /* Complete the trait expression, which may mean either processing the trait expr now or saving it for template instantiation. */ - switch (kind) + switch (trait->kind) { case CPTK_BASES: return cp_expr (finish_bases (type1, false), trait_loc); case CPTK_DIRECT_BASES: return cp_expr (finish_bases (type1, true), trait_loc); default: - if (type) - return finish_trait_type (kind, type1, type2, tf_warning_or_error); + if (trait->type) + return finish_trait_type (trait->kind, type1, type2, tf_warning_or_error); else - return finish_trait_expr (trait_loc, kind, type1, type2); + return finish_trait_expr (trait_loc, trait->kind, type1, type2); } } @@ -20081,20 +20121,21 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - type = cp_parser_trait (parser, token->keyword); + default: + break; + } + + /* If token is a type-yielding built-in traits, parse it. */ + const cp_trait* trait = cp_lexer_lookup_trait_type (token); + if (trait) + { + type = cp_parser_trait (parser, trait); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, /*type_definition_p=*/false); return type; - - default: - break; } /* If token is an already-parsed decltype not followed by ::, From patchwork Mon Oct 16 00:09: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: 153083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157102vqb; Sun, 15 Oct 2023 17:16:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBykstci2XgYddq/e3TDMVjOPlcCNk+oGkFsumyOK5w5f/H8bXOqRbuo4n9x/A51A7LV8z X-Received: by 2002:a05:6902:18c7:b0:d9a:c587:e50 with SMTP id ck7-20020a05690218c700b00d9ac5870e50mr12638069ybb.39.1697415403356; Sun, 15 Oct 2023 17:16:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415403; cv=pass; d=google.com; s=arc-20160816; b=Zvf890i/8Hktc/EZ++ELsTQ+59VwBRG908Dc1U1i+cEiI3Q93Afo+QoOHUycjHdf7X lgY1aSNG9ZRG2YS3LQd83DrImWRHC8Wsie+yRtgSEX2389OyxBap665gETvLJeeUM1Ry nqrWDQwwbrdb9D7wqIyBseSm8LJht9PYgPnXzYUS00WpNwMyaXzgFycKcFlKUKfga1mN j+/WEa+MH1x6N1e3ztziGbdnV8D/OER1weUrb3cyf8LQpOB6EyjlOKcsqvVai6W8ZRjL zZ6SdAp1mZXo2LAd/YDfB8jIYAnzHm+N5nEWvKHk6dANCu2PcuoJu/xG+YNxAXKvCato eKbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=azIA2KqwARrbz8bjqC4B2inLjKvCSX7yHeleo1OlgOQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=eepHVekfbp2e4tJbJpZcRxTrmtzcHLFLD4xHcLHzi8tqZ5cTNcLOZbOe4YFjDbyW6X Ddvyaj2PDIjzqpzyIQKagTyXNgip+jyE/VExpahXYbgV7aV6XfPewqbr0Q+qDEWd8eb/ qNVe1zMK3xJtMuOd/v8LBkGMmOmML2HQwXB1mO1uIQcmetbo8nSDjMbp0c6DnDiSubeZ sC91zRGSrtbjv0DAbh2GAt/7e7xf/C5QRSM6J+OoSn0Bl/P89PuJ0qPP3H7rNjfZwkvT iQGc9uocL9szq5xG+PuMCW+UqS6pvKBupdPjQbhu98OyRB7aYplRX1pX+BEhLOp4vEpa bQkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oXqQlJAQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id om25-20020a0562143d9900b0065afb1fed25si4755062qvb.404.2023.10.15.17.16.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:16:43 -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=oXqQlJAQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CB6B3857009 for ; Mon, 16 Oct 2023 00:16:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CB6B3857009 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415402; bh=azIA2KqwARrbz8bjqC4B2inLjKvCSX7yHeleo1OlgOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oXqQlJAQI0HakJm2xj2tBLvqf7/p6W2eoythHEowAMERmGZ7ZwVAAL7Zt1IUqS3Ka tqbtWti/QLQOnW7Qh+hGAD44ETaqpBvDzqMkyFri6uLKTCXkS/D8Gkwe+K/SgKjbkQ j39KPufFCAzfRxXWe1eZl6WlNQ/TnNss/ywpB34M= 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 8871E3858032; Mon, 16 Oct 2023 00:14:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8871E3858032 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8871E3858032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415247; cv=none; b=Y2qAaqStzBZj9NVfAg37W2fH74vQTyOfKiuuTiIf5bfqDyzdnHcSS8jO5g51PFhNUXl+a4TJOIsVA6T5XA2i5ra43wkpkzZocnwdocAVnoNf0xmijQKmMYYpZQbtq+aNyaQynS8RfB3pKgUnUfBNDiryDFPbxV6r/3I+bh9JPvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415247; c=relaxed/simple; bh=1LSX65YLPixz1kJSLlqSjNhH1TPwn+JSOo5ERmjtr3o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EG63uynYl6gZd4E5UyX6EEWSUIC9qPM4i8iq6pnnaNtBOQJGAzYp+HNbkDdHNR+p8Fykjb4qoiqIIY6q6cAJVlFnWKqoAlVwfhE4uuAamcNwL9PxUFx/9qNgOSqoRQPNmBd+pJUOMcxaI/FnV4h2a/OKKtFqQ96cRFBk1FOLSiU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNxhAD014156; Mon, 16 Oct 2023 00:14:04 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4wkma59-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:04 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0DkPQ005354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:13:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrr032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:13:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 03/40] c++: Accept the use of built-in trait identifiers Date: Sun, 15 Oct 2023 17:09:47 -0700 Message-ID: <20231016001227.2717180-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _QLbzUQwv3WptF3Nh7rOxUubfRxwALgg X-Proofpoint-GUID: _QLbzUQwv3WptF3Nh7rOxUubfRxwALgg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1034 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779681961607250764 X-GMAIL-MSGID: 1779869053783161749 This patch accepts the use of built-in trait identifiers when they are actually not used as traits. Specifically, we check if the subsequent token is '(' for ordinary built-in traits or is '<' only for the special __type_pack_element built-in trait. If those identifiers are used differently, the parser treats them as normal identifiers. This allows us to accept code like: struct __is_pointer {};. gcc/cp/ChangeLog: * parser.cc (cp_lexer_lookup_trait): Rename to ... (cp_lexer_peek_trait): ... this. Handle a subsequent token for the corresponding built-in trait. (cp_lexer_lookup_trait_expr): Rename to ... (cp_lexer_peek_trait_expr): ... this. (cp_lexer_lookup_trait_type): Rename to ... (cp_lexer_peek_trait_type): ... this. (cp_lexer_next_token_is_decl_specifier_keyword): Call cp_lexer_peek_trait_type. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. Signed-off-by: Ken Matsui --- gcc/cp/parser.cc | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index eba5272be03..0f2a1baee6a 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,12 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *lexer, const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1195,19 +1195,31 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } -/* Look ups the corresponding built-in trait if a given token is +/* Peeks the corresponding built-in trait if a given token is a built-in trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) { - tree id = token->u.value; + tree id = token1->u.value; - if (token->type == CPP_NAME + if (token1->type == CPP_NAME && TREE_CODE (id) == IDENTIFIER_NODE && IDENTIFIER_TRAIT_P (id)) - return &cp_traits[IDENTIFIER_CP_INDEX (id)]; + { + const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (id)]; + const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT); + /* Check if the subsequent token is a `<' token to + __type_pack_element or is a `(' token to everything else. */ + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); + if (is_pack_element && token2->type != CPP_LESS) + return nullptr; + if (!is_pack_element && token2->type != CPP_OPEN_PAREN) + return nullptr; + + return &trait; + } return nullptr; } @@ -1215,9 +1227,9 @@ cp_lexer_lookup_trait (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_expr (const cp_token *token) +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && !trait->type) return trait; @@ -1228,9 +1240,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_type (const cp_token *token) +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && trait->type) return trait; @@ -1245,7 +1257,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); - if (cp_lexer_lookup_trait_type (token)) + if (cp_lexer_peek_trait_type (lexer, token)) return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6117,7 +6129,7 @@ cp_parser_primary_expression (cp_parser *parser, keyword. */ case CPP_NAME: { - const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + const cp_trait* trait = cp_lexer_peek_trait_expr (parser->lexer, token); if (trait) return cp_parser_trait (parser, trait); } @@ -20126,7 +20138,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, } /* If token is a type-yielding built-in traits, parse it. */ - const cp_trait* trait = cp_lexer_lookup_trait_type (token); + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Mon Oct 16 00:09: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: 153116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3161234vqb; Sun, 15 Oct 2023 17:30:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHePKoB9bE8GID89nHx1I6BpGm6H3EpSshiZk317Ot6SE0nrdkKlEnLWplhNjFg1ZUeAu59 X-Received: by 2002:a05:6214:398a:b0:659:abd1:8d37 with SMTP id ny10-20020a056214398a00b00659abd18d37mr29962132qvb.4.1697416245447; Sun, 15 Oct 2023 17:30:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416245; cv=pass; d=google.com; s=arc-20160816; b=PC26NL/f6XLlDy4LQyss/+kvujfzxEl0cFFfFVk2Y0gIXo/81hIVeO9+to6ZpqA48r 18RHixXmc+ftavqc9aQcs3ekY+1/oWX5A3PbjaKVzrm8lsuGluG8w2RyC9+e2eTK+bxE A4eMyGf/IlN/uZqRuZn9FGlxhBvuOjuayaROK1Q/vq1en5p29UmgQ7lHj16LhHUbkf8e egNOZ/hNC0rD6kcuUCnZ1iWeKbziJ9H4CVfAWPf+TwOlG7mKfjofQIwdZvGavoikHnFK yaK/rY7T92gpyUjtYmJpodmYBisgbPCB4hAVHhdh8J8Yd6JXA49syXIvS/ln/ZzVn6Rj kh9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=26K/qlVmqmB0m8Kb9qCzAAsBfVfR067MxIsdPjILEEY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=P3xZAR3VAz6m05lrARRP8Uf1qztXdRVTyAnGV/ExRO3JjFB2SS3w7nDqs1Z0SuGbI7 v2PLnp/OsJFSz8zaWvtvlr8rdhxEqfTVcS0enIXHCQWmRyuRXQiK7GHnXPlSL8npTp+M HoOBbBkV3UknOgeYZLlqpIYqCxjPG8ZNZ5JSJYjrkuFQ651Wt4fFMzXYkGQSenNXoaY6 rMogwOu6ml8/uTRhg48NtX7wChT2GztZmHCbZ9WAl2IH+vdBPPUNjLt95U8CsQSnKWg+ LYDKwilSEIdPIjJP6f3P+BqLlgM0eUzyhMxLryOO3auMVawKRqSU9DXIroqu0v1Ql/Bn p1uQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oI5b18cs; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u22-20020a05620a121600b007757acf4889si4481206qkj.1.2023.10.15.17.30.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:30:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oI5b18cs; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2EA143857707 for ; Mon, 16 Oct 2023 00:30:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EA143857707 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416245; bh=26K/qlVmqmB0m8Kb9qCzAAsBfVfR067MxIsdPjILEEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oI5b18csLLG5HcYU5DjUHf267T+Fb+yRNGilCDZ6B6ou0bwgFXjaukrXZGlDunZHg nqCKby19iagiLzj0yB2v4KwEsfdcc/XmX0CogOtpp1b62bK/rFl1xpRpfC7LzhRCZ5 nWNtWbXcbUvSgorxStVZ154jpSz1Br+bhvk/NLnM= 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 C27573857721; Mon, 16 Oct 2023 00:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C27573857721 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C27573857721 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; cv=none; b=A6YUA88yxS3nU51ILciSFgtI8ZIEbdi/xzUYSMMptd9+5mlO9xG6IeWclwtq5Z3eR+B0z3N4ZE7/EALGjjs4i0Z67IxqEbuD1nfqTBy6S9BK6q7EPY7aChNh1Lt9wQp+pmtA6bWa2z10zi3G9ujetydh9yptXcvJX+fhOOfZK0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; c=relaxed/simple; bh=6JPxCfuVhSqaihzXYhZHEpbN0gLwt2YbjqhQFU472w8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Q/774Mvq//2YoXDbS7F463coFbBWHdKJba4+FBckYYq3AXOEfQc8za7SQ3UvoiioUlswmkUD8fY+4udn6D7RR+yPg26+KwyyCsX3SkIPZhID72wOaekDr7ytmYyg+/2YiJSQchnv+ZAM4hDQ4CO4ZxdBqxHevY2+6y8aOKNacaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0BNrF010749; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr556ca0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EE22016531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrs032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 04/40] c++: Implement __is_const built-in trait Date: Sun, 15 Oct 2023 17:09:48 -0700 Message-ID: <20231016001227.2717180-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: UbmLYu3QZoW_tHYGKPgE0pxzGDUtV_rR X-Proofpoint-ORIG-GUID: UbmLYu3QZoW_tHYGKPgE0pxzGDUtV_rR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 mlxscore=0 malwarescore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=937 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1779869936895091024 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 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 782aa515da0..23f1d1c249a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Mon Oct 16 00:09: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: 153088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157718vqb; Sun, 15 Oct 2023 17:18:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUocIvIYre1RRrp/5II0V2+hKWaACdolH/lOJhyVZ9jgu2C2pgcWIiU4EQj9k7Gb6+5xAy X-Received: by 2002:a05:6214:19e8:b0:66d:fda:520d with SMTP id q8-20020a05621419e800b0066d0fda520dmr10091725qvc.0.1697415535950; Sun, 15 Oct 2023 17:18:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415535; cv=pass; d=google.com; s=arc-20160816; b=tfs+KfvIFApVQqTURjeDwKX2MQLrL2jYaTqvAnwNSj5dYxMr3++oA6SjLHBsuS1maN nE+hPY/DmI1BgnqsysacaslQ4BSj15Rgdk2a4KuXc6F2aL7bBe7jjAhvPv0gEGBwBdmp yXVC4ftyliC0u8qHehohYV2iKIY/U6+AFZSyQA8+mXD51oq4ft2pa5fmWSAsufRMmsdW kLvD51Gnrnq4uTRoHIPC+9bursnrGI6B288U7LiDKhYIx/PGuwSN4mnm72aqs2RVStMW nS2PR/sfHOIZ4o+Swoso07Ge85uGSN+pT4ag16lPRbckIdsA6IVG2Vu+ZrOeOaVYVm77 US9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=WI7QuaK63OjmHZdIFdVNokwf/FajSapDPIEvJnWDZrqTIIGgg8Mi5ECGbpElrcq0iu cDcM5RsOiV64z4gZ/wYYr+KzosFlwyvl4j80mw9NaSK2/eeYO021U6PhezvEW0QX2zwh andhkRFV3OnBKQWdV5zxoRuoe7fiHVtfj+0q7pwvYv7tsVpcIASqplA9GGCMkIpAtOD7 Y8GaTMEqgwkDnuhAm2rvqZdnyXz1mCvJw6D/8PXSHgCY8sGq1gpUQfFUfAQ+/5QjbWu5 YVZXKh30mUHyAFCvw/5BoPqvWjeIvcVKZYW+N93mPevb3/Ydi/jlocZnjT8xnfT1TfGO wVOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Xd/eYRX5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c7-20020ad44307000000b006563889d9e8si4541461qvs.428.2023.10.15.17.18.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:18: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="Xd/eYRX5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F7573858C33 for ; Mon, 16 Oct 2023 00:18:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F7573858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415535; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Xd/eYRX5mujXhXQ3TrI+hTlr445xeS8fmHcUY18HrddZgGsHsZVuV8ZWO11mDlnHt XP0oh/KzqBUn30q77bU62LXwp3NGTDKYhWBvKDwPre8WLGmYlE6Wupk7+x7x8EsT8n dvB/u3Ag02txtQUt1kOk76+a81qU4mWIk6x3mx3s= 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 1BAAA3858419; Mon, 16 Oct 2023 00:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BAAA3858419 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1BAAA3858419 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; cv=none; b=hvtvscUOES/YRvcczld36AVOqs9ZOi/UOb0L9u7EOvDHXkBuVBuLZpnFJoZrq3yY4OaOocydqjTBt1NYBa+/1pAaOCVr2Qg3/ws/pDZC1YomcbswhVn4aoWrQiMDoLhg4QnwbtIPm/taNd3qLdAMV8AjnrR9NJWL2FSrxisiHYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; c=relaxed/simple; bh=Ig95QKG3jMRJ2d5xxOfPZpdM9Fw/zdK52c0tgvu9+Dg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Lgz+5v8mWWN+O51ZmyeiQWheO0jmY32sS2jz7iiRzujzQsxgVhgMQwlWsmUNdxIIp7MO6jhrt5LyoJhuYezTDOoF21M8G25UnX25h6SoFyetvdPbmW3EaoSKweQMoOGmKeyJXPvseKwtfUSXcB4X9F/GL+2Ml8Pk+NbKCHsV7S0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G09rij025728; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEFl001208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrt032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 05/40] libstdc++: Optimize is_const trait performance Date: Sun, 15 Oct 2023 17:09:49 -0700 Message-ID: <20231016001227.2717180-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: NurnoGD1mdleAIGZW9txWqVoUrimjyDg X-Proofpoint-ORIG-GUID: NurnoGD1mdleAIGZW9txWqVoUrimjyDg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=836 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995283749276021 X-GMAIL-MSGID: 1779869193066083933 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 Mon Oct 16 00:09: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: 153095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158966vqb; Sun, 15 Oct 2023 17:22:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/Qst45DWqyPL01kxcEO+fgC9BCwY0X6vtiMl0TOGNCXjHVthO7/SqLu9RO+VejiDEMR/5 X-Received: by 2002:ac8:5c4d:0:b0:412:c81:efe2 with SMTP id j13-20020ac85c4d000000b004120c81efe2mr8864199qtj.31.1697415779618; Sun, 15 Oct 2023 17:22:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415779; cv=pass; d=google.com; s=arc-20160816; b=Z8ng/9EiXbrrI5HrECeOgi/A8mGwdPAtGZrHsmZa3QPFM0uaI1lr7+5S33ay2zBSEu YniUOHYtcrTHc7TTmhw+Xd++ij1Ojo0h4hv36HuCgW/cV/GlDSZrKlQODBU7xEjxwNxS NyrLA7qbS77i85rnqn1vQI447zqb89P+oGI1nrUF+WpNjxGgHWb5cdakcURy52em3hzh ctyW4pUQ1F9g2esOeqltqNp4QKSuSvNkkZuaMCdcCaxblw4fPSA7pDk/mEnZBqNJvwL8 mDPRs/Ge+ns3eRA6Dsb1LadmdG1JX3fwUo2JjP3NcK7BlmDpbnDBoUydKq155qgpt9lk PWmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=LCc50Lc/nkF5ZvTjaJYha0Meh5UWsKUnK+1DhikfCXQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xLwGCNMWGIODEpe5HIHKIrc25tbgAt4DrYMCsVPE+rLaIYaKHzIa2L3i6dlp4BR256 YgDRMqZ8GIEMXvPUsVfg+fxhFPZkBamgiklQzl69FumOmla0VN0tnIsR6HOd9+tG4vsG sBgLZNbgHrEy6OdZsZt9JvSA8o/iF6dCZjDvCSfn8UbfVDypoCbu/6E5+b841XWVn8hs /bcXW4S8QtI6BELu1Dr6gU4QVK3AZwsRLhZlcVReLYxgH78FX5ogQPk4HbTYxfWFHk+8 I+IG/uyOxXnOSf/yiLiaDv/wXtbtRqM/TEPdD1gpBVDqiddVBJ55oe5joouln1bEdaOg ndwg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hEtiE62l; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w21-20020ac87e95000000b004198b1c4ad5si4706373qtj.282.2023.10.15.17.22.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hEtiE62l; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E441138582B0 for ; Mon, 16 Oct 2023 00:22:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E441138582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415776; bh=LCc50Lc/nkF5ZvTjaJYha0Meh5UWsKUnK+1DhikfCXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hEtiE62lvLea9DJVFsrKE+P52bF09ZiSrE/eyrlcLzVncqYiwbnHK4qEFPTrRu1zc jBr2p2HuKEuzpta4GtwNPCG2j4hU8Dpsafy77Kxs1HhQylnJOdNqYJuquYgKW/8F3Z XVxuLD5y/IxTcqeK1ePEvFdTF2Mrcxis8MGtHYcc= 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 41E0B3858D38; Mon, 16 Oct 2023 00:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41E0B3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 41E0B3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; cv=none; b=qnk71RcT45K0Dzaw949nHkX7Ytor+lo34J85JW7Qs5eEZ+ENvkKo/Nt9z4cCITSwH7qzP4i0Hn10FILAgB4K3eUH/orIH6e9xbE7ZFq9+U8HVNZunpfSJy0qo62ZJZVg4dXdZ9yRmK5Xn9THgdLe2KV4IH/WPqIuKKXVkLT9Un4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; c=relaxed/simple; bh=xqw39q8o/XGP+qR2z5DNEvo7F6x86F2v54CtNo6Mc4k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=s7NYlzQQ7yB9XtQ+w4U+TDrAP32HT3tjLFPg5lx2ydrx05s+ETorYlXMxi8DME3QUMyYVUgd9lB0jTNfZdippffTCxXuOKp93/Mdt8QEXmf0fzUZJkREey9QL5Vx53S/x3XE+nix2og25hLIuJKp8vgfvkZQ48TfDh6IgXr9i7c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0CcFx025000; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr52pcat2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EETr001209 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSru032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 06/40] c++: Implement __is_volatile built-in trait Date: Sun, 15 Oct 2023 17:09:50 -0700 Message-ID: <20231016001227.2717180-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: y9SobNQHvzdThL12d1gS3UhVad6V9cz0 X-Proofpoint-GUID: y9SobNQHvzdThL12d1gS3UhVad6V9cz0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 adultscore=0 bulkscore=0 mlxlogscore=909 spamscore=0 phishscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996916785922643 X-GMAIL-MSGID: 1779869448666854590 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 9e4e6d798a0..d786f47e60c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 23f1d1c249a..73178540fbd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Mon Oct 16 00:09: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: 153117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3161676vqb; Sun, 15 Oct 2023 17:32:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl2rFoqsaGE10O3gF79RRfCU/5Dk9olkszs4GmVtJviEOXREaZ8jHqngqw8x69KpukQGrD X-Received: by 2002:a05:622a:1827:b0:401:e2bb:e423 with SMTP id t39-20020a05622a182700b00401e2bbe423mr38181572qtc.55.1697416323318; Sun, 15 Oct 2023 17:32:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416323; cv=pass; d=google.com; s=arc-20160816; b=fOqS+2BRvOfduNwlQUr5bufNkxal8ohtfio4ea7Bb2fqWu5CudyIt3k4p1vR/dTFvu EJH9UWiueoockI0KSYY2s464M3hJMxlTb1uiJ11Tt40wHP23q5F3ANXGYDWCGllHT2PM P1aTpU2To317kTmSuhs3SFC3Z8kfh7iuRMgkygesHfVYXUIM1iXcZ6nsctqnSLXL1Z2m eLDEThjiuWLrUhVD9EOIJ4SNxmTWgcp5cEVny/31HCMX06nakuUdnX1c0ipmWL9UrBix F5AGzBd83hfJ9Xu/yRvtNUgbi3h1nI6z9TozAWhCVTpMLu5nlojE0YpIYhPxHo/J3qdE LhcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=feBlR4ZEtIRVdjJ66msr/4x18JQDR6hP1pMb+i6CAGqmxXmVLI6ax05eQSkHVfK82D vF9jqiW6pSWyROg4sNn5t8en0keTSuFlALdjzGF+Zl9sVvdgMiuUqy65Q9KovR0Wgd+A ublIXuKDN0pfMRr3ivUC1Hl5siuFrV4D0Y6mKxD1nP1OcLFCqXxqnbGhjRtgSx4yNUdB 8HCfbHE0cQiEVs/E/t1zg6v4XTPh5M9fkTAkXNGCqfxwztKVyvB0iCo/WA8nq9KNR2PV pxxpaN/K5XzcfL4QRCp1LUwKxRoX/11yWcZlmRRqkVM9Iv1FSLdq0ittdG13BcWG3aag tgjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YmfV4iuj; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o3-20020a05622a008300b00417d8a4318csi4570505qtw.739.2023.10.15.17.32.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:32: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=YmfV4iuj; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11D983858412 for ; Mon, 16 Oct 2023 00:32:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11D983858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416323; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YmfV4iuj5W9BqW+Vmbm5wmwcMOlOJVTgfyqHKddfhTwXuw7Ki9rUjO1ZfztB8ml7z XKJBGHuluCPXqq8x25adMFi343a5qVhRMhoUSnC0LxPYUowZNUDTgUrkfrUY5FZ9yE 4FNuIWIsoLDWLo2BHTLtc1vsFOcnA6TzaHkQllgo= 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 C4A553856DC7; Mon, 16 Oct 2023 00:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4A553856DC7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4A553856DC7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; cv=none; b=Rpdlh9v1ZLEf3HhIl6syd9OiooDGcnFTvFTzZ2YXPItWykbBAW9OMwvKZReAerBRwWEhKAvuC32GkqrvGT+nrYoNrXRnOF0bwfndlD6PXz9DK6leL2Yu+7DFkGklF13XNLadaVCVhLoaa1o3ZN6rRocCv3AoGipu+790DDAjYyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; c=relaxed/simple; bh=C0QfeWKCr4uUzOqn+4ufr8dEtmbXQAN/FqKqiHue+Tc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=R8RX5mRSZYMUWxj0Bpw8dDhLWz3fpPOOnN2k3jdW0xl7LLj6OTuDhRXkVWGoAy2DPN/dZUrYJUuG2of4/guF5dnKML70+hQze/yzGftt1Ax0oYcu1C5AUFX+Pt+HVl322myDsaybOkL+hwvNumo5Bu0ntexkScIOL5zEdHMBkhQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0175H010825; Mon, 16 Oct 2023 00:14:41 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4n04f53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:41 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEEY011857 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrv032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 07/40] libstdc++: Optimize is_volatile trait performance Date: Sun, 15 Oct 2023 17:09:51 -0700 Message-ID: <20231016001227.2717180-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: rvaHGG2EDavNmFGYKRS1BboOQiEV3Kol X-Proofpoint-ORIG-GUID: rvaHGG2EDavNmFGYKRS1BboOQiEV3Kol X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 phishscore=0 suspectscore=0 mlxlogscore=883 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997095680917896 X-GMAIL-MSGID: 1779870018717187491 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 Mon Oct 16 00:09:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159258vqb; Sun, 15 Oct 2023 17:24:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFo4wnrHAvuMWPRYseV4tcGgi0HymLfBqF70EJA0xRAghPg0+s9xpe/FJvk67wb1xjMG0tj X-Received: by 2002:a0c:e886:0:b0:63f:9130:4e9c with SMTP id b6-20020a0ce886000000b0063f91304e9cmr7897412qvo.26.1697415840444; Sun, 15 Oct 2023 17:24:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415840; cv=pass; d=google.com; s=arc-20160816; b=VeQ0TvGTxk9LPC/Lby5bBFLLzZnoefoxgBvb3OjHJnu6YT+UD+CKSrEQuHubQLgEvJ K3D/A9kvw1gNvv+CHqScEItnLF+zgrXz4O7ye9DZMozqmIDD7Ry9dblre9IYF8yuwPIp UT4sd3JBAVZbxSmWt7rhaQKXEOIQURQwBxShTR+cTb6QmA+VMfsmX2qQBGuurI6HZnOR /WwOgU1OqPuZbTCXapTEOhjzWpQei6im0rovUQz24+P0k6LYoEfdV1/hS/DbX2Po+C6X lK9WV3EZT1g/JBT4IEM7y7RDXnmuARw/QaIzDYOiGiEi9NEcWMjrbV2xF2H9AVKGLNN5 jP4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=uCn6la/LnywEk8VGHBHwuM1J45opBpq22UyexGLdNSo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Pd5Ut46iwB6oN5Ttv/MZdm3bQYZXyG0nq+C/fTMbVRaccMSeNrlJX4C8Z/sqnclNNh +85v7LuMy6D53VK23xfGdAT/97PPl5V0meSKs6aN+mHWaoQLVBeEMB3wdfVVSoOjJqpG hPRjRHZ5179IXNcYVJOUyH0k6AOk6MPSfR4lFz/R+Xeq+2C87iC1TNlbkJ6Y/pcsUEho cnYz/s1ZLMC0wH3RLDqRn4k1g2dkAyuQ8NVOQwo1WA3UELvji2y2n33gJWmi82lNwQID EPbaHsdQJ/YFWfl7vrult5wnfuT5Bq/csY6SWOoGvUr32/fOo3FHUGEvuJe7ceY4IW4H syrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Hn+cAbMe; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u10-20020a05620a454a00b0076eef941267si4848108qkp.495.2023.10.15.17.24.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:24:00 -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=Hn+cAbMe; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56F1938582A4 for ; Mon, 16 Oct 2023 00:23:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56F1938582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415839; bh=uCn6la/LnywEk8VGHBHwuM1J45opBpq22UyexGLdNSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Hn+cAbMeSOpPcB17Pwo34cjRCJjV3/0Ug0e8LvmwZzt4JeqWH91wAXmQ+unnrDh8J P4By0wJLF4VI6Y/cpAtRds/jeI1j8q1AdVACWo9YE6lPDH+RjWGW9TrqtU0n+QIvsb QGZRU0lTX7t+6WvNCgUO5dJLNVMwbm6Wpr+E60+I= 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 E329D3857C4F; Mon, 16 Oct 2023 00:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E329D3857C4F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E329D3857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; cv=none; b=m0ZKyUUvsAI7mXb2igNhJGeIBwm7nIAKWDiFuag6+9/+L27McWTN3vuzSCQD9p4omozM0A9QCmwp6eZ5sl/8X7Qc0kgN55MfW7ZZaGKvYBFKc99NktYBBaIjvZxosk6td5dJ+Lb1iRHpJnmoBAJX8MzzWYlS17r9PykSpfMFabo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; c=relaxed/simple; bh=DsGPZkxBCE2eoHEIcJJLN4fnWE8R7+pD0SokPGhsVvs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JNvvh6EfONaEWJ51XiYMX1LIiz7NLfdLEZ3Hs/FpMzHWMoxT7H03+ky8FazdWuyChn5iM/o8q9TYIeaWFAWukJJrgjzRWmmRoBlYcKrLn4MbpZWWU6u/1E1z3DifxZ+BfoASoI+0n8/fxoJHPoXEXzaycEy2uxfNbuJ+RHZKi6Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNxYn1012948; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr517ve5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:30 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEG1027867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrw032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 08/40] c++: Implement __is_array built-in trait Date: Sun, 15 Oct 2023 17:09:52 -0700 Message-ID: <20231016001227.2717180-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: XUd0yaiZGr-LPgSf9SbBlAB34i6H_x5g X-Proofpoint-GUID: XUd0yaiZGr-LPgSf9SbBlAB34i6H_x5g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 mlxlogscore=717 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1779869512481342916 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 d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 73178540fbd..e1358afcb3f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Mon Oct 16 00:09:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159276vqb; Sun, 15 Oct 2023 17:24:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGs+m302qtanWniGN3uY/QQ00e1eAyB+pDS6yEwW1Ib/xTA1ZetC39XXWghXV0l9VHCaTcJ X-Received: by 2002:ac8:7f8d:0:b0:411:fa33:f0da with SMTP id z13-20020ac87f8d000000b00411fa33f0damr36113956qtj.9.1697415843744; Sun, 15 Oct 2023 17:24:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415843; cv=pass; d=google.com; s=arc-20160816; b=eh0nDkcLnQZkf0vRsJ2XGkDl1c6z+FK/hy1A02SyiTe8/r1AriE4/y81mAanpB8590 41pGlzFidUk9D37bXLcm0o7MmoSh14IKqqkkwQuY7l3XUKRwiP7caU8Dr3sPDi13Yeql Pd5lyiV97FZR5YaMRVC/4P1semWyxjgd9IE6U+t5Ry0LHeVP6Donz/kSVq2yYbm9qRGe xYsKetR2uxX9Z6MeuMvScNA/lRr3MNoziyX7MirSnfpLliwctAUNaEY7OIJgtL0owfLe ppSrrmKkquJKOk/1H3lWklVBx8QGYBYD7RbvlILEF0hjrxJht6w2Gss4aPC59XCj+Cho T9bQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=IkjewVrJ3473K8uan7c1E6WdGsG20z+wqmuVvdmVAThfX94DeLQc1T9z1X89BvGDQb tnzqx/c6rnnubysQRSAElIN9QxqeVhqRCf52DNBp/3o4X6Mk+t2dPpkLhUhqtb6OPVdt U8u/ts8iD3CXzXiB+C8q7gknTNH3goVnPlOVhrITIkFSbmbvuxyc8vpSQb44bOtwE3xr WOO+u/d4M2zgoX4FP69V1pIWtBYqHFR5IvKJCtanvTuWhyW14pQY018FP/1248cxOScr Smrm58Lu1/qDMM9vJ2SzuCF6fwQEomS9KJ92d/L33on8DB0JbkKT0VojPOcHz6VKpEck +/8w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ntRiUweX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s10-20020a05622a018a00b004197d6eff80si4467805qtw.588.2023.10.15.17.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:24: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=ntRiUweX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7546C3857030 for ; Mon, 16 Oct 2023 00:24:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7546C3857030 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415842; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ntRiUweXuFv2vuFB1hiGdv+QNtVFb6/0eYLWzj8NTTbSmq7zF2drP8twGbuh2DzGN yKsOkc7QcWUZcMy92oRSpNsf3J7l+kc71oDM1VKwKVfNDpVXFHOOg8lbm3yQMJyODH GRL6ISQcuo8BguI0Q4Z+zs5JsCMhNtkq/HOYPN0A= 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 9C41C385772D; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C41C385772D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C41C385772D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; cv=none; b=O7/cKitCWDKb4xGbDp8jL9ldIpyZWq31rKI8YJdP5xsDQZhH+PSwWoqJpbpWlIXr+DdMwYpHi6bhv89CKjTZyQf0bwhJq/3oZFX/ac8seQ23hYrGXN/gu9ggjOdN1p0zFJieVgxOqdMt5XGngdqnwIdaIbpbRpBuItuH6oIG5y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; c=relaxed/simple; bh=MOf+TxQspyRPPZlZdf9KhTx3QdQB9mHppfT5BFfsWxE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fkwOvut6mr8RmHIcjbYtuhbaJLn7U4TN8nBagVhTpdDfg4MGmWl8yA/HqbGC6dwtNBqFMjlOJn2kz3NbIQo+pJIF2cnr+AKDN3hzDzPnMYrqxul85X6kfD3KvMlL9CMclIhhwfICunhaFIS/FrUZ3Lg2MEl6GGZJdrP/97cAzC0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0EHTS003950; Mon, 16 Oct 2023 00:14:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fgn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEq6005468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSrx032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 09/40] libstdc++: Optimize is_array trait performance Date: Sun, 15 Oct 2023 17:09:53 -0700 Message-ID: <20231016001227.2717180-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 4oVo-aE_yvT0P89EwJGrxzicq_F8WNaS X-Proofpoint-ORIG-GUID: 4oVo-aE_yvT0P89EwJGrxzicq_F8WNaS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=597 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997263374731491 X-GMAIL-MSGID: 1779869515561329405 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 Mon Oct 16 00:09:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157679vqb; Sun, 15 Oct 2023 17:18:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDBXIgbzKOvBmew7K7LAGcKM1iTsnb/qDXmQAKDtQFjrUg8KDk0+zZlqw9PvygPyRQshXl X-Received: by 2002:ac8:5748:0:b0:417:a81e:d730 with SMTP id 8-20020ac85748000000b00417a81ed730mr41262279qtx.46.1697415525572; Sun, 15 Oct 2023 17:18:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415525; cv=pass; d=google.com; s=arc-20160816; b=RuiALga+VxuK6gnTmu8BSx06xlLUD7PiK2500PtUHX3c8Pc5UhffOiQo2uPPgC5h5K ZiYfpCeVNH+fbIcICNh1aM0wKW6Nbzmug7hu/thX6By4gKfpiEORiu5SymMHZpJfkvqr tdPoj1/jAvCmaMb9BdqqcK39yuGpOgdeq0DClhtmyALRA3Zf5QfDEuxh53ev9ZwmGS/W G+rImgVhjdvnTJLYFCvnLhpujXxXGG6UQUdVWQ5ZKuXZcG9UZGyAujbfOMTrNjEnuvbE bl6bEAs0KC7ZduCB8umpcZtwZN34nnNM0K/Pkyl56lfuENGr17z0QYJRp0arbLTLrCER /Vnw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=CW3eyBpQoWOoBhWJjUOB9V4bMVlspSyZzlNmpSj3X2E=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=v49ln6GbRsmwOm1oL3pYh5Mva1N43+IFQyqAEmB31XIKFLMAevR/zTfSCbke9OTQnQ Wd9qmS+AeO4XYzUxbA2CIjUa+mG+xmV/N2d+lbAX/1ZMQczYew5t776IFQI1588Tmk66 MFtK03Wovq0GhmVUxN9KUP8AHCOMsFvH+nmKod4KEEcLsSH7uQ4pAceqGbRrmCgQb4fX ZOzlpfHGkEc9fVyfC5AIUqkS7nXutQgAWawDq5sxNt51y18bBYmIumJWuOmkyMcM13Ma jUiQN8JlCvMcR234VwhXlk5hV2ua/f9Ud8KqHBMDdCDE85BqMi85GmWJDd4Pvvy21gCS 10tQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eOJblau3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t2-20020ac85882000000b0041961b33c4fsi4517557qta.808.2023.10.15.17.18.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:18: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=eOJblau3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50BD538582B0 for ; Mon, 16 Oct 2023 00:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50BD538582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415525; bh=CW3eyBpQoWOoBhWJjUOB9V4bMVlspSyZzlNmpSj3X2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eOJblau3xL5IYpBi0LNk/j/OOEZMaUT+4jvWMwjnvCNOtMZP+q04X1pdyN0OY9MDm 0+4HdvO1IgFKvEepouN8CkrDUQIO8XDgqjcHVFcxmIWy8Tr4HMz+Na8c5iAztQ4p03 YlT8e2KZQ5YPG9vK1u0UC4IF8slGsRrFPnJawjdY= 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 6EBAA385800A; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EBAA385800A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6EBAA385800A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415270; cv=none; b=vNbr+H/vr7tZe7iS1ZPKSsS/P3Xt+ZT14j2Wq9tbwCNoxu8uv2ZcP6SDI+R3h9fdgKiIXxeAUUWhcP3XuuBLVcs6XBcrGhYUnksQSn3U2rOdbSuUuBB69QVq0Ho1IbPwQwjdF0KyBp7h04STwB2JFltknoBg2d5oR9awDTXFWGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415270; c=relaxed/simple; bh=v2lsRGOo/nCN9eGyZE99q0QV34l9yaMPagXjCKrcMeM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=s3h/ezVabI98OBwGTIkTarrVSbYW7nTUZ5m6Hvenl4tgxgL5zQJsno8U5KMUA+pNJTO+JG80rAe9DuxM8BFG2Dng5iR+a+iw+2pHPwXjJqyN3gfidmKTEl7DGV9QiYNo1Wp+adX5yCY+uRv/4UQYMeYmdODUWSr2kmDBy437EKE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G07xCW012606; Mon, 16 Oct 2023 00:14:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr52pcat0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEHN010496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs0032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 10/40] c++: Implement __is_unbounded_array built-in trait Date: Sun, 15 Oct 2023 17:09:54 -0700 Message-ID: <20231016001227.2717180-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: U_3TR8EMvTXwWxiXRGZPCcpK_p3Firvw X-Proofpoint-GUID: U_3TR8EMvTXwWxiXRGZPCcpK_p3Firvw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 adultscore=0 bulkscore=0 mlxlogscore=604 spamscore=0 phishscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997094718165190 X-GMAIL-MSGID: 1779869182253717898 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 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e1358afcb3f..0a2699be476 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Mon Oct 16 00:09:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158978vqb; Sun, 15 Oct 2023 17:23:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFgY8klWTXe1LgXFhQP2foLa7FF/uDSb5yA7VisjGxSiTIihFEbOBAoLlK0xxjdmS1rJqp X-Received: by 2002:a05:6214:21ed:b0:66d:4173:5ad1 with SMTP id p13-20020a05621421ed00b0066d41735ad1mr5109513qvj.39.1697415781514; Sun, 15 Oct 2023 17:23:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415781; cv=pass; d=google.com; s=arc-20160816; b=Gqi7ZNEU67UOshUwtRNLXVM04UpzZoYp7mqchaoeqULVsUYKJ8bXZXOHxJFDkI41FU /OKuu3gky4PrfwIIIdjTDc9JRSzmVi1k1e+BN1nCFPkye9HhX7LGc9Mgv26tMkgu1Hhl QFOcVmSc4tJ+KKWkKBuC5UCkt3Th757cb0jjY+xRc+FgfgQAEGrQhNh7Z339EzqSrCcR 0djqQHoFZ/4vLgbK3Mm/bo08/kGkeVDtQjujW1GiLbLccdweL08ivWHkfaaaoQpjv/+o cOUnALaB+25EF1a3zfGXdyOSMjW3EpuKYMgrC+12IvfbWHB6GSY1gJiW7FFykr7p4Yen Rjkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Zhu9gt2zajQeuWweQVtoMlEtTvyyFF/QAdbjXamMDogwDu4XXuiBIo88V/lLc6U9YK vWySkd65Ge3HjtrEFnzcfKEEEf8X87vGUzxZ0mdFI9BC6Z5Ru6tt6KxuulQkNMvYuI3I H/T8uRcirGy+7gLjdW4rs792j/DORHkmgzPMQMUHsCMl7Tzk86NrWU1AaNV+CkmxYMHx 4hyC1ANANmpdPbaU/0GDn3dK1tCqQm3ZLWjbAmbL0gq81Aul0cUfOPfvBwYfAXt34HT4 +u/4fPW/G6LBOm7xsWi2PsMw4f6ak6i2bVwePmp7dHKZW+BEfdEshYAKb6GRYRknORwl K2Rg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bw50qLtz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c26-20020a056214071a00b0066cee07e1fdsi4573236qvz.315.2023.10.15.17.23.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:23: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=bw50qLtz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E7F13857027 for ; Mon, 16 Oct 2023 00:22:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E7F13857027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415778; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bw50qLtzCz/7e8lchYr0DFZ5X/F2GajorOZBDS+dSLvY6qsNpN3I3FPsvQaBO625r 9axxCjtXSyYN1l7LMPoOAkF5hexVScpJ/kuFENK133POqc5x2Om2AgKwmQzywofh5j 1pCuxh7QmeL2srSFBX99xrRLp7V4TGWdSASj8FHY= 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 658A03857345; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 658A03857345 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 658A03857345 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; cv=none; b=AXJiq206We1WJwacrrFUUG9tjbz8vkuKVl+ApxmxYtBkWGtvuSDClSg8h9kFWQP/DKDBmLc5WZ9x8Jyere67pcxC/3xtOXFe6xhgEHKqOyX+GR4u4BZM77M7a8ZpV6B84xWv3raKpNnWSO68jKxTIn83hqqsGUjLLvdLyjGfSMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; c=relaxed/simple; bh=Cijkk+1KKS2ERennoIfTZ8dR0bWLbMoE2sdRxU4V8ZU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sOygGQ/n0fMteNRi212PTZVfpNjADfuWE1gQdHRydWttEEjES9TrDf2T5/jt8nEns6Z3GGESXo5f9iYJLOaAC0ea6dDapQyEU3GVRvR/1BOWlNxX5ZGCz7uz4kUtO8+3K4pUv1c5sOYe/qZ81aRaUgfGV1E1GLy+n4urSE7v9RM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNvgwO028057; Mon, 16 Oct 2023 00:14:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fgm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEMC005469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs1032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 11/40] libstdc++: Optimize is_unbounded_array trait performance Date: Sun, 15 Oct 2023 17:09:55 -0700 Message-ID: <20231016001227.2717180-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fXNrkbPOVPxyphrbuz4N5iFs1hLg_chA X-Proofpoint-ORIG-GUID: fXNrkbPOVPxyphrbuz4N5iFs1hLg_chA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=627 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996817880022434 X-GMAIL-MSGID: 1779869450906661411 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 Mon Oct 16 00:09:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158487vqb; Sun, 15 Oct 2023 17:21:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG36aJ4R7y/Ttt9pSCJBFD2KZKkHWwnA43loqo0Nk00FjaLQbAUbbkVFz5c6iVm1Rf5dD7t X-Received: by 2002:a05:620a:2ac8:b0:775:ce75:9b7a with SMTP id bn8-20020a05620a2ac800b00775ce759b7amr35378988qkb.28.1697415685596; Sun, 15 Oct 2023 17:21:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415685; cv=pass; d=google.com; s=arc-20160816; b=K9i6BUC533LrvC4QWvazVi4gC1g5X7F7uWJa8K6WgTj3HA4GSXhgxjy2k0eGSE5J9I Sru0VUTt77YDuQ6pFD5NVMLScf13XlxbuqKmzSKepl8aR/d1oFVR4Bz3zr5dXsz7rEp7 Gp2YIB1BocBUucScP5RrALxg9VE6mU7trXGyAL2bRMgpqX80mXSRbu745sdNGDs/EQha n67qmkrMeEcmFgeKzNsDx0ebXDE5XOEsnbCrHHaGElwT2mjyRA1BYleWubsN/h8pCb/l PThHTV+djnTbD4XkQKY/v/JLnIq3kXxzAXlNT6dJc9zfOfe5JRLgG37GuYTtETjhDKch Cbfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=giX39DHtXANzYyCgk0U07cVNW7IUM4JONf5CCV9Ulfg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xrA24fYoYQWqUmJ0wjyahjVh0WFCZJ+U7nihr08qeB63/MW3KZPgvzt82CnkePEh3D qUbcrEyMYMsUvRimGL3aAI9mo8RhJljwsEMzHnffhI+vAGiFi15wmuI2pc8jdykNErFz Ct9D+2Ihln7CLdymm3loNPm635SYhZNLm660l3MQKII+z+FKFESrUkMsiBLq57QuReOO ttaP2YGgJkQbQXorfA5C34J3rPWs6LrYqXVGAdFX1+OULjXBNQ+CWbeavMzf2QoxmvPB 5C4rdJHBtwgAr5QD16evAvfCsWVrRCwYpxzuFsGP5ZuH7sKH3ndfxU/EzAgOWvVoQA5C lUSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZjZNlBSO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ea17-20020a05620a489100b00768064b6b5bsi4562019qkb.755.2023.10.15.17.21.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:21:25 -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=ZjZNlBSO; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50A9D3858035 for ; Mon, 16 Oct 2023 00:21:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50A9D3858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415685; bh=giX39DHtXANzYyCgk0U07cVNW7IUM4JONf5CCV9Ulfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ZjZNlBSOp+2Vy3nQ/9Ser5tadiJ764CLv5ki/WBCXexI3apjfZT8gFyb6DV3abUyV B5G8WjUQAIV2S9CqMwveE7xdkZpYyTMKBPSeOjBNvF9bWQPDcjbquiFKO4yeKTXzNv bk2aDbA4S3XMmb7bS3PN6z1s4jvVNrqa0vBKdBl4= 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 B39253858C3A; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B39253858C3A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B39253858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; cv=none; b=H+tHkuhAlQQrc/Xfaw973yT6w0+6kq/47Cf20swxXyUYLc/f+Ioi+4itApOMr8zT0SC3/9Mi3+3sKymXp8TeeG/fRNrsozGb55ztI0wmH7LbGfBeNsCI1fcVGKJq/i4GBOEd3CGmXzIyrBeVwsHohYNhAyEQ4Us9dUipZysCIm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; c=relaxed/simple; bh=ogzMGBylxc3cnE5HG04I36bkS4DXO9/Nng4O0i18Njk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Sa5y9rEisldx4UxhpajaKctr5FSWaIyW9q9uMhJCTU6UPCaL05gHNqcfgkLwL++oRK9li6a0KQ0z1/MSal0BuULmySDZZO5COICp3ZKxuJ8yWtKfloAOs3UYDOy9wc9RyzISYB5Vgg8DRMZ9r+FWM2HvSk+kBeF+iwJe5yShqHw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G04Ha2025143; Mon, 16 Oct 2023 00:14:28 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr517ve5p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EECn010497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:14 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs2032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 12/40] c++: Implement __is_bounded_array built-in trait Date: Sun, 15 Oct 2023 17:09:56 -0700 Message-ID: <20231016001227.2717180-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: feHQBX7Q3Gbq7aoBsNBDKiiXDr8AnkP2 X-Proofpoint-GUID: feHQBX7Q3Gbq7aoBsNBDKiiXDr8AnkP2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 mlxlogscore=566 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1779869349451307897 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 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0a2699be476..32880754020 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Mon Oct 16 00:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159831vqb; Sun, 15 Oct 2023 17:26:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzzaDYvzR86SadT3HLj7wny4v0IKZP4CZywJBaMFo26HgXC3b34vKbBkQGh+UPWkAkpSsF X-Received: by 2002:a1f:eac2:0:b0:49a:6742:b176 with SMTP id i185-20020a1feac2000000b0049a6742b176mr23903898vkh.16.1697415960799; Sun, 15 Oct 2023 17:26:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415960; cv=pass; d=google.com; s=arc-20160816; b=Yvafk9r9B0wicvwOaccs4KdZlRTBowIQrWdrGnkR9G48YDLn9SVGJDlDcQBp7U1skX aF3ddRCXLf5vfmL9e5H+eCGBrvT61d1QVSbsKxq/O2/nChDIl5szxjvT89x0JL/0Ljfh wVnV4J7NiVQeY0rzBxzWls/Wf/lj3BXuoJHrGrRwiiKe+k+kNkvBCmA9ZiSJuD35Ubad MnPmFduZ97Wv9Qi/i/R5/QrgpSoJ4soeasb50Od/eKPFzWf2WYv5MAoV4+Eqn/i1cu2g SWJFU6sbWht6YMXh3xWMKI68WRRiW8n7FVCeigrIZvWkCHprp7UwCX9fIroZj+zrwfqg pbyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=X/Cn0FZFoj8o3agmctC5Tijl00tz3DQ3t3J5WFfZuxNJgFLJ/DQC2Fkdn1/BPgPwn7 TTDS8Hn7zR90milDoAm1jRNFKtxN6VCAoYRLM2cqNPSPrsTE/QckW7FZr47EhV/KRpNG HM2VocNfbq0XSrEU7TgIJWbwvy1CQQC/XtTwBdAlPbyWF/S9X1JLTou6pHksqWxBqGvn bFEUhmGBVbclf9fohIwAu+A20xExzw0bZ5ENy+0ofUEV5CP6kOolrvX1rhfVWXKDM3XK OJEHZkADrzbf4W3TWdOsvbNze/7aA/m4Kr3Q2yniJuUlG0NZdZkiu1f7AsDAZrbicSTQ j92Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uwag0DZ7; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p12-20020a0cfd8c000000b0064f73d0f5b8si4423311qvr.18.2023.10.15.17.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:26:00 -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=uwag0DZ7; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80CB53858434 for ; Mon, 16 Oct 2023 00:26:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80CB53858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415960; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uwag0DZ79+yMBPHpfSPaoBV5MZV6eyh4M7Vz9YtfYyPh4/5cPIMRuHv0sFdlQG4I+ o14ClogxioP7RaW47zwQqvAGKRWCyuXT6NqsaZbOvcBt1M9DMVBvXMaoAE4LdpkVJz +6yiaa8zuBchpJA/iB/QjqVmAxrs8VRwUc+Vejww= 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 CCB3A3858401; Mon, 16 Oct 2023 00:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCB3A3858401 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CCB3A3858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; cv=none; b=TM7RbIjvLMgdnBtvs9Yy6lxcG7lgxseFBTHg1Uk/mBzFtdmLtfGSwEjuNTn3DBxSsO6Udqbf5WFCs/jdO+IVXwgp8EV6M58Y/6QfQiQ9ni/BKd3/cKbklLjMclzPiX16yDRDq6isyF8g56DKRre38XOsExCSXffryRZJRDYRcnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; c=relaxed/simple; bh=bh/DHfcrUuildpW5273OfXvIzy/3HS7X5XXA7BH7W8A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=eIHmfz7WQVm/iJ945+PTuwQdgg9C+inRtbtFV37hkMcnF1U0X/OqifH+lU5ZM8ageyfvxH2yGc15BpvPA2EmC7Ro/P8AfiEj5DfQXwHvVOGgM5AQb5MGb3mt68fzqqif3dBdYkdPX1OCNDpIr/qPG8Jj0k/f2I8ZDuvKJL/7vgc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0DIVY018381; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4a8vgpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:41 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EEXg011858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs3032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 13/40] libstdc++: Optimize is_bounded_array trait performance Date: Sun, 15 Oct 2023 17:09:57 -0700 Message-ID: <20231016001227.2717180-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: T9DnH17ElsZOkrG15Zf_aKcO809lNo7R X-Proofpoint-ORIG-GUID: T9DnH17ElsZOkrG15Zf_aKcO809lNo7R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=620 lowpriorityscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996999788880715 X-GMAIL-MSGID: 1779869638758951409 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 Mon Oct 16 00:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157913vqb; Sun, 15 Oct 2023 17:19:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3INVUc6CErj3KyrIwSNKMsMTHMWqKKGEnU25HtT0A+pBt42i0frNjKlp3MNQVZA+fExVK X-Received: by 2002:a05:620a:b5b:b0:772:4851:163d with SMTP id x27-20020a05620a0b5b00b007724851163dmr32724118qkg.14.1697415574887; Sun, 15 Oct 2023 17:19:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415574; cv=pass; d=google.com; s=arc-20160816; b=vAlVAE3HiaYN1ZTqtT4vMDrUSudkDYB/N0BzAjizJ/IEj0CqOVq0n4gio0HWhcd0GN nK7n1rscUjMeXsOEB/5/npBbIIzpOL3qMlQGZKRnsGhmXhFk+e35mmIRGT7Z9rO9+Jx+ 0GdKZiKccn44jDGnY4vGQkjj7MEpdVri+CEXoUVX1d87B+ZWUpDY54KcmnOcHK4ip2/c ezRB0vuBV4NftdXuvgSmE+y1bKaZ1gE/SsWjYNNlOVN/D6RdKx6PCMkBI6CKj1srlEc2 4ZIC9KBJqaVeOHtzvjtWxpPhrWBhwHFsqHVyN/P5vHdFNpbm1PHk62Lu0RhqG2Im9Cxq /S7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=JX69+/RpVRgq1y9CphEvESzuc6JFE2In8CRsEYYDATA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=AaLeL3AYhSvH7ozRR/p+MLh2kYvYoW8d9xdUkgrnx5TlMr+zuF0TY2JMaecFMuBVO1 YOOGfZULpBp6UKVbnyV1fZldXX4Zl4MX8gkWjiGZyM3QJoNtAI43yn6dd5Uy2e1v2Rqu DEsmsPSYlDcGZXhIsz5zgg8Ayn+ziGe6PI+rw8IJ3rS14BlFneZNMu+6lTw2EYiqjj+U flytVJxNjwDljKAaB9zbrduKM9jGGFn17B2I3wIrM8OIM3SZWj4KkR95FeQarsm/G/dk CbG95mAP7uhfYtbSFVNFK+b/o1+XExXZPH3ntmDTOXezWCsWhkvZQWkU28gY9kHGfNDL U7Eg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=t69bktJ4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qy5-20020a05620a8bc500b007759bc40decsi4510305qkn.106.2023.10.15.17.19.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:19:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=t69bktJ4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF6D5385734B for ; Mon, 16 Oct 2023 00:19:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF6D5385734B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415571; bh=JX69+/RpVRgq1y9CphEvESzuc6JFE2In8CRsEYYDATA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=t69bktJ42Iac35PhLWyKquJSrA2j98MpJQ6YXk/xDrdWv6xgfIObM3rI1b1p/yVif VzKxwj7jGjO6iiESncYDvlgwnZz8yKhQjKq/NvWUsOjgngm9yWFndbEuqf4LuEJ6P+ fvQxCjMIVAC36LiMUwm0x9Ii+KR995noq7eNgAqs= 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 A3ADE3857B8E; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3ADE3857B8E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A3ADE3857B8E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; cv=none; b=Yh5/TV/0TQmWwCoynxgtZl45ZJkRi1KRNmtNa6S3Z5flT3pkAPk5AWSjWf2e+Z8H9SaKIA2+T+vtorTIJMwPUNXHe+sjj7buiFOAeOOEvNNZU+mhJq0LnMzqdA09ISNS6go9lwN2oAr7jjV9EfFCInw6/4HpHLTq7uAr4ULcUuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; c=relaxed/simple; bh=Sxcmbc5LbGup6HvKWahgNZEiqjI/88JvXWHZhFg1oR0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DEZTHI3iKULzXdFcSshhdn3lQTyUAc6cPGigZ5iNetqZtFwm8c3xdaYRbPjxQQpY8ebksrVU+RC1DlOtSdXwkbNConymDWwCFQHM4YloxO+lhfgEOgvzWgcDowCpNNQFdnNjHiJizZ0dye4+NBWKCpSiJWJ57tx3hZKjtuSYQrQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G08X0c006729; Mon, 16 Oct 2023 00:14:28 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dk4by9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFIA010498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs4032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:14 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 14/40] c++: Implement __is_scoped_enum built-in trait Date: Sun, 15 Oct 2023 17:09:58 -0700 Message-ID: <20231016001227.2717180-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: -cb_TDx1EJGEmLUwKKgjAzrg-9gc2NM4 X-Proofpoint-GUID: -cb_TDx1EJGEmLUwKKgjAzrg-9gc2NM4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 mlxlogscore=586 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1779869234008751859 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 6d6dff7a4c3..e0e3fe1d23f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 32880754020..f56ab031d5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Mon Oct 16 00:09:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157325vqb; Sun, 15 Oct 2023 17:17:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGC+cACoPNiDxpH/fRiAURTbH5WPsWx9mqis+ti0sImFW88akn/O0+UMcGee8jMzWQKJyQB X-Received: by 2002:a0c:e50c:0:b0:66c:fc98:1da6 with SMTP id l12-20020a0ce50c000000b0066cfc981da6mr14289350qvm.36.1697415454723; Sun, 15 Oct 2023 17:17:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415454; cv=pass; d=google.com; s=arc-20160816; b=YHC5szQGJQv9aQbDmW6MOJ3gJEJQjwUC29mPvDPLh5qfeoBHoylXDDcYukbXq69OMp z2q/wFphMDtyiprNPl0j9WQnfOhkqf57Zel8RLqp3ckfHrvlGj1ioGS/f4UdUvt0CE1P VH8Rg/DlD4sVDINk7PABzEMr8Mk/hnOeCVSilmuHTjC7mXsQ2E1bioKqtK6/PgYmmPHo O/Z2kaueGGx9Im/e5Bg46oN8NgGTuam6lPtJF4KbJ7QqYc91mLqVwaKInsW2btbSiLiq YFzaOE11OtmtD3tAxouJAFaxs5/Y0G1GEQZyV3951WT8/Xpa1jPTq0QuCTuIjNFzGV0p LO8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vU32YUFpZvaZRSgDNUcQvHRmNFXec8HnHqC/uUdQ+ar7+8dnbY4y0QQVj1694pjXaw vRVcrkiaFsd4PsrNDRtnOcOJMGOpaO+7WDSM50LC+b+1wNTusIKpuDV+3KDfOeRjyEYK hcW8ik1ml+HzBQrEaoq19ogSm573k+KwLpsOEAeAlRus4+G/L1WzYbUT1vNmb/XrtTVx iZT6wJ9gItkxVJsWhI41jY53x1yB5R8QIcBIrc6LbewF5pJkrEzce8lbAN/iVwtKjhsd QDlzKbCA51uu3t9vgsjekRIJpvfvmDBDi7nWO80ss19mxympNmC2xQwviLoi09syQonC XceQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=If71YWJi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ot22-20020a05620a819600b00773d6c99af2si4560867qkn.449.2023.10.15.17.17.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:17:34 -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=If71YWJi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70D533858035 for ; Mon, 16 Oct 2023 00:17:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70D533858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415454; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=If71YWJi4yU3Bpxn5TWR/TzmhmOWbL4+iirapVQdkBZyKRtdoVIoBKZP495apJa22 UbPpqSi+A6fy1CI6snrJQHwFMF3GoFT4mn/tucPW3OPqEBWACvp7j/pnYB0o2HD3JI tSe4YmmJjXdyc/FUTYsJ3WCPk8xqdN9FxfpO8m0g= 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 BDD18385842C; Mon, 16 Oct 2023 00:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDD18385842C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDD18385842C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415273; cv=none; b=qhWWK9QfhZylatbcPEFS29FzzAXoDYX57UT6Iq5wkLRkzeT2/TwZSfEGvLASGdEGOlIe36sJRd8xtP0ZMJT0Olvvv9+l5WDu3+wM/YPmPdeNbo6S4GmtAOVsO9HLLFG1HWgi3+MA8di0YZ9vmdjvSk1LIArswXiDBWOX1vsYGqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415273; c=relaxed/simple; bh=Nz7P73GKgdaoysk+y3xwS5zNXk6vIepk6igOSMNcwIA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=w3WXQBRJ7d2cyLt1ExzkyT0mCzOUFjzPYoXMAuwt9bmAR2WZiTOfIeWjltWNLuXsMPLcGHqKCvNKi6s7dN5o/Dmhv6WGvLBycgtVDPzRbbygthGxUjP/p3Lt8nxf8j+IM0jtQN/bH9pRsaU8J4sihBry48KEydOZaV1CEwS964o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G08t1j003274; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kq4d2g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFbw001212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs5032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 15/40] libstdc++: Optimize is_scoped_enum trait performance Date: Sun, 15 Oct 2023 17:09:59 -0700 Message-ID: <20231016001227.2717180-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iV6ohZp9-37UY4CmBjQ6M1KxRSnFgghH X-Proofpoint-GUID: iV6ohZp9-37UY4CmBjQ6M1KxRSnFgghH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=889 priorityscore=1501 impostorscore=0 clxscore=1034 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776994899316432234 X-GMAIL-MSGID: 1779869107836040136 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 Mon Oct 16 00:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158461vqb; Sun, 15 Oct 2023 17:21:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX5NxI+EW2FPAhTb9Flrxlq+Qd/wZQqC3NrmMMXYuuYXf4b3TnoWikU7OdoHs0SDXlaIET X-Received: by 2002:a05:620a:4712:b0:76f:5b9:3f29 with SMTP id bs18-20020a05620a471200b0076f05b93f29mr8773581qkb.2.1697415680917; Sun, 15 Oct 2023 17:21:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415680; cv=pass; d=google.com; s=arc-20160816; b=hayd8ry38JTsWRYdBq/Xd1K5LPYEfBoUKLJ93dBVpM53bIIQrpwFmg/q+XUm+8sstq L+70+75x54cndVkIMobtNM371D6RPYHg6/B1NPqtz4kLDdKw05SDMCYgO1R9II0/Ibsu bzql01TMvkqRZ1brJX/JIWPIiCMEbRyUyVhlRsYywMQs2c/tCVAW4c9dwDRK6J4yOkBJ RIu4SWfi2/4wnF6f+ESYWEdoikJ37l9pmp7aVQzmFRLS3FbLdWk8ZRGQmdHzsRnzrO+k mMOpwsIo79fG45jqKay2Saiw9lLsQVonNuJPlRTeI0aAZHeGFHB4fJ8klvM0Bkf00su/ khww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=JbBAXWTavTZm5Qh2adX9PXFqb1JO6HPcBmYSfB3Lzxk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=XWzTnsRwv8jQTxDZaHkLg6gShi5Op4EFF8yfwIdL/X1+VslJLkxxc08aEacDFK3Ukl LmC3fiSjrUGbVt56MvdYGPE6kblDWzCTL8JzBK/lf4amoCjnltEDrvrF6OLK6bNjT6GJ fSFGQ0Z9d7C1vkD+tBJ5AZ5F783hHTEv58fWf6nrOw53E6LHMP7MbU07ETntGLZV1h0M y95XDat7GJhrsKH44+Oc7KUEZR1N981/aoMTenLb9N2VCcOKHvWgsNnt5qcFpBHsURM1 yW/oiWoyaLzi4eVOGSHh6Ib9ZWzDFEyBFT9WRaY6U0hzOXrjDsvtHdJ+asTRIV91puz6 ZR6A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fVK6d+Or; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h19-20020a05620a245300b00773c56f9551si4609168qkn.647.2023.10.15.17.21.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:21: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=fVK6d+Or; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6B673858284 for ; Mon, 16 Oct 2023 00:21:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6B673858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415679; bh=JbBAXWTavTZm5Qh2adX9PXFqb1JO6HPcBmYSfB3Lzxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fVK6d+OrA8BBsUr76vOH/mzqbAEK5MvM9KWhNp3Td0PVOz69ijHfhabu3ngkbyLBB I6WybUQEv9+IZiiNfTwa67vuB+kZcyY9ENcHWdfh1ey/yZ1tjXqqffc4CkfuWj0YLT QrOnULFP9wIX6oIF9d/DO5S9rSKJmerlkrChiryc= 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 D23A7385841D; Mon, 16 Oct 2023 00:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D23A7385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D23A7385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; cv=none; b=IhuLsW73gIbwSjzybRWuAW4G+Vq/bbclxcS/Gd6Fm2YMA+IZ5MW3h9m/cDlm9I/9jWuaBS4NVvdxgX2qW9B2R8x61If0wEaKCEzrHutLmcZtEc2bI2/K+I7dqCV+B9VSLnYOTqzYPWF/7x2+n9GI5pT2m1FLw8v5CShYQiixp7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; c=relaxed/simple; bh=ljB0T0SypDKUjc4/ns6mdqYQRtTPSJPAGAx63hfzEGI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=s8/OxgwWokhb5MmHvBwUP20M5GyAa/4uNOxKqOgsy/fHx89SJ/io0S84CNmzbkLR0j4m1rPbCD9vAQ/1PpEoEkGWQT7azEhzVj36ep1hu0PsV+74zGStMhbuxesILLkHdyfpI1Nwy1RwJ5hW6WRc+Z17PMg0a0kKTEQmt3smMvI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0Cgx5014997; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4fxch7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFvq027868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs6032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 16/40] c++: Implement __is_member_pointer built-in trait Date: Sun, 15 Oct 2023 17:10:00 -0700 Message-ID: <20231016001227.2717180-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: og1avUoNESelLbqPwxplvk0fWUoOEbbm X-Proofpoint-GUID: og1avUoNESelLbqPwxplvk0fWUoOEbbm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=735 priorityscore=1501 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1779869344934213067 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 e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index f56ab031d5f..6c4880d8a33 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Mon Oct 16 00:10:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159156vqb; Sun, 15 Oct 2023 17:23:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv9BIXOln4lvBgJVrZ61SwkEjYNgkZI4wKTZY+zLZmhDHcm5I1vjcTUoWtTGE0NREC681J X-Received: by 2002:a05:622a:1a1f:b0:419:b54d:9e91 with SMTP id f31-20020a05622a1a1f00b00419b54d9e91mr37869785qtb.48.1697415818021; Sun, 15 Oct 2023 17:23:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415818; cv=pass; d=google.com; s=arc-20160816; b=Ytlnyoe6Hk6Ozpqnj2kfAElg66WMG1lA4O1xjLW3ihCdg06xvPl/xOwPjp7FnA7yG4 +5RkzYXmIr5ceUhVI24jHIvkd/mSasUb1a+Z5YvINYVSmh+zPgtA4BfVSOFWmZIlRriw F527SYg7y1FImW0BPmJ+8sC+UyANSYB6Nq0Z7re4k+q16reAv0ME1vTHr82Tcyxx8s7s Dpvo+OjbO/kYFXhxoq35RaNWUx+tOP+Z00YeJaEH5T5AhoAmP7KR3SN+e65eP9Aiv25N RfUB9MizqR5xx6UT73/SsN3gNm8guUwB4LkQfC63kPIGbtRHbrzA7C6OGjDxzmRjgQx2 bdhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=INB3v5HP7CCn6OIhOHvsfbi2c7WvkmqELTTnL1oic9p4Q6nvNsRq9FggMqpINLdfQK Qx525i3HeWhC9gihw+8sW0NcJoF9BPPHTSE/JVliFZxu67Y0X9YfeE6oDToeXw55md7w zMUEJ+IkNlS5BLrPhSOkWC84zGxOqX+voDRVvpoe0Z/dNhY9CK7zAwLjwiMoDMPyT54S Fh29JLebR3tC5c+8n64C0rka8Ec1kKETTMBHoPOxbsUVbsStRg3jXylstdIqk27tPL3Q MpOEHnbRPPVPq545UQopkhu0dT+LKeYDXkLsLeeGT7mEes8IZVkmE0boI+y0DiQEZYwQ m2nQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KzQoWIsE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g14-20020ac85d4e000000b00419576c2d1asi4721284qtx.773.2023.10.15.17.23.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:23: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=KzQoWIsE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 329093856DD5 for ; Mon, 16 Oct 2023 00:23:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 329093856DD5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415816; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=KzQoWIsEUC9TRLND5pnI+A27lah0CZ6AIZnkx5zm8uPCyUNRqYZ6DTNZ9fXU0rLX+ xjiTlrCDVz+fxZFNM9WCeBVuz6zC8bUYAdmx6sXwInTkO1S6cXbjku6kMNm/0i9A6q ONpklXZMd5tXBUDtw9mzFD4Qt59VoORcRGsM5IdU= 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 0804F3857438; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0804F3857438 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0804F3857438 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; cv=none; b=MuLeuEOyQ4clc+WOmYov5T2XK3M/TgyhxWMSyvCPa4Y+2y2cL0tFgLW3E+djuwhg80fIW66hJRT5t/kvOCSvnzdQAjaLhg214N7dBdstO0ZX5UxlkYmWTRaJCbNdOpPpdzh4JLGc1eKDP5dATfNBbY6kPeRYv1Uk2tyyrqhXzCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; c=relaxed/simple; bh=UJgksNSlORUlZPpOVuq0Q6PZq76Ryp5/hjZPmLb21rk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Q7B2jbKyh5M7Lzi7d8taL8yLHfg4X6INGUFBt4/L6Vy7XWGsDAx9p2c+fGjsAxymEyRdubk3OTD4KVhqogAeFoSLo0EjC/BDX9UU66ZO9g6JGNwpPXmiut9PWXH3g/+xYrx4Yq0VzNF2xXjhnu4duPL5IrxtN5UXiDR2JZmD4/M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0CGSi015859; Mon, 16 Oct 2023 00:14:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dj4es9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFeR005470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs7032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 17/40] libstdc++: Optimize is_member_pointer trait performance Date: Sun, 15 Oct 2023 17:10:01 -0700 Message-ID: <20231016001227.2717180-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: wTqOLQOdylE5ZWT-FUXX5KwU1SXNoZa_ X-Proofpoint-GUID: wTqOLQOdylE5ZWT-FUXX5KwU1SXNoZa_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=579 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 clxscore=1034 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996307296308519 X-GMAIL-MSGID: 1779869488801619024 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 Mon Oct 16 00:10:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3156918vqb; Sun, 15 Oct 2023 17:16:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGp8LXP7Rho87W3cOzmq4JDfj8H1xx2DySy0yukNQ88lNi6iI9PCjm4UTTSmzCMRaQgpLoe X-Received: by 2002:ac8:7e90:0:b0:3f8:71aa:f11d with SMTP id w16-20020ac87e90000000b003f871aaf11dmr43711220qtj.37.1697415375541; Sun, 15 Oct 2023 17:16:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415375; cv=pass; d=google.com; s=arc-20160816; b=Dtc0wI8sUXAA0mBpGScr3vWnmPG7mhKDqAytj2r6y7fBgvm9lZqcwJFrSf/sxhjuwR unH/7cRXK65ToS0QH/PangaOXkeQhsByxciGmHH7yel3vj5foihF4uBAXfkX9xmi6iRS xXn4U6xlwzJnKfrOLF+tKlxIF59VDf0XUsJEcRo8/781QiG8Y/n6kXaehOSUqmyedlPG MOF+aFNJmAG3pm8LbGE0p7rUWJA/qm2Kkz1m2nqkNLoKe3SYh7+Y06sOWm56oUtncWvn 5PHZujMUTU4+BEgBwSsJZ5q0oXK2oe+9knX8796jYCmrbA7tXef07o5lUpplD307f9CT OyYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=IDpdOtabwre/+xP1Y/kTGaLq5K6aaytRAI3t6sZ+E30=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=TIADJMweoqz7d5xCQib1sOqZ16cW/mfeqjD0TfplTPx1gqGKO83LglL36/YB/bl1P1 TDAI4KFBImJxZQGqd0eH7m8SfQCV+r0DS2bMlUvmpsTwnI4MoDaW96cGWo/OFmnQWPbd 7cHWhIJ8E70eLyYwVI/sK+nWn+xf8T+uiHTj+5tdTVOTeZ2wHorgImhmnHOeSy7G9n85 2LApKpJO3FPxuY5RJ5D3hpMFH6j4svSHi0Kkvi3Zd+d6JxxzSR7+xh3GoCiC0wyTxrAv v5APHwFBBLN3aUuglk4Jx6IvVu1S52xaSGvuhzJJiykSQ2OYLfIgNggJywj5wA5jC8Z1 LXNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OYTtmAIS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l9-20020a05622a050900b004198b50a2c1si4641230qtx.520.2023.10.15.17.16.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:16: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=OYTtmAIS; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1ABBE3857019 for ; Mon, 16 Oct 2023 00:16:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1ABBE3857019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415374; bh=IDpdOtabwre/+xP1Y/kTGaLq5K6aaytRAI3t6sZ+E30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OYTtmAISN3Vq60jocms52nVgqxkfHpgqE4tg4vYguv7am3Uw2Gpb5t8HMNcxFziBh M7p/mFZvAPcUdmzO5BEA3SpVmVRdzYfu/khyyFA44eXd+8R2r1tBhqJ9aNxrJLCfDx aGJbKlvnrWowbxO4Xrk8630LZM8ZrY2124DGS82M= 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 6EA1D3858C33; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EA1D3858C33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6EA1D3858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415271; cv=none; b=abx89UkoLWSIdZnZBGxM8PkVv/kMJ5UE+fWa2eL2MaeeSKKm8iVjuUEHfFJKWMefXbE4ulIlZPTOPLzDGsVWT6DUn9XYRA3ElIQk0J+cbKEFa2KffF7iaGyaH75JyBAucbZN8xWDaFXwzYs2sy+FrfZuYWjdT63fAS6KRP9Qypo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415271; c=relaxed/simple; bh=HV5W1URdWLWYKR4ToEcPgS8obFQeieaNlJQf1K53gl4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gpOV2GCq0uUjQ3WV0mWMTvslwsDQivvwOlzsY1sDNwFyRpIRWxtiYFchQOUzPfNvB8ORddn8pHMFbPb912JxfvdtvkOnREM0C4SX2cGjronkKFCvk2l3b5CWAX1BssShnjsWro0m3FcOjScPiRnOC2lG6Aa2AqIqLjeLxLST9Eo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0ENBZ016854; Mon, 16 Oct 2023 00:14:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr556c9y8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFOm010499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs8032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 18/40] c++: Implement __is_member_function_pointer built-in trait Date: Sun, 15 Oct 2023 17:10:02 -0700 Message-ID: <20231016001227.2717180-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: IAPCfXI3rV2LQV5ByoMRxEFB5SEvYW0K X-Proofpoint-ORIG-GUID: IAPCfXI3rV2LQV5ByoMRxEFB5SEvYW0K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 mlxscore=0 malwarescore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=791 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1779869024725831934 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 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c4880d8a33..4d521f87bbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Mon Oct 16 00:10:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157957vqb; Sun, 15 Oct 2023 17:19:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPc2C6ODIWZ//S3r8mWKKoKYkjBwCVTNMWCOeRpsHHf0UXYNtEBmXpe/B9NpzO/dfusdGM X-Received: by 2002:a0c:b446:0:b0:66d:3a89:8125 with SMTP id e6-20020a0cb446000000b0066d3a898125mr4824779qvf.53.1697415582393; Sun, 15 Oct 2023 17:19:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415582; cv=pass; d=google.com; s=arc-20160816; b=O6Yd5QB3jRQSl/jltElpbAIpNuAl90fEYdTLpNrepln7znslsEuXQfH1cETV0G+l3t jGL6c9ZFtlXeD9ZqnS1msQ0D3n7p+OvmEmvVdT0OkbSG6xQncVMTNfZc0/SxoD7qEF15 wklYuamrRdPBexK1tGWhHlGaiX74n3owlbuI8UgCtmhCU+8rq1OiQbBBWeEhbYvCP4pv 47Jkr7LXOxcjSk8ZjPuZmYFUHGnAHy/B3hSU6XB22xgwkUgcJhewkvHqJNNAQkmPz3VJ hma6SJda7pbcf6yf/8NrQD/fK57zEGExzp+1Xn7SdhImsvBi5ynwMOc0Qw16pWIiHEIx CTtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uut9Nmz5A8C5pDFvzI//faIzATGJlcGJUowWIgjncFcI+JYuOId1UMZsb+52bgkCsu ykSAOxmMQSzJRJQknIQb+VbntgjuDi8AR12xue+1upDMo6z4kjxuC9cYoPTJP7xlyk5N O06iSWGPsFZGYG5TK42jj6GR+lpeGqWJFQvoP6jSefTvheCkgr2WnkkyWF0pYuIPaX82 Ic4l/4Csld7M/R5F35+D4jP3dygRgHsqf28L5GIIjDbTwnQCN++fubk+Dkrm2uA42PcJ P4Bhw1g+f6LEljebCSqD19dycF0DSS8e88fe3T0rrBLSZa6qDRfl0ojknblHxreUgC9N OVZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J5ThTX23; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k4-20020a05620a414400b0077593f71496si4784676qko.720.2023.10.15.17.19.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J5ThTX23; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A9EF385B52A for ; Mon, 16 Oct 2023 00:19:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A9EF385B52A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415577; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=J5ThTX23Qe2Yqf/11sWYWPxuqMGX3Rz4rTDdEcGkQk2/s1JoK6nL2J6QC71ilp2ym TMWUZG5kbyEaPAUSRGe3Egpv11Mh6Btw1/kQ54M31YLh8E8gJvmo10T861GajHXktJ ffRUjCf6w0Lykjvjw8zNnGtQjtJohH4vcDRdlr1c= 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 DB7333858004; Mon, 16 Oct 2023 00:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB7333858004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB7333858004 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415273; cv=none; b=yE6D2rzLqpOmdPuLHcCaryBS3S7bdNw2/ZdxLTO6RCQhOmiCMVYK7LPLvKIsTuOjNW+isS9zmKRveymlHIwsfwdgij8PDioV2q/f8Yf0qkvvx5wWT+a3bZDEggTyoSp9f9b5YmqLyT8qEahOSMxiyT6UjrO3ojzVve3rdeWV2Bc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415273; c=relaxed/simple; bh=QuMkc1ehlJ5Wg8V4Rsxxo7gXiPPchTtHkDih2h1/T8E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Y0uwBfvW/z26C92NHdx4m2Uhw5m7SyU07wXQR1Wa/oyvuhGCtPHpGkqeYzwuZLOmotURSvw7yqJnwr6MRJHtcLevFm5IkLlDreKYWj6xD2zCqI70Xyxw1oOP0fhe6TTK0Akmj2K+g8NIjvEpV152TLQcyhj+vJzbpYEXf1D1cIo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0EOa2020876; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dk4byf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:30 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFH4001214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSs9032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 19/40] libstdc++: Optimize is_member_function_pointer trait performance Date: Sun, 15 Oct 2023 17:10:03 -0700 Message-ID: <20231016001227.2717180-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: MFnh4bqiP1-t7QA4gDCCCx_esGii3074 X-Proofpoint-GUID: MFnh4bqiP1-t7QA4gDCCCx_esGii3074 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 mlxlogscore=665 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995423218726551 X-GMAIL-MSGID: 1779869241688717479 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 Mon Oct 16 00:10:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160078vqb; Sun, 15 Oct 2023 17:26:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjGE+fEwN+N3leYrRt9om4gQ6LlHJ8HbKznq4IAb2yAqlaqwjDbgGo47OlTnwi7b8D4ZTB X-Received: by 2002:a05:622a:11d1:b0:418:15b9:8290 with SMTP id n17-20020a05622a11d100b0041815b98290mr42929605qtk.53.1697416017221; Sun, 15 Oct 2023 17:26:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416017; cv=pass; d=google.com; s=arc-20160816; b=x/p3uDr3nd2O5Xxio7dY5AiSwP1oGRmA0r79JWNFq8ZEAujTWIK/3HkcNUtBj+VkZh Db0Kko/mN6QWRPH0snJh3UJX0ks8HlYM25pMyyamw34mFhKZEJiyW3XmC+723qztA4WL a66Z02I+lJP3sbuns6B+cr9vkQMriU88Hxpnpsifw7He50YtBbGIQ+XDI4YLwAY4IN+X JOI8OacLQ3LJycl0HPoJ9Yi8dfH2av7LSPsoZRIYhAYmJjqRs3+bAG1kdzjbWN+SNW7I dIpF+q0URFqVhP3a7qWw/w0uxoAI/hBXvw6VQ5cuzXt9Cx8wtXVDDbuFmFD7frtUglOz aJww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=sOXneEePZa6D+778pbdiLmvPrBEpUomCq7Vsadfrg1k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=XVALahxfG/4o/FX6vs5homxHT5Oqt4MaI8Q3eukrynslShe1oMkzgTvhaBn0nxV22c zQMf/OflAjji+UFgRgbMHGqVwd4H8urbQaFX0y4VMbFlK6atGxCp5yZWXhocsVeXv74H 4BsSFYvJs7wPduBFDMYc1scBKWtljIgL77UzH9rsv1XpSmioUhuoPXvf8RPTjVDF39Jh OEIW2J9VZUVvKkyJxKbOLxoCOYnmeCwGCPJDpt9qpQP+ZYOeZK07wq2z2+DCBvZZdgbg R+U9BAdWe1+OdnxNiSRWZ+K8yfWWpisvvWDkyg2d5HcqYl1CTK24yhpq0RraZIwtdoKm GfBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QH0c8ES0; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v12-20020a05622a144c00b00403be2ad0besi4534265qtx.11.2023.10.15.17.26.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QH0c8ES0; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC3F73858D38 for ; Mon, 16 Oct 2023 00:26:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC3F73858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416017; bh=sOXneEePZa6D+778pbdiLmvPrBEpUomCq7Vsadfrg1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QH0c8ES0vmDd/x5D/c2bszmp1090qzltiHaUQf5VqGejb2+ExcuzoRmnW4dHEnTvl rnpYhoCEjqrQP+MaJgWnK2vlfDO3UynZ7sK18m4K58Rm7he6er97FGDLEOJfQ9xVPB SfqrqPiGx2X29a5uavD3ujkYI13TcS3S2DzKZNeQ= 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 E26F23857357; Mon, 16 Oct 2023 00:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E26F23857357 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E26F23857357 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; cv=none; b=wuM/msIjatJcmpxuG7uhvdTtHLISOML6GE/eUBzGNaqzP63tcuWAmi/ncpUxFsuQDlh2HvvCiUZBjIBlE91ffYDqRAhfyTysYWDJ/9dNvfhcz6dLvDHJ3v8aovYD5XkvsCiqZDedIpIk4X6ZatvDCsyJ5rr8tg/2dlKDUQuZbgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; c=relaxed/simple; bh=gVFjHGrDeSFfqNrAmgPkZb9TPnETfEvtpe9mHex92bg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wlnFiPW21sZAuVMp/z69IBMel0qSeHGb6BXg6yiCMrblyDQ5PCJXKW8Jl9eg5tdVDiuLpcb56AUXQ1WVDI5j+0BOhXA7uye8A22wGrtDMgowz9DF0j3IBfn4CCBtQoYlbIM2P8Dgr8n0oF3vw9OB79JhwwGUAk07/uWWiGC/eDA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNxhAH014156; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4wkma7d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:41 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFGp011859 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsA032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 20/40] c++: Implement __is_member_object_pointer built-in trait Date: Sun, 15 Oct 2023 17:10:04 -0700 Message-ID: <20231016001227.2717180-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QMZiNFpRiQj8TZ1mHrSTA-JunueQSeHA X-Proofpoint-GUID: QMZiNFpRiQj8TZ1mHrSTA-JunueQSeHA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1034 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1779869697523213710 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 897b96630f2..11fd70b3964 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4d521f87bbb..9cbb434d4c2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Mon Oct 16 00:10:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160909vqb; Sun, 15 Oct 2023 17:29:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQvoXSN3YLO/NaOKegBSn9oHEQae8sWnQTpL80ayVgF6y+1wDMh4UiPtZ91V9p2vtJiO44 X-Received: by 2002:a05:620a:2215:b0:775:95c0:af5b with SMTP id m21-20020a05620a221500b0077595c0af5bmr27288346qkh.73.1697416188635; Sun, 15 Oct 2023 17:29:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416188; cv=pass; d=google.com; s=arc-20160816; b=ltDQ8n60nYHp6h2ntYF6h/VNe8FGv2A5LHTQ82ZuctOHD5oXw0TZ6Hq0DPyvvUH2Eu 0XMG7j2nvNB9oUXN/DKNGTClUPl80477I2TX2q2rm0+yvxvzSIKYRML4KeEUY2CxC/ca LKYWddwR/1B1U2k3rO8OjeRRtsLPLEi0kYnPyFOW979WgHyJv+erNUw+ei8P5tuj4pwb sEviy2A/MYGIdDmMK+lgDpZvmPFIvkESkzCGKIVyHAmC3ai3ZaMgH2UXrx8rjR2k15c1 CDbjk1W04SDMRzLuvWTyc5cS/RDrIlQzS97KUrXmesOrg/wA70PMmGNt9OPY+WJDhck+ GrOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=O8lZK0VLQoRMq5w1QQWMu4xj/0l4X346wuuVFEUHnPFkrdlr6x29xf4RLV/yCycE7H UMQnCwf1fyIeCwaF1lYYD8gLQ8/rzQ8fEGC6AVsJb0BEDQVl7dq1kw2ladRk32CiOv6q UyF6eyk8CxGg6WTRLYwNa/TsiIqhSwvGG2EUnsR4NgftBbB6hNL5dl2WbptbYivLT1Iw t/lUmFtzZPL5RgiaPVrGC5M0G6KPUZLHnirqEls/FDND4qGT5j7f0EkikTXM0uh23/cb FYmDNSWpMe06VXyJPcvTgk696g2dcYd68smlNgsrHUFhRQEt1KCIUZj0XB1YgPgYnCOF /BSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CNiZIwGn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l11-20020ad44bcb000000b00668ed051a35si4600133qvw.548.2023.10.15.17.29.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:29:48 -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=CNiZIwGn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DB91385841A for ; Mon, 16 Oct 2023 00:29:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DB91385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416188; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CNiZIwGnjkoaUUh8zJObhRA1/F32Ah0xXswWRkF8eFFRn1aq0WeSArl5L4t6/OSTD T55XhA4caj6Lx9M5SAMoootdp1l/D+keayCLTD2YI6Ey7/PRFE5SoXNvSP8EM+waJI 3xJXNiQwSrboO5LF5s+NsYMjHR43inOwxLlq85iE= 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 E7728385771B; Mon, 16 Oct 2023 00:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7728385771B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E7728385771B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; cv=none; b=n+H2vsT4qbRVwnmp46OOBhPWsETtTSJAtEQhB1X57tZg5SVTYarakTKXbb37ZVrFDAeJgZ57s1tL+lV7PA1LutsuAyEPAa5eylZ+XLzVBy+CEM7/RZzpHJe1MHQroFBWS1JDCNswUhBbSSn1Xcv8uWbFgKWJCdLiFTgjM2N6oy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; c=relaxed/simple; bh=0fPox7o95TE1z8HSfQmP62vuVnxXyv8pdeoAV2lJZWk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qT6tFgB9nVrUEl6ElzM731ab/PZdKnA3PUE8lED14Ji3d0WaUBsOGFeU2beIjGAg2nC6w0QvotB0cWgK33iAtld6pDPvK4lzwcCONXAabVKtb0fzGuO/DbL0mMlrVJ4SM5PtJmAOrFtsyQ91x6hnoXmq30sHRRYfLV2RFKCTYD4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G08eVO004392; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqk70fuwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFpW016532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsB032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 21/40] libstdc++: Optimize is_member_object_pointer trait performance Date: Sun, 15 Oct 2023 17:10:05 -0700 Message-ID: <20231016001227.2717180-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: N1W1RLsM7WBc9gB-0_CaZbUrkqajSvgW X-Proofpoint-ORIG-GUID: N1W1RLsM7WBc9gB-0_CaZbUrkqajSvgW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1034 malwarescore=0 mlxlogscore=716 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996522370919550 X-GMAIL-MSGID: 1779869877458569384 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 Mon Oct 16 00:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3161125vqb; Sun, 15 Oct 2023 17:30:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCM/qb7yf9xWgpcggc1f063W+5lf9Q+8QcqjHfnyA738zyM3cGwSG4dN24IxFe4LD5HM+D X-Received: by 2002:ad4:5ca1:0:b0:66d:1624:2203 with SMTP id q1-20020ad45ca1000000b0066d16242203mr14656646qvh.20.1697416230289; Sun, 15 Oct 2023 17:30:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416230; cv=pass; d=google.com; s=arc-20160816; b=lPJPRm9iac80sMJAVJxeG8N4vYe1IY0bZCUimDueeAS5bLWhLbotVG0GXL4FfjY02a LFELLWaTpBKrvzhTzn816Ugx4oEq8l8eQbPN+ox3DJfBGjtRdmlOZ3sTybo9PI72UAF9 2L6Cx/b51RyQa0FxAHEDaXCBOnfP5Swf2LGZid3nbmxQsbxHRxdTdJp3UKlEVPHWqYFD TJ5/Wtg7OVngD0j2yLdmmmPMOxaI4fWn0nhGkZ3XLWWH6wzZY3Jz4B3qmHSu8enOeAy1 hbDd6XB1kb/0h7Hvppf3tktraQrip23F2bzo3uGx/N0x+f/QGCQSteYaD0cbTznxA2j5 GLpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=rYOxhwOWvD2XyGjKQSQOhQD7ZBCfCytfD1txjAM+C6M=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=bsug3cEYmJudZbaE1CeVa2wf6/cgyOdPPqE9hH5Voo0kMZIiuJvp2KijHFwSKBIwpk 9E5kKRYtx24fMyhRDljAPHB0f+pMw+9WPjfzL19o0+xu4bIdMYzerGCzGP5tjn+Hc0Jc tIkxUHsZ5hXfG6OmQLN55hNETeTTRTMRpb6bjcx65RFX2pK+x8MM8CARuOZOy5OFZST9 4EABNltAvOXpRl0m8y7B9zGeEC/KOhQMDLkdvKBOkUJ/n3QPjjnbKS7epRJYGnOUQ5NN yR9O5u7wMCC1KdKPTT3eoJc289k0A0VMzTmArPhWIZd3gdzLTVmtf+/BSzqNlnbmoJvq 0ZHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yy2CtA+Z; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l11-20020ad44d0b000000b0066d1b390dfasi4625084qvl.345.2023.10.15.17.30.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:30:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yy2CtA+Z; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 088D83857702 for ; Mon, 16 Oct 2023 00:30:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 088D83857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416230; bh=rYOxhwOWvD2XyGjKQSQOhQD7ZBCfCytfD1txjAM+C6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yy2CtA+ZuyiCuZfnmrXYg30LFYSePzfcR9YdI/yaIlBoZJdinzf7wkaQq/tfE9yQA LZvEU6Kj/lw50olIA+VsFxHRHMVK9lkNf2Ef/ZyMW1hFmGh/PBSMj0uOUmO98bndYT mOP8F4T03KMEokwBnCc6Y0VjsffCl8hy7SGb5aKo= 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 909E63857028; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 909E63857028 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 909E63857028 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; cv=none; b=GSuuahHRmRD2yObX+XSUxpyw4tf/ikw9gXFklgg6nxC3ueO4LoH0lCL62kUN/wYZiDBgFSvUlxx7+j6N1atdBrd+8Uk29R2jKOOMMWrum6gP+CtKEQOcB9rHRU4UISjQlVUncmB+Fueon/i+Ad+pxrbfT/gl8gDCgOBdFx1mdIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; c=relaxed/simple; bh=dsDjdx4nl2QpDxqn8lEFrjkEbyM9PBSzwec/I4CqoUU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iXYe9jgBDur5lU4aj8O0eoO9gcsG+f72oRJpZL4yWYkTKCf2yMCLss1SylL6U/0U+Y3hY8Dg/yJnQ8infsoW70BVu1khS6IgWSySYEFdS2U7lMGMtwZffuUNKjj88PQoKZqbPvsRq4mzfjvFkOk3BeWpZ2cce+6zMNItteDUCWc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0BR8M005713; Mon, 16 Oct 2023 00:14:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4n04f4t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFd1005471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsC032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 22/40] c++: Implement __is_reference built-in trait Date: Sun, 15 Oct 2023 17:10:06 -0700 Message-ID: <20231016001227.2717180-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: aCac7DcTmg6fCsbOtJHhBXex3m65vtKr X-Proofpoint-ORIG-GUID: aCac7DcTmg6fCsbOtJHhBXex3m65vtKr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 phishscore=0 suspectscore=0 mlxlogscore=743 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1779869920853953943 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 11fd70b3964..e867d9c4c47 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9cbb434d4c2..df720459458 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Mon Oct 16 00:10:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157302vqb; Sun, 15 Oct 2023 17:17:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH71HPrnYMhIB2V1oMR6eRAPsVgHzn55NT6RQp5oAASi1cujYcgcQUJCa9w0RnT8s5V/InY X-Received: by 2002:a05:6122:17a6:b0:4a0:6fd4:4332 with SMTP id o38-20020a05612217a600b004a06fd44332mr21284430vkf.14.1697415450679; Sun, 15 Oct 2023 17:17:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415450; cv=pass; d=google.com; s=arc-20160816; b=M9Rv9KOrUyToHu4hnq8UcZ9gOrPwVDh9EY0YFS3OrasH/2e4OAqP7g9LNpGUahRRz7 81ds2/R+rDb892G7xhGVnNzqTo+7RXglX4s/lTqvQmnQNLm7SzIgKYnkBmcPGrpIM8Mz OiS2JQwi+ud0/bQ3EZN64rUjg9/ZOdKT4ajztmY+MzOuaFwZu48Ni7nHVzpyElzFIJ/n Jzj3veOvmx2oNV3C4mlHIekmHSypGHsXOIUmTeYd2SzP5obn5n9oPlWzJmxCbEp0C5Ti JouHOfaVvFEjhtBz5DDZtFn/335RW4PGgtdV7wdhvzy/ifHjQrSYC4r6YMjwvrh80vnn uT1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=VvwvE18RwslpGevmimxDe6Hv8Ct/hI7q3l5QTmX/fXv9wtixAKIf1g2MIkQYjailtw IgPpuRbmYem+WzYd+NDrDwdqecoZsp8cGI70MGfugHnqSju7Y2GbC9P5mREBmnhn/pF9 QK3fQuGmMc44wT+TWZ+WC9hbWOaiHGFyy/in1KD98/Q6DZtLiZWXKILrE2GvPCbOmW8p OFCLr7xVTzYTSHdR2n8gLHsUjEr+DSm9+5UYUfK4F5RX6QUYC3u3xFdjdxMrvxp4fH0N QgZuCGyUVS9g/7y9fzJa+M+n2QEpDlami1uQBjHDrQRbsemQEmW0wPhEa+aJ6/sKoncx m6Iw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S3tWkhKE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x19-20020ac85f13000000b004181a0f4104si4795411qta.34.2023.10.15.17.17.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:17:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S3tWkhKE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E8C2385800C for ; Mon, 16 Oct 2023 00:17:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E8C2385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415450; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=S3tWkhKESifzIfTZxcb5BJ1w6Fe9/I1wbrGbuwPRDH9hXPDVNx8YCWVJtJG37+05+ ur8cgqTTnxcxkQMjAyX14WoGB8vLCX1bdcIfDGHQiDLmGbkTXmhCTcLiE53Jo81XyU z/24Z/ERJgNx+FZivmYBHVIGLYEQiUIAevcASZKU= 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 A69893857B9B; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A69893857B9B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A69893857B9B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415271; cv=none; b=ly2XIiytn6vFeTviJ2ZUWNajO3KYrikDDLJVCTGXDc6CxKcCOMyRoJyml0fmSmgyPUhoOfPVhvN0JZgl6Oo+xhS4rXQR/BPzzM2a9z/dBpJm9GqnedU1lHBwyfX0xW8C7yPRyCDUEITiSsPvDZOyIabxjaAD34XLCkDmIMwxOQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415271; c=relaxed/simple; bh=/ZpKzUC/+Cn+6c4i+PdtJvMDzWz2wSkg6dqToHkptIU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uqqTlsp5gLrou9mEBi8cekEwksRg9soVk8uJDzzMOCNvAXyg09EVqbGnhKyefEcSK2w9RhxGwsRAXvzt0IcJAVC8TYxmjcgQQ2D1JfPck7qYqn+dyRb8PdbelTHFGHuEFft6yTyyMjCGUvKl7/DofRVujTIJkj48kDp4SAlvYSs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G08g90004501; Mon, 16 Oct 2023 00:14:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqk70fuv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFYM010500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsD032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 23/40] libstdc++: Optimize is_reference trait performance Date: Sun, 15 Oct 2023 17:10:07 -0700 Message-ID: <20231016001227.2717180-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: TZlICjPVgaZvq3WD1ZdyGZFnTcU3cwHw X-Proofpoint-ORIG-GUID: TZlICjPVgaZvq3WD1ZdyGZFnTcU3cwHw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1034 malwarescore=0 mlxlogscore=661 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997499735714658 X-GMAIL-MSGID: 1779869104061507058 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 Mon Oct 16 00:10:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160308vqb; Sun, 15 Oct 2023 17:27:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7iXQ3QUVYFhF5IkPEp7Kr9zu2alHr32KwVXfZcc1I3o85Z/fxlZmFfgtJJAe2vye28J/9 X-Received: by 2002:ac8:5b0c:0:b0:419:4e1c:68fd with SMTP id m12-20020ac85b0c000000b004194e1c68fdmr41351051qtw.6.1697416072107; Sun, 15 Oct 2023 17:27:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416072; cv=pass; d=google.com; s=arc-20160816; b=WOMn7qvrLv3hew/LOdhmwM6CUEdvp2od11B5ZzbD//zZs1COKNxsMXi7+XED44rdmc yRGFknshy+vUmuxuNnYV8UHtELxBbJBbFfta29MZX0obNkfgx86RgvZii73NBhmcADi/ +qF/wi0ZIz0CH7YDY0r+YnweDMvU4fXUD9dnHPolowwGbAaT9EfRnjRstPTj2Vc4oiHK 0nUyEeyfFAG+RCmLbSNkJJaWl+gjX2sXhxWutUpa3gHlgOwNtdyufdtBlrlzg0QrVCYO WHY8T34k99Ly/BPVbTVBdX46Y+Tymjn8dk7E1XjA/WLQ6YRgT4t0FF1VMccAXQ9KvqKk bZKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=dhuC0lB5d5muFaY9D4xzNOo4MEO+VrBVPoqlsmhZK7I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=W7pbFwHI1Dz3WOuABHrdbFAJXKBaByAoqqbOaJzZndq9Pse3wYeiwuydeNbAU1RPj2 S2LUkZaQPJHZRYMjIdWINEPZBLxXqh+pzWQVCAq1sNT/fACzn6hqdhbijAi+OKsimxB/ lIPlbKqOE77M9yG2AKzEbeQyhqlPFqj2hvOGc5O+iy4LgvzsTGF0LaPoEBNnKUuafsle EYPiv8KTOOWPBA9IMfiuYYDuDGwLWG8kJZlCD6ybICj6xrcqwPx80ElFabED9h18MRdL 2Dh2i9xtNKXb6rdwGvAfJlp6142n/ptZmsPxT317NYq17Aj29kfZFxtbTlsfk7yNo2X0 fcKQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SS9Bj5pR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 1-20020ac85701000000b00419576c2d0bsi4564974qtw.548.2023.10.15.17.27.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:27:52 -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=SS9Bj5pR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2BC23858D38 for ; Mon, 16 Oct 2023 00:27:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2BC23858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416071; bh=dhuC0lB5d5muFaY9D4xzNOo4MEO+VrBVPoqlsmhZK7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SS9Bj5pRR3eANi3MUMF9aDVWGBEDue6c+Rb55cqftqirf+cLu4VTljnuhMN2VxuEx k97WytCayfithT0uc3cXqr9XITdlAuK7znDdEvGo7ds7LDr+wixIZI6b09edz8RYSK 1HllIrBarSVvjcFg68/AKlAEfKftVgwNAePsk2zs= 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 4539F385800C; Mon, 16 Oct 2023 00:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4539F385800C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4539F385800C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; cv=none; b=imvFzdAk4wjqVFO6lqT2WFXoxhttR+Uz9aHF/FBtOqFH0QwjeTvzgs7ZxCQEZZxMBDjbL8+sqhw9PhUIgj/5cAXiob7WmcmNE8CKeXk4WQuo+Q8YTSuX6r3wfGaKPu+d7q2Eg5+vM2othS2C2/WTeHJlSlMr+3oH5VbzS4+DjG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; c=relaxed/simple; bh=IfcQ41nRXImqQXapwjIzr8cocnSe2ZMcN/ZPJmfbvg4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CT++VW1OL/jvhk5LIpi62t8pOlht3aT1wkg0khSE9si5PO/Brcm0pbqikd+Iz3eo1/ndq2qd+3fPll+PaGBZt2tAVpY+M7F/2tO3r8AolU+2rKp+L1tWOB8Tdjc9n9+UjyLOBmjh7GA2C4uGpw/hxVuzWCIvida/cTcXmm1iOI0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0AjS8004098; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4n04f4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:30 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFA3001215 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsE032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 24/40] c++: Implement __is_function built-in trait Date: Sun, 15 Oct 2023 17:10:08 -0700 Message-ID: <20231016001227.2717180-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: UqU6zVFNpcjL9ZmulFOHGZucKVGwGWZ8 X-Proofpoint-ORIG-GUID: UqU6zVFNpcjL9ZmulFOHGZucKVGwGWZ8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 phishscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995319714743541 X-GMAIL-MSGID: 1779869755051759951 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 e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index df720459458..4b8e80f3e62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Mon Oct 16 00:10:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159569vqb; Sun, 15 Oct 2023 17:25:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEf6DNqiJmIUdYBfdqEEPkaX2NXYNJIXEMdl+62qQax9XVBz88ATRqUA9MiA4TSSwYC399p X-Received: by 2002:a25:5ca:0:b0:d9a:c946:4187 with SMTP id 193-20020a2505ca000000b00d9ac9464187mr9053410ybf.22.1697415908391; Sun, 15 Oct 2023 17:25:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415908; cv=pass; d=google.com; s=arc-20160816; b=0U+iIFmp61N3kL1lMYtEGtpuuu2kbBlx7O4rQGZUTB7X66MntK/4PEFeXQekeOQerH aL0RuyrRk9xr5cmayD20V+azqmcrsm9ynhYggAVOIi7IcHe/uERU/tmpqbhmWk9LDVKI EWaPCZQ1Jt2AHmn9HWg7iSKb68hiSaIv3qBJJN8NA8SsbyiqFViNRyoSBEV9yYtFa48F 2GrRqB3biFILGXlN1ClLPTFFeRgaGSremJ97W1/e/7QD4AVA//XsluQrwx+UaFPCSgSF Fi+nD+D/cy4HUrOHpjXcWbjtE4yaJPGJzJ8ejOXPrwVVrmUJXsIdWMc31w+lwxKO8EB3 zimA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wqtiG/mV3+CUfPqBT7Lz3gLAaWur3yZJj55wagZNBVtphzoOoCoBH056vOjgpz05zQ vrw4ATFhVfUCmStWnkFMeKoa+tiSBepk5yg007BpI6EpC23qOPAoOIfjAIr2y4wfOhdX WV246tbVuCUygDEjoXHljnbkSv0fIeilAr8xvMtTbcfhZQS8/88Oy8pvWhAbyb3Tuz+d Lo96pf1bGDF8eGa4doqfucbo2p1sPvf2CctkNPGiUO/e/MzgmxaGvsFGzFG3PxPzMTyB pedjn5qUrjwSd/ksdYjMzngrKDkeCyiq0qLLNx0O4BOaP7kyoKXcROE1VSDEkOz5nxU3 ht8A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YhML2Udd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lv8-20020a056214578800b0065b129e617fsi4507919qvb.306.2023.10.15.17.25.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:25:08 -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=YhML2Udd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C981C3857351 for ; Mon, 16 Oct 2023 00:25:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C981C3857351 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415907; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YhML2UddZiIe7UyA6HlKVrN3RZCztdSM9w05H5qd/xo+SmQCrSRQNp2tUuelSzEb+ fZ0OWcN5qSMXRx86RHsQaD9KEuN6v7TatDhCePhLlIaUnHO6nNOkwRtln8JFCU0zZx 19Y4ltosCn+J/ppiYoA+C5aGDcDqHlevqQP3zAnk= 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 2BC123857029; Mon, 16 Oct 2023 00:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BC123857029 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BC123857029 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; cv=none; b=OH5BsLEHW0kiQnKSvQMFLS/4dcBFN4hVIwhmZd+BPumOPH0W9l2siG4jFPX9qo46xM3zHBFnqNI+3Ejrzyd2DbEupIco3eu79HmtrPXvkW0HbypoMRs5UG/9+kyCWOyly1//v6hRLBchwc/1Mjwa1hFuD98uFUF3l/4fa5kqDtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; c=relaxed/simple; bh=c205PSleSo98VKF72O15l6crxQGKXbefxic2LHXRDwk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hFJ8vEe0srkqcBOHmXGUW5cN3lc6d9zYEAFCmBaj70bosw+j3GP7IbQpQylTjasKvOSzrCMpQkO+eGQW8uJk10H94OZKhzyFaKHgCTDgeboiv2NyWfIG4wcgf0A0GP40hVIEDKoGb6w4H4fbzDxaPmeW3NQaP20HlxPw1ohD9Jc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0EJes026225; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqk70fuw5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EF1J011860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsF032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 25/40] libstdc++: Optimize is_function trait performance Date: Sun, 15 Oct 2023 17:10:09 -0700 Message-ID: <20231016001227.2717180-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: xu4G-0OkRBhkEalH4PCMErwYPELUykcT X-Proofpoint-ORIG-GUID: xu4G-0OkRBhkEalH4PCMErwYPELUykcT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1034 malwarescore=0 mlxlogscore=582 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997392552534413 X-GMAIL-MSGID: 1779869583530419534 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 Mon Oct 16 00:10:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159700vqb; Sun, 15 Oct 2023 17:25:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyl2WnRBHSxyzTF/Cv+gEBmYr82Ro92iQ/LxIyY+wbvkaXiOx+fum6yNZZ4p1cMjW/c4M1 X-Received: by 2002:a05:620a:4249:b0:76c:a695:fe5b with SMTP id w9-20020a05620a424900b0076ca695fe5bmr34620938qko.62.1697415932598; Sun, 15 Oct 2023 17:25:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415932; cv=pass; d=google.com; s=arc-20160816; b=YN3arBQMPxQfgnPyaE919QTtaoJPABQEA/9dRrflIrLuNiPqjIC7u/OpddKIuC0/X6 /Lw2nJZj6PDm5FWPXpHpAzhC1IB3+yLv5hdOh1CM4mI0bIgrhJQSNbgaqly6WGRy4L9d Ne3Mgis+nCNx1MxzShYHyudeI+m4Lvtf64Tvx4k9bM1Yi9rifvxuOk+3E2WtIwNXb758 X1tEl7jQ8k5XQVs/mmmYCJehSWp77/I1xtLMw6YZ8wG6/jbJ/LQAGzKdAvzN0eTthQSu 4SNkWAS+v726paqh6tJqF5ibt6g9lLBtwGQ5yw5MfQkHDQOrCw37Vd/FeobfCP7rx+XR +xvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Jrul6N9aBv3Au0HucnI94koxPI5vBARFiCLMxhmEQ7Hcv5FPpQl4helI/NNilrXJO8 qCDuWHSAFJzY5WR4BYwBxwTxxHPKYO1SR7mK3Yg1AVV6LXB8Dk2wXDFveO0refihJe9m hILuTEmJ4NMJlRWcdWLSA4Vmx7Hnhgr3VYzLuXur2uX4f07QKT5w8a3om7H9IFnwnxNs 19uE923IHNuJX8+Yto/UYMtilPrc0y3ZxwDy5H1ErbGDMDkKWFfzdRhGNqHIh1MEHU/D VordM6kSotYUpa5ePe5bNVXb/3M6qdkNCEH/P1sXkK6kK3Wlle9LEYU+wyhL6z7xHvq/ mi4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z5HOeFzT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v15-20020a05620a0f0f00b0076cd6b898c1si4592209qkl.716.2023.10.15.17.25.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:25:32 -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=Z5HOeFzT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E11B3857B9B for ; Mon, 16 Oct 2023 00:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E11B3857B9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415932; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Z5HOeFzTGsCH/zy0SXC1M1yZh90XvHnS3SEBVomMhboiEczVBw6K+psHCuzSoI/N4 0tLKLqjj4eCCW+9cS39WTZIHfNWeeka7kxeAllMcRkaYxrnOwshV9gTRbywNxAviov IVqr8d6xrut/woxLAYJaPiOghkVrufjKwdafOfSI= 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 238F13856DF1; Mon, 16 Oct 2023 00:14:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 238F13856DF1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 238F13856DF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415289; cv=none; b=lAramd7wGQ2sMqwdNzySEOdgXykPLIbQzJSpT2yYDxpxNHKm1alJY4i0yJs5NxZyqe3WwLKkZHWs5sF18V3j7EHCXvh9XvPVXSuLR3kC+ALOIXQk7ZaQuznMKDRK1GHccGb1CBS+dJb1/m2rrwobp6zgCN74a2Qyxe/6+QolrzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415289; c=relaxed/simple; bh=zHRUm094zuZ3ZECOAp015pu8rl+10kg38IxbocgWKRo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=n0/z9StHftf8TWbqsDBCzK1lUeBAMhkhCCRkRvd3DC0wl+fpI1V83FQFLWkv4/UW8mlEq8k9MEXcoTFLjhgfbdyZDZtKNcyZ89WZYJDFqB3OGYl0ulf73MPK+7FBv7ReEVpOMJMSFlE3w9GPKgQJCzN9AIvOLoDzBVMuV5hOplw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNvgwQ028057; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EF25016533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsG032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 26/40] libstdc++: Optimize is_object trait performance Date: Sun, 15 Oct 2023 17:10:10 -0700 Message-ID: <20231016001227.2717180-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: NVxzV3cmtb8fy4nusXGwmcA0EJNeJx9M X-Proofpoint-ORIG-GUID: NVxzV3cmtb8fy4nusXGwmcA0EJNeJx9M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=792 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995944979792207 X-GMAIL-MSGID: 1779869609055639329 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 Mon Oct 16 00:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159486vqb; Sun, 15 Oct 2023 17:24:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdBJtKtc98BcVspIMTdl+SIC/BTr5iX9ata9FOx5RJYtl7Hq3l50GtucccB9hC0tILvkZ0 X-Received: by 2002:a0c:f111:0:b0:66d:4d99:bd3b with SMTP id i17-20020a0cf111000000b0066d4d99bd3bmr3181925qvl.23.1697415894606; Sun, 15 Oct 2023 17:24:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415894; cv=pass; d=google.com; s=arc-20160816; b=tXmkzJZ3OnVaoMe0lZJrsTNgnoCThJ/Ysme7MlFfVZRebm7TyS5EOYdj1yJ1VicJGE NXxq1OZTRCkB7EIxI90C5Ebx6aMMuLfs/nGGPT4FyC6PyDkFrrU8TsFGc/W12JVK21Vv 5qWgoMZoTQechtF50HeQEMmZobMcVyRHdlexp3pX/+pEeGThlA7c7FBMiz3honfl79Y6 e35GDvxZ5ROFTELojJLbVDV0OXMWt2aR7J1rakA5J4wHyu66eQRKPTbFJxEp37jRhSIY iw9Ys+B2Mdueh+D7th9k+aJMVu73UBRCDD9x8oYqExMOWvKZJzjlPM5YsXBDAbgtU4PU 5Izw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=jDRNR5iB6bYJOi+GxXEhpT2F5T6i8Zf9bhkWoFhA7rw=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zsOQYPJWJ3oQCG/IxjgzDaZja7YMEUQlH52wwtcVOZ4j45RILuxgQ2Lyye9EjoT+CT +hMUFHgaLaLMhaqzjJq+zNy725JU/PfMhuXmVXYIxRmk53xBmXQIcBg4cjfud69CmlJp RKlbmypVjB83DBdbNCJmhrH4WVveiUayWV5aELF57ww6u6B0TSedfrBGTh6gT4KrOUhz LLFk4coVvkIx8P4uPWi5PGa4+RtImmKeefExtxHk1fa4fTewzpv07V0AWLDR4JS9aYWD N5csR+UWEU8djLkJvMTunT+WwSwblER1NZbWfOI0gGEeIH8uePRA4TuHe6EpM59UQyCb NWNA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=u9PWvke1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z9-20020a0ce989000000b0065b02de7317si4635619qvn.573.2023.10.15.17.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:24:54 -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=u9PWvke1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41F5F3857355 for ; Mon, 16 Oct 2023 00:24:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41F5F3857355 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415894; bh=jDRNR5iB6bYJOi+GxXEhpT2F5T6i8Zf9bhkWoFhA7rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=u9PWvke1pSaaYpKqcXsXrv1K+NEsZieFUJ8cTctxrfpWbLBvTQzpsSc8rNXDEpn4o Fvq5Zoh+Xi+N+ffkomT/JOv/uEdv/i84Z0ZnNBoTfi7AnaXJw3Uo0C72bmcjL3+ARU me2nlCa7XWfNpmuzJlhUgg9xyWMWl2/bJQzgRqWQ= 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 86D5A3857731; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86D5A3857731 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 86D5A3857731 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; cv=none; b=Cn2i2yOyxldbYfiR9jHzUqBELhuXmaE0IBuioNzkyS5pOfBh7iTWWwPewOexrqN5VjIGDZ05AQFTmyoh8+lu9zqWkdFXg/OXu+tuUh8/rdDpj1ttwADesPDLo3gIdmqckOH/TqZJbhtYdE/WNVk/4nHRqeKytvkdzNthcEgQwAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415280; c=relaxed/simple; bh=U+9OETR3cwAkBtiqbalra0qDs5YRLO9PcaCRJJIMh6c=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KAZiQvG55xVWaZ9nO2hvo2ItnQIhD4+O7Apx0DHt+/aXnxwray8Cc93/fPkT7sZqKGf4WrDh1bSjMtfB8XEj0sQDhxqZz4qtSLcOt+yOlkpZUtDTAUw5bEOvjuP671aEvDD3PEhkog+TNcsC5rpwceIt1x6HAnc7FtgBtW6HGHk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G001Bj012854; Mon, 16 Oct 2023 00:14:38 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr556ca02-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFFc005472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsH032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 27/40] c++: Implement __remove_pointer built-in trait Date: Sun, 15 Oct 2023 17:10:11 -0700 Message-ID: <20231016001227.2717180-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fnqdZABxSxLaADJk6qVJlwvKl8mnBQUh X-Proofpoint-ORIG-GUID: fnqdZABxSxLaADJk6qVJlwvKl8mnBQUh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 mlxscore=0 malwarescore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=621 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1779869569203207312 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 fa79bc0c68c..2add97ae749 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -97,6 +97,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Mon Oct 16 00:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159673vqb; Sun, 15 Oct 2023 17:25:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIC1mBi3RnYBZ/tPhFOAcwZPY780dckJZP3mRuhIJL6EXaSotykoh/WEoBz5LVMsY0FU5U X-Received: by 2002:a05:620a:6228:b0:76e:fea2:cc79 with SMTP id ou40-20020a05620a622800b0076efea2cc79mr25739517qkn.67.1697415927130; Sun, 15 Oct 2023 17:25:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415927; cv=pass; d=google.com; s=arc-20160816; b=IQnrNA6H8MgypW7r2BSeQr0iT1p5KTwmaW/Dqdpb3XNpYP/yLMeoze9Q99LRBMHvPQ GpUAD9cAaSrVXGWLQQq02dNWv1tpF8GXx89oQDntlvoEuJyKgGP6X4prQ1vcYgnrVL9Q cylzqJVwOutOwbw9MEXjA5aeQgJf4nAL+TwZKDcxzLLoHsKNRwrDkUXtEfnU2KNMPfdE BuzFdAMVeuo8hxVXGwnvWAmqlvU19LW7gaqfBC9d+a5GfCrZ/ZBA7U1kAx0r03zZKBmD oaV3NSNqoIhfhpt8Ws9MVMM1cJxQSWD8hOVYcTunCpAuim8mxh/1SNd0svjmKxtzanOI iRJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LcKdXZLxxaR8AQrDYoiwFTrQkLsi6+fw2PvDPJN4zdLnISxvXMdS8cTvsMXEn8svcl k3xUg9fJEDGn7CcGI+pm9uQaqAgU+PSrTG6wK+BeCWop9vHeAjL3qSGTcKTK2tsmnCP0 RfJapjsbrZZk3l6PGAy/XwGfi139lUUWEsUPkHyUCVciWQd4N5+1o5RzystLBcoCRCYv NeyARulkKd9LsP4GCxbWKmf+rQNtWsUL6EBv2wu1mHd2x4XvaQ6HWEWah3jfyDhVC2BL TTCIflEsLtSL6ZGKXVqXGs+Tu5RwHUVeBID1XZv77QV1os0NC+2ly5gF/kFSpqf4bddt J03A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="BrsvJx+/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id uw10-20020a05620a4d8a00b0076cadd6f855si4533555qkn.219.2023.10.15.17.25.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:25:27 -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="BrsvJx+/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C12B13857703 for ; Mon, 16 Oct 2023 00:25:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C12B13857703 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415926; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BrsvJx+/v1qCmHsrqBKi0GHg0vYF3TiY1D+0IneTMtrbq6aXHSU0DMSdRp+8y8fWr O1Ji/WTQyud5hcaUjsKaMYpezVrXCEyP52u6HqComWuzpvAg4OhhBs/j6KhFB3XyLY E8ph0Vq0eRi0cPhMcofwL5fmd15avoKQEJFxV+2k= 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 AF8513857343; Mon, 16 Oct 2023 00:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF8513857343 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AF8513857343 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415283; cv=none; b=A3xDWozP8cDcKBTeCDXJfWYxqsmt5HW1rDCMA+hCwWZkY0dFX/TeOk+GHknP3cH7zZ3CMENfg3npeDsD/K/9V5mnKz0c7Xii9MmNutTdDcN9/WFTIZxvMAMyetTmlqjXriguO+SPUnUmkgZGMyZFuqkP9kmKW9I7x4vl4VKiSuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415283; c=relaxed/simple; bh=vHI02GzVWW7SZ1SaoXTatpzigzV+rRMb+vomEf99kE4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VD2IpWah3/zsVPXdmqOtZUYcxfmp4xRLQAqLhzrrRvDvyFWfEYp3xkd9R7dCp4VjNGTCF91usZ31QjXK/WGvsAxVEMZorDiR+77+tv33x2TAurYiToitBziFoCriyTNFYgyQIcd95nIn9HQ9Etx/EC4WoIugriZkU2bI0j34z/c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0CTSx012279; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kq4d2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EF3R011861 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:15 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsI032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 28/40] libstdc++: Optimize remove_pointer trait performance Date: Sun, 15 Oct 2023 17:10:12 -0700 Message-ID: <20231016001227.2717180-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kSPaBJZCVoEEM9boD94PmJAhP0ex79vv X-Proofpoint-GUID: kSPaBJZCVoEEM9boD94PmJAhP0ex79vv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=664 priorityscore=1501 impostorscore=0 clxscore=1034 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997286578618893 X-GMAIL-MSGID: 1779869603109948586 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 Mon Oct 16 00:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3162009vqb; Sun, 15 Oct 2023 17:33:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcA4J1cvkyhk/tYpiqLWY/TGib7N1nx1cgRumsUG3rFelQud1pA/Rn7+NE0XTOCMTq6iWO X-Received: by 2002:a05:622a:15c2:b0:418:d3d:30e1 with SMTP id d2-20020a05622a15c200b004180d3d30e1mr43582540qty.4.1697416388449; Sun, 15 Oct 2023 17:33:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416388; cv=pass; d=google.com; s=arc-20160816; b=Nz2crRb//aRrXQatme6Tm0k9k23aN34xpxyJYUJFCfXqxV5Mdo9qr/ca3ASA7iOiek 6ARWvWEeiG4Az+ITCf48YkG81ah1kpkCtX3xRD63uDc40njZkwhlEWhgTd3po7XuvfcD +2AdQA8gqVrg4PC4DvhyJ/JOUUtBa/4ION060VzK5E9xy87zCB+Z0RaJoqmC/raQyE7x DPOsQXeyP3FggtH9VHL+F4HPxYOY2IWbQFSfX3K0qC2M8Y6KzTWPummi1mkFgO/9eHxO 0xSDHaqxXrdmfJ2R5UGZusKvkj4izkJWl3DxbodQ3sjDr4WGB9uKLrC8QVmOaZemL0TT RIqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=GF4/qnKX4yF8JC8+stfWhxEV5pzoi2UJn5NIgQNPUJQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Mo+xosnmdkJDQnXI7BUHjJ3NefuFIqQIXJsciJ53b2FDPRBizpDFyyWuwMx0sMdlmF /33BryeE8Ez8c/JyAIk+ZHMT2Bvv3acaX0reBEz3jd7NZlZ9l+P+8JQHXrRsfhiEasHp e/UiUaLDNVa81FtgYc7huLxdPeTDLFVUWHm9/WRADDGJ97udYLuH64sHTn5p/y7/fLLq PBFHTYgrnbj7vqih+SBNKz+DJEnYqZZP3IY4CFgrcRuYFG9327Fgw6QFwpDe/A2Q758M R4W56Vm7TBNi1vm/fDN7AQ1+MHVYezmdgUmPvDrIUizsj8BAKq3/DNkeCH/Bpkv+eTHe QCZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=SpT1GsDV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bp36-20020a05622a1ba400b00417afb934casi4703822qtb.683.2023.10.15.17.33.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:33:08 -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=SpT1GsDV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 323213858428 for ; Mon, 16 Oct 2023 00:33:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 323213858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416388; bh=GF4/qnKX4yF8JC8+stfWhxEV5pzoi2UJn5NIgQNPUJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SpT1GsDVGv2ZV8qNhf05WIGoive1MysKLhsJiam7NKY4PUqAP26t1vAovIpXRvh4u 6kXKN1A7iAoHsHfwzayU6LYYyAKuUMzliyY2juTE2nchI4mL9V/fkLfsw5PG9Mx7IK XduGcaFmldqbAlwwKaRn2E/YEOGsEu0kxx152Ipo= 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 BD631385828D; Mon, 16 Oct 2023 00:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD631385828D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD631385828D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; cv=none; b=g7wza9Sdz6+02NTONur1cUF+d3DL68sdkLhESZ9SCgHtze2Vqo/eSfsoSTDpkNdiumHFr22kptE7hQZXzI+y2r7A868xbmgeDW5T8wSUwR15GBnFGxZ/sGUsEf7VB4XiVImB+EPmE5PpYI9SAhYJMdqTFPXt+NHpzuJ/jyqAUvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; c=relaxed/simple; bh=SqbJdNvFjC1K9XsOX9b8Johu7kZhG0kdx0ehx/Oz688=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=w4f36+I7K5h2hqh0zKwc4WFJF6ptjDvWXPyW2nUbeHq9q6pkaWCZ56tR/N1nokyIZ7rDwRIRKrKbk8RnyhfuxTe7vyKgnFNZUY/5fRa+X3qV80pXtbTN1BGo0nahGuUMvSeozsEKacLUidVzqYu14i04K/n14IegKbK8R01XMPY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0Ckhm015029; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4fxch8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EFDo016534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsJ032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 29/40] c++: Implement __is_pointer built-in trait Date: Sun, 15 Oct 2023 17:10:13 -0700 Message-ID: <20231016001227.2717180-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ZvTD1qSXm4tsz8B6pYnU22-yXFT1DpP9 X-Proofpoint-GUID: ZvTD1qSXm4tsz8B6pYnU22-yXFT1DpP9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=727 priorityscore=1501 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677497968726301 X-GMAIL-MSGID: 1779870086985687273 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 99a7e7247ce..c9d627fa782 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2add97ae749..c60724e869e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 168411f6700..83ed674b9d4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12412,6 +12415,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcab0599d1a..efce04fd09d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); From patchwork Mon Oct 16 00:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3157494vqb; Sun, 15 Oct 2023 17:18:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXFGTT8x0ufwh3Mn1mEZ6BYQQMdIes5bJOeQ6HNxK25TLHJd0Cd4VY0kpuqXqO2VORslyR X-Received: by 2002:ac8:5fc7:0:b0:412:22f5:fe00 with SMTP id k7-20020ac85fc7000000b0041222f5fe00mr8444964qta.2.1697415488552; Sun, 15 Oct 2023 17:18:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415488; cv=pass; d=google.com; s=arc-20160816; b=Bl/S11866fmZX2B7k+KxEKhMiHeCj0Jey4i2PRHuIzfn4YY81AhteivRLE2qZGE+Bm Irnwe/Dw6zErqxVtLEU+5Ml5YFKLqLJkE30lz0x0g7vV+07spmPhm+jFvf94kytQb4I1 f7Grye6tQ9ShUYoC8BmlkpqMcVy43vJPZ1jRp+QMh6pRgky9c9IaCtFPyrpFHL/20EkK dlEJOP7GijL/f0cH5KbFpD/7+E6Y3LKHtXqXbCw2GstQcAYifTkmkVEeFTLxeXYnFt9/ nLCwlPrN4ONZ2hCuPl0iviVPRVZRnTQ6xQvOrbfnXXX3dBwyZMryFqp4YZHStG8ptb4y 4ypQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=drDSkwF2b66LppQZo7mvO/N7JkJbD5f+nFqDwGJeobc=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=ly29BKt9jhT8cfyKVghAK2mophVlRrtesOf6Oc1YwkNLd/q+ENmKsVwB3IPI/3WCkj Z3/Ik+lp6SImL1i3HujNls4fkILdqgYh3HNTALMk+XmqTDXcg8G7dhyeoIi0FWWOw6du x06y6dlGIf7ZWCHAZs1CWrTFdj5ZfaCfndOBPg2SgCTu7CDsEAGDG3pIquRQBgB9M4mI fxoAh1Vq5vsphRVbFgovQnYGwqlR/vme4DZV31QNMI9gQ07WUTr6HJB8Hgff5i9NQvdi SXtU9OXEL/nQIX2GE3Iuxa0EhXVgPKtoOzb9JJXdc1xJBrJ5SrceqoxDjDi5nzCr7QaZ /mCw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x4Kv66ph; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i2-20020ac85c02000000b00417a3aa1fb5si4724327qti.573.2023.10.15.17.18.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:18:08 -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=x4Kv66ph; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B7763858035 for ; Mon, 16 Oct 2023 00:18:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B7763858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415488; bh=drDSkwF2b66LppQZo7mvO/N7JkJbD5f+nFqDwGJeobc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=x4Kv66phTWnu7jZ9Zp6WNUn6vTJIZbAX37HP4P84YCLCfSxr/pb9np+/ogKfmvnQE T7/xV0Cz64g0yLrCmOTEi/L4UCQJTvJZsrpSq15ycPhjv2N+aozQ592+a/LJLpIrGW nV3Hug6JALz5RI9x+GAoQhIHqYzcLM7kENDN1WjA= 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 EA8943857803; Mon, 16 Oct 2023 00:14:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA8943857803 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA8943857803 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; cv=none; b=PyDx3bX10iq+XkSgf/mPX0GL5OmEA9iXcpyELLn7BgNZh5upx66yEUGo/J/NLFQ8OYrhXfdft5fF7bhEnz7uGSs7TaYVDbK5EyzCK8Sru3OcIKvy7I2B9GnOvBtrkxzh8EuSUiw28z3+6W7ptK2L1T9MkoEhS6BEwwrmO28b40U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415274; c=relaxed/simple; bh=BfhYt/j2VRJjuMIYFbFyeiniSUdXiuS4K54TRYwyHXs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=M9nOBsGHe8xD7sBkb4iyl0F9S+rAM0h+uICNJiS0g3PIrlcD7ct7AHlA89H/O4qCuF2lUdUupcbwIRceJdR0YYtD27B9J/VVuribyx4rBO+Pmx5n1BVda9sYgZBkZ+bf5URT8/Xgj5u5t9pLKO8grT/9XEqYpB6H6WtziaJ8xm0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G09Qgq008142; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqk70fuv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGJ9001216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsK032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v20 30/40] libstdc++: Optimize is_pointer trait performance Date: Sun, 15 Oct 2023 17:10:14 -0700 Message-ID: <20231016001227.2717180-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: j5e1xzZtUZyvvQ7cCfAC7V7vKOE9RMuD X-Proofpoint-ORIG-GUID: j5e1xzZtUZyvvQ7cCfAC7V7vKOE9RMuD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 clxscore=1034 malwarescore=0 mlxlogscore=486 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997371839653001 X-GMAIL-MSGID: 1779869143690292446 This patch optimizes the performance of the is_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..cd5ce45951f 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_pointer : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_pointer { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9c56d15c0b7..3acd843f2f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3254,8 +3268,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Mon Oct 16 00:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160324vqb; Sun, 15 Oct 2023 17:27:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXg4Q25SGoBZeAP6mU1bw3EGj0eDbvfNnFB64cJ/8ozYAZDWw4D6xMxp5Tulssopj/y+JI X-Received: by 2002:a05:620a:2446:b0:770:96a1:558b with SMTP id h6-20020a05620a244600b0077096a1558bmr36361880qkn.14.1697416074797; Sun, 15 Oct 2023 17:27:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416074; cv=pass; d=google.com; s=arc-20160816; b=GS6Ukkkk+Q9LhwupJYCo2KHfbSa+bjAutne1MEpJIa6QXZ8zRZ3DvVCAxl+xpILQ+p aA/kLIpd4AvXt5QhPn7ix7NQyS8yVP6XxtQqSDkkd2ObX+9xDF39OzykcNIjqOE90nmx QEHn2MsTUrAcGJ7nJjBcR1cas/unFq1NjKX82lAuoeEYzd9/fGDsBAYp2aoi/gkz7r1F C1a8kU+iJXc7gssNX6MqFsjZqzJ6Vej+RIJy1RWC7DO+wyhlxGw/qeYJJ29vVwUsg8hV kIoL+2O9qgjir0MbuSzSqOFca6l5MTUVk5kje4fLJ8vQlKF3O7GQInCvIVJkNVWcLo17 /Lzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=f7z37DsjAwyX042EfeSVKHpUntcym/J7MYn5lkdDXBU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EVZNZ1sOTH6LkHdDNDHmMQiwpEGIQzLzE/KjSfSW+pc2HEX9Na5pbgeYq8s7jfW9QU YGlrwa2+SqGZZKnvlWD6aMQU8oV2tBnQjbWdupxBD/B2zsVGQ1T7YCPUuX2YlWZfzecY wJ7wQ1OfXMkSBwl1CfLmbDT4yvP2geepzBWMyWQxrpVUWEhll0zLaIZ3x+aDR6j7kWCq XIRhSrLYMsZXCx2/AFpfleXkZsn5sZkexZoldexaBiLU29k2eoRGXXv8uDfgXF51m9Yp 5ajAHVhUe/sCR0WU2CBsQQWpo4F5ZZ9zmvStU7gi+l3MomRIzYQ7ONLqPVwQx0iC/Qrr d3MA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wPFx8VSh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dw17-20020a05620a601100b00773bbc97627si4523191qkb.467.2023.10.15.17.27.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:27:54 -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=wPFx8VSh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81EFC3858C66 for ; Mon, 16 Oct 2023 00:27:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81EFC3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416074; bh=f7z37DsjAwyX042EfeSVKHpUntcym/J7MYn5lkdDXBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wPFx8VShSz5wjzQGvuO6WkkuA8/3IG09Ioh1iwuZ3f1KvjkgMR74PMuPgaLf8VFfv g+3Dd+4D5eU7vjl822NQ1uNQAmuxpTvyttZLrJ29Rl5jk0/4XH6GGiZ5kp0HixZPkF y/SDaLjlqWrippMLZ10lgf2u6Y++W7Z8Zv6tAPvE= 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 C1C1C3857BA4; Mon, 16 Oct 2023 00:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1C1C3857BA4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C1C1C3857BA4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; cv=none; b=nYQZOjFAAQZkD0q/9AQNpIVH7Cr99/QDTA5wfTJtViHNQ2A/4S3HfYkiTtbI96YRygl/sR2LAvsyFFq5cGeLofFlwALotGmbMYo49UnqJo8/qLNJZINITeLkiXukHn8r7BTptIEuSy08OXQr2ehdqofCIC3XVQxW8rmwQPhxXVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415284; c=relaxed/simple; bh=e0naa+kjY6ClTqeN2DAAC63a3CX+tx4Hxum4u+PM4us=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=B4w/2ek27tTP61MxftOTF8IzubMGGuK5qVdz+yBEMorE7/4njHcc4zcxUkGhDEq7V2PN0T0vrOtjcDZ/aCOewIgEGMLhi6ffSuCtink2+GaEkZGwbi+wJ0YA2wNZUnOfQ7/D3cPTka6p6zo61B4J4PAivX2DYws8NN0iJdwOOOs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G02GX7021570; Mon, 16 Oct 2023 00:14:41 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dk4c0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:41 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGm6011862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsL032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 31/40] c++: Implement __is_arithmetic built-in trait Date: Sun, 15 Oct 2023 17:10:15 -0700 Message-ID: <20231016001227.2717180-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QRHNGQPQiv2_E10SdTmKGydpETDAoUKE X-Proofpoint-GUID: QRHNGQPQiv2_E10SdTmKGydpETDAoUKE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 mlxlogscore=856 adultscore=0 malwarescore=0 clxscore=1034 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677582756408093 X-GMAIL-MSGID: 1779869758471358606 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. 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 ++++++++++++++++++++++++ 5 files changed, 44 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9d627fa782..3a7f968eae8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c60724e869e..b2be7b7bbd7 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 83ed674b9d4..deab0134509 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARITHMETIC: + return ARITHMETIC_TYPE_P (type1); + case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); From patchwork Mon Oct 16 00:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159244vqb; Sun, 15 Oct 2023 17:23:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdcEc6LU6jAZE5kecuj1YscrUBFgkDpnQJpWrntJsgFTe2shQM8udNM/TZ59haGnNbiCfV X-Received: by 2002:a05:620a:2f7:b0:774:139a:e442 with SMTP id a23-20020a05620a02f700b00774139ae442mr35085168qko.76.1697415837226; Sun, 15 Oct 2023 17:23:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415837; cv=pass; d=google.com; s=arc-20160816; b=fccjoDM+LBlxXW7vXP3ID6cppF7Jo7PepwGXftl0LkscnQcW6leudw1CKwCT6Ozo3k NX49wRLR8OM2B8O1B/9LL+z2d9eHv/27ktIgQXb3E6XvxiTfjghs696jIlg42SZyBI3s LCQbSC5F2Bh1TLvBWdkeUV5ij5YK4ZjxwuWchgXCmwHPVhc+wV6CkbPkY7xILiUtvYHT 3HUUMvE3J0x8x5aXVACDoVInCCHcvgKlLeprIvNH4hfYsQOgTpgZhgUIjbNhUyEgQ3TN mCE/DtjHGVyor+MplHQD9j6Dzpc/sX46GZitBzT5039nVL/vFoac2eaxmkxx2VGZ+99z /TzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=GR/oeFXla7puWWh7QKpFOKC/sIPo9/QU9YiXU71ulwypHHC+3yap4+Okvpel+Gf8hj mIiWOw8g2wIFAO0DcJXDqpwBtMGYVeEIXtT/glD0xGIsnDxSd2PkglJKmYCWpz3yQVKD dqYUj+2984Qusmw62fuSfbr2GDJbFXY+gztmgTJTDdQ6/FSU87lPUrxeQZMSbFJhU1FU 1krhtcvWCC0HC9DnkEMMg98rWCWdn4dDRWwbcbJbBp2aj+iomtPiObhu3UAeKhCAA8+A bzpXNa6a3OXN2352s+sqQCGhpDkq0KsVlLkYEtQHNKFLk70h1UD/TUpQkCqFbFQHyQ3B SwFg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pegYVC8c; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id uw18-20020a05620a4d9200b007756e6c7dd1si4543029qkn.573.2023.10.15.17.23.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:23:57 -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=pegYVC8c; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D62213856DC8 for ; Mon, 16 Oct 2023 00:23:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D62213856DC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415835; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pegYVC8ctJTlT3IWsI9PK6vwyeG8CstOenKEpDYjRwpVuN+lTYZmkL7tODrcnPIVV C96mWUOhLz2VY42SP0oLK9YHDjRAZKAt8bsOFdw8aI1baQdPeXGsD6lZ1CracEKp16 k8B0DW+SaeiqIVKLwo7et8dAJHe/yPxtLRK+ZG2Y= 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 780783857355; Mon, 16 Oct 2023 00:14:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 780783857355 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 780783857355 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; cv=none; b=XMS1L8kdRiWAybVtD5IFJ5P72TYjWgwds72aV9FZd2ZezQbx2qlzHgo3jUCQAmEwm/sZarG36+uXoOUcXydVOKY7yYMqbicOKJePBseT7RFyIx11PwElnG3N18+f9YHcJc/xjVCAPbkCAUtcLUBunAeKoOCx7L8lTGsPyGP00+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415279; c=relaxed/simple; bh=axxlZKKPGB8wuYsjw8SAimjjV9ZTlh7UjEpqEksZVtQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Afj0jskGOXrfsj7dKukjI9TRIButvAQcCCdcsDDK8dJMj7pIHbWtJdMy2ah/9J9itXMWMsLDMzvUR/804AS5j6IGiRBjfZEn6bhawBYTPQp9JRA9lK7ERi2yU9rNyoO2xf4mJ6swS1zHZDIUXsyiTKBdOVWCCYlfx0PlCNSKmYg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G04Ha4025143; Mon, 16 Oct 2023 00:14:37 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr517ve66-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:37 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGBV005474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsM032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 32/40] libstdc++: Optimize is_arithmetic trait performance Date: Sun, 15 Oct 2023 17:10:16 -0700 Message-ID: <20231016001227.2717180-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: GzSkb03lOSvQzCevGVU6argXWvckosHQ X-Proofpoint-GUID: GzSkb03lOSvQzCevGVU6argXWvckosHQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 bulkscore=0 mlxlogscore=666 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996488688417878 X-GMAIL-MSGID: 1779869509067060720 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 Mon Oct 16 00:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158805vqb; Sun, 15 Oct 2023 17:22:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDk73o8cGigpSl98RehMiBI9c93Z3eGAnIglNcP27kJjTVWV/mOgHh6YdIhzdZxNa4Z3dm X-Received: by 2002:ac8:5b4c:0:b0:411:fe66:9462 with SMTP id n12-20020ac85b4c000000b00411fe669462mr47905907qtw.12.1697415748762; Sun, 15 Oct 2023 17:22:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415748; cv=pass; d=google.com; s=arc-20160816; b=Qn4QO+VPV1tdtbxzLm/cyZMfMUj+3G/PW3o0ohP/7YTWAp1KE+Plyrw/MFsmno0HQD DMtX4ZhU14w+oDIBoUP48ZIcIENYesi8KKbDtouxdSq0jKPd+oRSSiI+FS3QJhLJguBC dbZ0OIc4Zn1Z7RmGU7jKmE22WjQpWVV154OIXEFh8nWn6nO7sskvawrHgUQy8M8UWMck y1A5nc6+w4Zqbzti3iXez16r/CPl8eTSOUltJyPtZNtxs6A72/9mYUX/it5ZRgvOq+fN 3jMaoqrXXiO5iu+OGmr5Pp5wyQeq8zNwA7QwSX0amb9s8FFH5SSLfDeinirxp78eyXtC zTNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=BEE/LkmRGTVxlVfmv2sIHyzZ5dUg7soi9QNBavqxv8IAw3M5RzmdaGiR0N4eVli5GK ffqbF++s9FcBgzPioHKJRRisJFsQ3AIjjn3JQntR9CQIahNjZe3XFN0NVUFh4bI4pHk8 WNrr0TIpxENq6nN81FKBmFEzb0CZXJKTT0mWbjo+QV0D1htn/IR9he2CqvLLrlQwJKEF C2Eep77cChixeuwhqbqP20hFi42OEaouE1osJa9XW4qAA7jIf3K/ejzcVShOj2ZTltnI JLLrcguKhnD4lEvjomcmaLXVZQNspUsHqa0tPEzZ4TUNjowajn9KZEu7BiJ3By8vadvD ZGNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JKqM8YwU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f11-20020ac859cb000000b0040f3c2813e2si4611847qtf.166.2023.10.15.17.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:22:28 -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=JKqM8YwU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 134EE3857727 for ; Mon, 16 Oct 2023 00:22:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 134EE3857727 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415748; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JKqM8YwUsI/+62LapnM9PlSCf53cRmVw4+zfkfDdxJ+PDcz+FrLustKfFeohkN6gb /fuqYZReQbMlE4nGyEGdLP1mekC+j50tr30RMXAuVgY2i7h2WWSrS27Zij25TDsYM5 D0lDFLDyQ9ZNowjG+oEuLEfX6vyQo4T5uIWkAiJs= 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 19FAB3858024; Mon, 16 Oct 2023 00:14:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19FAB3858024 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19FAB3858024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; cv=none; b=LLFuIqdinaKyX7cPK+kbWUVMU41UljiMvcZ/p+86qEtAGO6VyYtcmWoBpFRNrll333vG3+gjD14C0PwG9WSiBBuI4gvQwP2iaLMt29ftSMIeggNjYkjB/IcThyOwnyYx5Mkr5NHZU71hZZl6uQj0iMlX3/dUbt57nGP+8jWj2MY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415272; c=relaxed/simple; bh=VMehu4HE7BzN624OVO4Fw+NnsTWTfYiByT3bQXMD4Js=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vi7V9yEFLHXz4inkhsD8a6Bcngeq3mOlWaiQbAxIoJKJOTUzfHKtAxyfK/QDa4Q1jVU8VIKxi+gLUN3AEjhpO5mJdN85e80ZXc8UlGX6e5dr6tMG73SSUvzDpMJz/VQA/1zkV18BOkmfqRx2IdCKniqdl6F2/n4JNaoc+U9bOj8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0DltX015645; Mon, 16 Oct 2023 00:14:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4wkma6h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EG8M010501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsN032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 33/40] libstdc++: Optimize is_fundamental trait performance Date: Sun, 15 Oct 2023 17:10:17 -0700 Message-ID: <20231016001227.2717180-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: y593Bxaq33UJ9Ct9Lkawzcg0wFjSrd7p X-Proofpoint-GUID: y593Bxaq33UJ9Ct9Lkawzcg0wFjSrd7p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 clxscore=1034 lowpriorityscore=0 spamscore=0 impostorscore=0 mlxscore=0 suspectscore=0 phishscore=0 mlxlogscore=534 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996476757191546 X-GMAIL-MSGID: 1779869416173607221 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 Mon Oct 16 00:10:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159412vqb; Sun, 15 Oct 2023 17:24:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGye2UxY2Mpf8eBFrmbn2nLnRtr6cHk4xJ6IXOloKBa47/EdaSKdOE/8JbWHVq7jY34PnLh X-Received: by 2002:a81:83c6:0:b0:5a7:b96e:9693 with SMTP id t189-20020a8183c6000000b005a7b96e9693mr16266595ywf.31.1697415874727; Sun, 15 Oct 2023 17:24:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415874; cv=pass; d=google.com; s=arc-20160816; b=KCDMSRHdxHpkoDNrEeOiviZ52glAl01OCv/8NMEkUal4ANpjiw1g+jlbWZoQyZJJ45 33W+TuHFoWcst2vON58+J+xdOpz2p/SfXvMkdJnDpoZoFyLN0xo6ojNYabT+MvzR1jZ8 7AWsFMO+xJCE2TXAEuEFyQgHupjvyNm6NJwo9AKbrUTYKtA1ZlKjoTWb7slA92EaMi2a By1fZPSBSU8UUsMBeHLMH6feQAqq6R8fEt3wNp5Er1s98ffZSEv0T5WFDpiBmWhhHFWH kJZ6/tGbidsm4hwGu6tPaKnqBd+QSHI/7s/5w8f/ycu4/8XRjWVbTdbHZp0rbXX6q6p5 l8EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=byYmSGUzWWoWvz8kTKJTqjaiDGSAuoZGB6C+v6/HkxCysx+tjR2dZ0MWKdecOa+0GJ Z0V3UuBdHU/pssjHcqQ0ZQSrp8z/aCvcDpG1xdNyFV4wwHiFcpHwpBlSN4I7IgutmOZd RGTpyKR4zi+IcXMk6BPdl4P5aPoLqfpu4WGoZkeW1Zbl/YUF2x9lqKZROkTK81Xbw0P3 BZutMUMXYBCzxJNisV7ouM2YmAzmfPvnmIvalTjoUu3OLkObG2OVjd1gEfLmrVczSQIX 3I8R/0fflAfKp8Y19quLY7OF7uWRxXHiMWO2WZPojwnvQhjVCS/J5ek2V0ar0wJ3V2A/ /8xA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Iz6KFwIq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id es20-20020a056214193400b0065b0541ddb9si4601011qvb.93.2023.10.15.17.24.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:24:34 -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=Iz6KFwIq; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7BCB385735E for ; Mon, 16 Oct 2023 00:24:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7BCB385735E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415873; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Iz6KFwIqJA00EhI8DDOw1z31vf3elbDPSFaPYkZkVWPthR+Ma603sCwwFhFVjFYix NYk1oXUUX0eT9q3QJ3NKUdTP/lVTN3dJOEVuXWNYD4t37PCZa6Sc85MCSkEZ2XOTvm Qi5Ava558BPHA4eng47G37c+Rr4IufVF8lPfXHGE= 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 0DE003857706; Mon, 16 Oct 2023 00:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DE003857706 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0DE003857706 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; cv=none; b=PONJ5KOFUsoc9gEbynCIz2CJ1ManifeauCn39ZgGl8SzwoeRDSN2ApoawMtzrtWErdmWg9Bg2LK5ErKijECd8o8vmeptst/vSG7s7wbR2gEDBzAnITPZSYD+0PbXvwYcZguXvwZ5WIQoV5P1HD9A9T6HBAdU7+QD3d5SNso8cDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; c=relaxed/simple; bh=oaOZvY943DFsKkUU3T+LqLGilkqxFzx+Qlt1BfE8jdQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vBi9os/ihK2AoeTE71272D3MbxMFkqw3urTX0BNGhH9f6mh/SnfhbXBN0IpyBPlfT0uDpikSUKbx92lxD77ZYRwJD1FeHkDTWdO6W1PLS7Zb06PwbA239AEdHVzBYvLO+H7T065+QhFCteb5M9olyLWRx6XDr1qUInr5a4MEPUs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FNgdBT027663; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr52pcath-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGWt011863 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsO032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 34/40] libstdc++: Optimize is_compound trait performance Date: Sun, 15 Oct 2023 17:10:18 -0700 Message-ID: <20231016001227.2717180-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ICXXPgqdBmElH2moFTurWo2-sE44VJtR X-Proofpoint-GUID: ICXXPgqdBmElH2moFTurWo2-sE44VJtR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 adultscore=0 bulkscore=0 mlxlogscore=596 spamscore=0 phishscore=0 mlxscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996293852351903 X-GMAIL-MSGID: 1779869548373336528 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 Mon Oct 16 00:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160618vqb; Sun, 15 Oct 2023 17:28:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKRYGX/kUzd+btHiyr4rwmnGgwFsEbspdTBSAr7T5vwAw7Djit/XOwa4yxkTLC25l10gQy X-Received: by 2002:a05:6214:580a:b0:63f:80a0:4eea with SMTP id mk10-20020a056214580a00b0063f80a04eeamr33099553qvb.24.1697416132599; Sun, 15 Oct 2023 17:28:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416132; cv=pass; d=google.com; s=arc-20160816; b=dV67CbP8rCejA9fMvIHBu/yUelmO435VeFAAoBDuHvv9510x83ej0jgpxypXs7DrpE A5czmRUWX4fobqYNMh8zKrS4SkGMADKo6xkahtfmL0l9rmR7xV12RYM2riJ6HTbx3T1M gXIJlXvEvd4LixRi4FXI4SaVMBIBJ5CScHWu3yZzkN3QhdXQ6aJz3s7EOBd5XTHuX+DW p9JNUXLO11h/ee/ddvFYCy6xCzPpDUDSXE6wsH23Vx2C8Dx9jzccAO3X4SFNqcg8qZqa OBXFSuSBPw/aY3mNtrZ0LVnUd00GlM9MyqnmhowcAL6FtoKzB0VdqjRSluqOsCrYlcFn nCTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=u1w4u0QuQ6FgMTWhhAvTAf2gwffiyTpOXFoWbInJw6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=DzGve+/usD/63DOQ3byYvAAuTDupQeLvOPq1nT5FsU4+pPGU+9Lbpd/m9IMqhETdVs koctbiwAJ3CZvnnfSrO/IfOO7ET/a9/YYdp6lF7xu1VrMvoZ9jXFcENdiWUXwc4/OrTX 2fOLWAtFFaE0IRHq/ifYvW/ZaPlET1eWm1pamho0fIg5iUd4vcC6LHiZV2lr9ty4lMCd 0C+DMrpz0M3dLnSvIQDsjdKWNi7/mV12tbrtjK7pU4Fh73yjgwpqKVrvZ3xuVPbVztA8 J+6Wcx7Q588TblVjczxr4o/rP8OvOe6H6wVU0GNE+kQd96sbgBGOMlIINtUizNHxsUhr 7jlA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="X4Of/NB5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dz16-20020ad45890000000b0065d13c27e57si4614621qvb.487.2023.10.15.17.28.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:28:52 -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="X4Of/NB5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 506BE3858D38 for ; Mon, 16 Oct 2023 00:28:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 506BE3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416132; bh=u1w4u0QuQ6FgMTWhhAvTAf2gwffiyTpOXFoWbInJw6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X4Of/NB5dp8GM7EvKbsKi3a0EdDhrwXxXRvN3jzAYUU7BSlwa78EJcMuOeyj3CA0G uNIouXLACl3gP65kBjAJXlnM76AD6ICTYvh3tOCEWRQM/TWMq0tXO0IOzN+/8+ZIq9 0r1iTX52B5Wiy8I10GLH23+6BboStVbkWAbWGAG8= 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 13CF33856DD6; Mon, 16 Oct 2023 00:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13CF33856DD6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 13CF33856DD6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; cv=none; b=sgt+1i10p4kjQwvBtHhIjY2SjkHZJ7m0OCrJ/NrzaT5Uy4FfzXXFaNIPMCaKInwf5FkYD05DiNqa57A+7MYjGr2NyWRGugoT2CFrwaU0hZ066ME34yuHK8pgkL0pLdyoEn8ZXIu0062lE51jswM6W+jmlXIJURRTJm3r6NtAqHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415285; c=relaxed/simple; bh=a3zO0+PvIZh6UbIZgNK/H9Isums6y1Y5eSQUiaLYf6s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=d56jZV0/mr1hpGe5PkNhGZjVvR2UF/lg8LF8rw25+lHuaJMvQyKJLnadYW99doINFiyv5nTLYQEnT5wKSPaQBSkSWTQYtU3QesCVGyx1rU9J7t7oAkjfxpTnDBQSgbl5xfV5znRINW1aOwQaA7wCYUk4XT+SMTJK4eBi9Zo5Up0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0CaAe001570; Mon, 16 Oct 2023 00:14:42 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fgy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:42 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGXG011864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsP032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 35/40] c++: Implement __is_unsigned built-in trait Date: Sun, 15 Oct 2023 17:10:19 -0700 Message-ID: <20231016001227.2717180-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: s-WCoJ4vCuwqrnLTka1Z38O55tl7j_a_ X-Proofpoint-ORIG-GUID: s-WCoJ4vCuwqrnLTka1Z38O55tl7j_a_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=809 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996278564175547 X-GMAIL-MSGID: 1779869818649196320 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 b2be7b7bbd7..0603b4a230f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -94,6 +94,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_UNSIGNED, "__is_unsigned", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index deab0134509..14387821b85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12250,6 +12250,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_IS_VOLATILE: return CP_TYPE_VOLATILE_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4bc85f4babb..3d380f94b06 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..2bb45d209a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Mon Oct 16 00:10:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3156620vqb; Sun, 15 Oct 2023 17:15:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJx6QzFAqXwQdMlsrwnMl+ppd5gTUr/PakUP68JbPjKzsaroWt1rbx50cIFMiFxrO2gxiU X-Received: by 2002:ac8:5704:0:b0:419:4e1c:6904 with SMTP id 4-20020ac85704000000b004194e1c6904mr43554862qtw.20.1697415320579; Sun, 15 Oct 2023 17:15:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415320; cv=pass; d=google.com; s=arc-20160816; b=EebAkLPc53LucJDzI5Xw6dgK7X6bsdHVBK2VW8uOXo0PBR71EDp39YEjYf5Ib73OhW rlk+pr/jy4wAZ72YhkSqWhRCa4YQBcQ3YQJEwAK7uUh5xKzzBbnqSmqU1K4ltb0bMaSU ePCXbuO638D4e0eo6bOgvIKR81U44rn+QMi11JDVxL8IjQO93eJ+JNdSTvTcXEYACKJO JcaHvMu6zAHCD2Z1RxoaatltPbk/Rns+6zoQXYrqqGqyB2nV58bQ1CDSlrEOnjduWavk YuHaG31cxSlU8o4I5tSWyioKwCqw3bB7jBmB1oXNpHraX6zSTPgbAEB9t93qjMHfmVu6 tHVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HyIqaSaiP3w05ctNKK8+FKP5EQIoDQPLiRyEASvaQVPrEdAQaWXAEnRc3eKRXjRgri jgW7n+0wM2QxoiU8zbSXtf5qhTzZzNtf3sfWVA86azDveqj+nO6meiuxhBnvQ89y9bxz Z/yAWIP+Pp2dcmrb6Euy/EM89fxTBL3IzDN7OVojkirIUG+J3RCTaej2Rp7puwH+bCt9 I7bWfk/zv/tHY53V49x4L2BwcGZCH8Rs6VhjvzJsjhOmXXhCv6ko4h09HjKBfr3aUP95 xFHHU9wQX9FO4+V5kzPhyl5kvAlRrmQPV8IUbr75/tXgsKp/rdIuDsaoXg3ZR0DMB/yI UAjw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CRgoEPEN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s9-20020a05622a178900b00417fed5d04bsi4594620qtk.685.2023.10.15.17.15.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:15: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=CRgoEPEN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D94E3385840D for ; Mon, 16 Oct 2023 00:15:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D94E3385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415319; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CRgoEPEN01uDkn84DBJUAwZjNLGaPCrd+S+TutCvVedyJSB3eWbvf+7jYPQmVo/2x NvXUQPrHtwFaO3PpApaoXgmL+McCjMNozEXENLXLAr5q9Otc1f5Ki6vWD9bL21IWrz 27ySr9s+cCrD6ekJYlPGZ4DgcFlnxGki3iDNt+Rw= 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 85C4C385828E; Mon, 16 Oct 2023 00:14:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 85C4C385828E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 85C4C385828E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415270; cv=none; b=Ws6coYY5bGvhZNIaJYhOMhHBnAnmatgVePkeXVUxf34OshjTNKfgNOVo6tzYgfm510CPzyykLCzjHYlXE3m+WOFOCXQBazE2DaeFq9D2le8EN/Q5KotyUnwg2qWSV9S+LEUNopV0Oj1mbgEn7q+LzxVy6GeQKifoyOkH8Yi/6uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415270; c=relaxed/simple; bh=OO6VSbfKobcguq/wZw63boKixhRizHhk1hfPeW9ER2I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=xws9HdREDndBft8U29fw8s7Zr7Batcn0FfbnCTJSCEcjdKv1bzu42hT81nWHSSfTaocYv3ptC11AkXiAKJZObQnPuGyw1GCWRrQnXAev67ZrWKFSoIYeQMrWbQYa+c0E9tYaMrTbZRvSFcyd5LeanZLXUkq45TbmCKS4PB8MFEM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0Ckhk015029; Mon, 16 Oct 2023 00:14:29 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4fxch79-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:28 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGiq010502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsQ032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 36/40] libstdc++: Optimize is_unsigned trait performance Date: Sun, 15 Oct 2023 17:10:20 -0700 Message-ID: <20231016001227.2717180-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: aXTP6KesCVjkt1vbC3yCym-yio6e5d42 X-Proofpoint-GUID: aXTP6KesCVjkt1vbC3yCym-yio6e5d42 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 mlxlogscore=629 priorityscore=1501 suspectscore=0 impostorscore=0 spamscore=0 bulkscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995061376064333 X-GMAIL-MSGID: 1779868966795813103 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 Mon Oct 16 00:10:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160068vqb; Sun, 15 Oct 2023 17:26:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNEQl95STeO5GIWheUMSYt2IxR/Srb8bkjvLhCcytwfs38BWzpdrYBzTKuug+nU3YBK6R5 X-Received: by 2002:ac8:5896:0:b0:412:964c:c4d2 with SMTP id t22-20020ac85896000000b00412964cc4d2mr40241190qta.0.1697416014829; Sun, 15 Oct 2023 17:26:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416014; cv=pass; d=google.com; s=arc-20160816; b=FLAT8vThSi7T+B8wVUkE3Wj1nlvUymU+HA8CT/ggv4Hxv/dgHA2+WpEj4mRrGgCjSt Wx1AXyB8v8NvW6lf+rM1sgk/3fqj0IT+/Nak635G4RCVv787XHUZsjmorFNwkxSgLUIZ tCTyjC+WIthNLDPDOjF05PgNhD2aPkWEQLynyup1Zbbva8V3UKRQO3zb7SB9m4BP1/Oz qUKsVvexh/8TvtYUNEUYhBqQ462pNo/ZGDtiDjyUjDhrrJgff7Wn3idGjupl65zCw+7i 3ehj7ZgVbHXi3kYNuSTG2Nj4XhvdXsNkl8ZOyxxd2CgZGyCMnObuShstyO/v+3gSNOmF jWTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=5i6jRaqZ6z+129iF1E7ryZwUXyZ6lgJMJ5o91F1QYXA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wKUz4gQ1FNCBzur3RANZlsZID6a1cpAq5OmuXmOFn5v9sEvOoEA0tH7JaxfIBHsTWN pF/LlPVt0pLw3PnB8eawid88ALfmRkdHIvcDkgXsY3ZHj9FI7HXmeJQ8KU0CEIwz0sCY ftCMvgWVutCKaZtbLkXimtLmk4KMFyHsVgyoKo+8B32ii8JV2p/4cLG81uT/bPH3k/t7 1XsHsCpKqA5eo5a/j8OZYuA0UHskFkBoqUU99t1sNtCaBLgz8rrHiHkR4WHSh+Wi29ae GGR2kARpPdH/HWuvkrMw1cPjtucz/b1iRW6INnN9tFowxsOVGgjEge5nOASgvcUrrSLG MI9w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J9rr2NSl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s19-20020a05622a179300b0041979c13981si4768741qtk.298.2023.10.15.17.26.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:26:54 -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=J9rr2NSl; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AB413857C41 for ; Mon, 16 Oct 2023 00:26:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AB413857C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416014; bh=5i6jRaqZ6z+129iF1E7ryZwUXyZ6lgJMJ5o91F1QYXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=J9rr2NSlonKI7lHDFA+T+5NCSFoJPkG166mC/amScdmSUvxOwfugs6MimCuL+OIZ4 KZmCB2m9dBgiUzz1VNMM8T5VK1TQA+yYE/0m+ZSs//HNcHqJe9gCgizCJBbwrqO808 SNwajmzxIq5jC+jyMCoWTNIBzlP2hYc0QXG9Z9rE= 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 622D63858C39; Mon, 16 Oct 2023 00:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 622D63858C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 622D63858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; cv=none; b=u4zrdQL4eNNAH7HI4UZRyQNeUWFJ66RpCoBKKz8E4ZDvLENl5lOI4dmZMDXphUWJODF4QxouWN3PM/63XJdb/iNVVz0aUiZruUcb6Orm0wEU3ZWI6/89N4oQJwXzkMLQQG35rYAcU0l7uofHFwJNSyOpAhnS/ox9KevadbC1gOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415275; c=relaxed/simple; bh=5HFd4PflPh+n+QqXM20vU/ksqTwh7engB/ztT19aLLg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XFmfwNy7j8etmgW5FasQykbkiQe5358v63jvyNpLu6XNM4HZJTHMm66wA891ZnwPrCPIhutQT1U/PaogXfLOrPChO/q21mrjADdd36R2XA5dld+iPBw3qK9N8KA+9Ca3BAUTqHr+MAyJPqgpkcKQljrPgW673qO+Pb+ctDD0W0o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0DhBp015460; Mon, 16 Oct 2023 00:14:32 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr556c9yc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EG0k027869 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsR032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 37/40] c++: Implement __is_signed built-in trait Date: Sun, 15 Oct 2023 17:10:21 -0700 Message-ID: <20231016001227.2717180-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: j7gNS5H1ZGB6GkKSTHK6nyXd1ECOMiC2 X-Proofpoint-ORIG-GUID: j7gNS5H1ZGB6GkKSTHK6nyXd1ECOMiC2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 mlxscore=0 malwarescore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=705 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677879825354017 X-GMAIL-MSGID: 1779869694870675103 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. 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 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28dad702c3..b161c9b2c9e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0603b4a230f..b0faa4c8937 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 14387821b85..5e6b2ca37ac 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); From patchwork Mon Oct 16 00:10:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3160093vqb; Sun, 15 Oct 2023 17:27:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6t/oYzDXDaZa9NVrnaWd3k1ZNF3cD1yFm2C7sZtlE6C15YvL9yGvIgSjNhOLdc0TtCnaL X-Received: by 2002:ad4:5c87:0:b0:66d:34a8:3ed0 with SMTP id o7-20020ad45c87000000b0066d34a83ed0mr9215334qvh.26.1697416022016; Sun, 15 Oct 2023 17:27:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697416022; cv=pass; d=google.com; s=arc-20160816; b=Xv4r7aaVMebklwwUhGy63HL+N7Ed1zgbXNgyPcgkdfp9ipkjZI/O+akyIlzCOiHDHR 6bv/JKesrp8RGG6OitodzZyFI7j1gcRkB8066E7f+ckouh7yEVJEbU8RFjGFWia/zTFw R2Sx69EIvqccU3RWNglnaiKJtZ5cscW3FXD5cPJJ4If6c5XzxU8ixOUWWbCW4HB0GLqf BwPmJO0r1QihHzBZWrHDQweIWPnx3e+GOAI1T9FZLryi/2LAQqGHz5y76lvg4qU6Eg2k bLiTHmXhlvgAv+BdJbvIAXl/EvlOq+/97uea8jBnY0EFbcDQig28rGVXWhQmgR1gbf63 uYiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ro9s9+c9r8EO6plocY6sBr0pXUB0QOmWO+JmuZO9QgaX3th8aky7jovhGIQ7+IS0Yy ulHOFStHojPIe67nhW1roTBCzp2GRlpQavNqh4svvIoIJXhX1yLnpt4zxd+uvJ5kla/A cxJnLnXIau/9KlyoTko3XWOJLm/QJJSbUEmbsZJ3XE9sZK6KdLnjBjhjqEZDaF2z/L1d f2bXI/2W3K4wH2oJNc1CJUxeBOxizroqXOGmBlvMRuMvC8puasrBA+GiIksfCHP8HB3b BxFqMgFYoFf3fIfJSpFM/gE9cZNoefOrhPf3esaMRydFHJkY8Tp0Gu1zumv5TdWurOXF BZSQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IXRgnB7z; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c4-20020a05620a11a400b007759f94721asi4504148qkk.209.2023.10.15.17.27.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:27: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=IXRgnB7z; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B63173858418 for ; Mon, 16 Oct 2023 00:27:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B63173858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697416021; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IXRgnB7z0KUk8DJ/83TdSw6PlYRK+teqWG+IOniI5CEGCefFhWpEcPWPIuiJviul5 o3TbrBm0nZ7w5GA4E+G7nNnXGkb+ENP3UHKPzM53LfOMcAiM1g8vmlEQo8OsdAzFX5 vY1SwwZwfH7P92WGVFCd6FVt1DBoy377kA0djTyg= 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 CF9DA3857027; Mon, 16 Oct 2023 00:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF9DA3857027 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CF9DA3857027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; cv=none; b=UtXBD9Qft7+ZCTNu0rX5c9p+gcP883EQ0KlOGOahvg0tey7DQXqXe0RUBVpkCHyDMdPIOZfNb9pLVdbB/MLO7TEpg083b1BIdc9u8OELYjv2U1n5BvUnHfy9jwlOaM689soUVAH41pXXG2itFKxP9G/D53TztmD6T6GtA0Wcteg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; c=relaxed/simple; bh=fm6aTmzL/u+DvSJqIIKZX3rAVzVD2tqarjJM/UYhTyo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=f5M+0mbOGBzjO35B5shvwk5FF5fNy4Hd6hf1j7EHuQXN9MyFcrh0jnueKddeEKzA3Os7FluK4259bHRi5c7e8GDhd9kjgOgNx0AdI0N5y8pv0zmkX7x2FMWPT0C2yroGv7/Es18ctAvDogZ/Kq7jein3HOPhZaVq/hDCEgG3PDY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G047E3010005; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kp4fh8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGxT016536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsS032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 38/40] libstdc++: Optimize is_signed trait performance Date: Sun, 15 Oct 2023 17:10:22 -0700 Message-ID: <20231016001227.2717180-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: OFotz_81xw6eeZHKWrvmqzkHU4yWkjhh X-Proofpoint-ORIG-GUID: OFotz_81xw6eeZHKWrvmqzkHU4yWkjhh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 adultscore=0 clxscore=1034 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=731 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995527999111836 X-GMAIL-MSGID: 1779869702600678599 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 Mon Oct 16 00:10:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3158682vqb; Sun, 15 Oct 2023 17:22:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFA8MuqnGmLMAq1BCYmFvzgqXYCqwpo1hOeicWgAJQ2TgWqG4Gyad6DH7/iZ5C6+kLA3h14 X-Received: by 2002:ac8:7f4a:0:b0:412:288f:3853 with SMTP id g10-20020ac87f4a000000b00412288f3853mr43506078qtk.28.1697415722516; Sun, 15 Oct 2023 17:22:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415722; cv=pass; d=google.com; s=arc-20160816; b=D/Z0ezfrBNKuDElSH4HIUhxlsqzRmEnjTolfbsmfNTVlx0pd545zyNH0rJ+MwcqcUc fwnf8MgHRVJGuyHR9TfFd6GRhqzlc6rbA8KnNRDX/bsHHHiy6zNvxFnfUviQ09QyM/26 4rUxnTDWVZB6gYE7Vpjk4f2CTvrcPmCK3t+Jb90SQOoO+We1vea5HQ+mUTQ8jtHm5v4i QagCWYm/tbDXQhLuaAmqaOQK8bIKgqRUpycKTOqLrAOl8w4UcfcmyY/L0AgpJ/N2D4D9 Vd7Z19s7iEJps9hdlkRwdRiNOJjWFk0D+ulBjatunyePtrX6d2dSNB6F+uDm+LsrW+SC wFiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=1cw5aWItF+xudFwPBrI9S7bfrceiTwRlhmrDaDpGufA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LTvvPojl12EnGUJ6ITCxAe3ablHQEdw2k34MZfVQSpFxvBzltalIsSzRbqQha1rpah +fAqbNJ5z6yiASWMa5aKEYTkN8XZ667w1c0o1SGYF5JTipJbox1f7FKUujkJBIY0YYaA TuRjf4Ueimv/JJG2k5dTMcMhtVcHvjUOl+EG57GfFUch8h2TnfUTQ2klS5gvTStv+rQj rU+eCV0IUSlh/lsK6+N+mdj26bIE7EBW4JBguYEmO4Hv2L72/3+mKJhmxD7YguE7ZCnh 4TJ6ThypsMNhj5y/3qcahUtL7qVPX292r4EOUK1HymUy/pC7vDSyvY74uZPaRjb6mzQe /kLg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nV1FELhh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o9-20020a05622a008900b0041979a08b5esi4629649qtw.726.2023.10.15.17.22.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:22: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=nV1FELhh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB6433857731 for ; Mon, 16 Oct 2023 00:22:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB6433857731 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415721; bh=1cw5aWItF+xudFwPBrI9S7bfrceiTwRlhmrDaDpGufA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nV1FELhh9gT7elQK+bL/IUjXdhRWL0jyPbBhPVOxH4EABYRAJfmRiXxTl6RN8GYBU F0xzcdHznywvOhRDmkLQm8ltuzjNLmiuksiFPcqcrJfEBMHiZk7/LZRQTc4JZ9uAMF CNWm6orTtUOq96I9PVI4nhymAHDwXN2ytpH4u4Ao= 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 4A4253858425; Mon, 16 Oct 2023 00:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A4253858425 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4A4253858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415276; cv=none; b=sIGE41fNjt3XMyMz1Tz5rkz1OCEWH2YPkFJUkyPEgSLopGUnHzFeew1LehyWutcDC7trjyYd8dlocLNFQQ1osBCdGdxmn0afLNVaBGk7eU7wZYrvW17Ah5GVr3ORC5LC5fIxLBmBw9TsWsgx6jdRyO1piJGEYY9SBsgqU12lzSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415276; c=relaxed/simple; bh=NResit7Odh59MzZrBdD4uvSo5Vxv0qGFBTNKipA2nx4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Vhkeu9xagOerNQsw7sYU7izn7aAmuviNLfBywuK6h8M7Y9XsMHLUm0/FjzAxbQpn+hWpLo29uL4CBTCgoPKSEpUxYrtTka1uQSGfisBdPnV6qJb7NhsqxCSg0EvPnU3Wmn0EsEc4l8EfFyrVqjsUbA6tNdnjx+FSOklRombzDFs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0BAZI013796; Mon, 16 Oct 2023 00:14:31 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4dj4es2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:31 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGMW027870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsT032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 39/40] c++: Implement __is_scalar built-in trait Date: Sun, 15 Oct 2023 17:10:23 -0700 Message-ID: <20231016001227.2717180-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: k7UB2GveTo0cHonRAjyFpFgIic4sV51W X-Proofpoint-GUID: k7UB2GveTo0cHonRAjyFpFgIic4sV51W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=578 mlxscore=0 priorityscore=1501 bulkscore=0 adultscore=0 clxscore=1034 spamscore=0 malwarescore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677930252305327 X-GMAIL-MSGID: 1779869388998571401 This patch implements built-in trait for std::is_scalar. 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. 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 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b161c9b2c9e..78f100d2745 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SIGNED: inform (loc, " %qT is not a signed type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b0faa4c8937..08a2780c929 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5e6b2ca37ac..be345f9aa47 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_SIGNED: return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; @@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); From patchwork Mon Oct 16 00:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 153107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3159854vqb; Sun, 15 Oct 2023 17:26:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3CzxpmtdCegqIGgUrpIlsPeEEb6rV0D4Myfn+Eu07SH4RVyGF0kmJM0iGygE70s9ruHbp X-Received: by 2002:a05:620a:5583:b0:76e:faf1:5e2c with SMTP id vq3-20020a05620a558300b0076efaf15e2cmr31253364qkn.45.1697415965258; Sun, 15 Oct 2023 17:26:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697415965; cv=pass; d=google.com; s=arc-20160816; b=D1Sit56H5rBZQQloaQQSiR0C4pAmqV3WeOJYAhUz/sELYvYERiU0D7Hgq3/CTZJvgD 9Wt6pFmvkUOyyLVNG0ROpFP9Y7FZ3Fo+wyMwoeTuafoVOJzR7SqP/E4GC3zpURkCkP5u nH4bKM/B1ACt6njlfZSUVaMThE4f98kNHTOERaig6yN+wFZ014UJFMgEQU2QOL2ykSdC HLnOTKdoTNVbexylTiR5kpg7z01WeSgvWuj+ShwR1xjxgdnz/9p558Z88MnaCVk5hywT stw7S1pWlkxAW3hiUCNaT7YpzlDtSCzCzZzPNGETdF02JuPeaTiORdkTq4/xR5QLTdDy SeuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=B0SbMaqpfoYuXFvpmV0bAByOLiNHLbGJ9uwf+FsdTXOqMC/aRCFxyNgLZuAVIyhHoe lahynSUk5DmvHLtMXHdUlPiGBlgRomskcgp9+vQGcZXbPywvTOcYFuUf5uWOF8M+KBlh XDv7gQRZ8VjAoW79nLls5XHeIyC3bpeanp4IkNfZoWjwbJOsnFWWe0Hwu4p4q1X77BpJ 4sXVXAhQ3T2fNVp9J/mxJdR619v1bioONkTu6nbEfVjT8aP+QXRthP+0d1TzptrHi9zF Cdqfyrf1LQY6kyOWMqqCT9sotXpxoGvQsXNsFd8qWjod7GFT52zfYvjlmx9Tp2l9P40i Cyxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uy6KqcK4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q18-20020a05620a025200b0076cf3531349si2243155qkn.760.2023.10.15.17.26.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 17:26:05 -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=uy6KqcK4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01AA4385842A for ; Mon, 16 Oct 2023 00:26:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01AA4385842A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697415965; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uy6KqcK4cp2ob+HFyyxapmAFcvlh6ILxlJkh2clCSKQcNTKsQA/gVxb/srViCMQ6Q NvUHaTrVtEkNXgfLoylZTjFWwz3Xw8CuNp7zcL2rroi0X8ve6bnGwRh0B1RJlMzNQa yegkolHPet6g2iQ3dvMZ21dZ/15rxtrzka7mOVa8= 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 C8ACB3857016; Mon, 16 Oct 2023 00:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8ACB3857016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8ACB3857016 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; cv=none; b=YL8zibAi9JiFXZUvXtmlfNMHP9xSosfBLHkhyJDniYgOjcbAfGJLVfRfKj/GtqPqHf0HEYs0IgjfHwo7TiShGqCb9GDRjsRfxuGaDYTPXaLv13q1mp9k025Bw4LGsCAxL6iwaQtHm70V/dKEBYQdido0Uy+qHnvwhsAvFpNIxIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697415287; c=relaxed/simple; bh=yZDHLGphd8jxjnk42PZPq1zND4PhrwWhUcJ7anaWSLE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lCnM5iAwejTG+bE+L5sG1cYbxSKcTEifnODCNUcS3BRfhLOYyauTETyfKgvn/7jEhIkpudhoi/gWo0ejd5ODFw4zIvAZenMY8PIPEC4o5v8hBtWoZq64szRr9VYbEMTjLj/q8jQSG1ITxpx4/hTKVWGj2mE5oVb2g/zLhKBgn5w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39G0CTT0012279; Mon, 16 Oct 2023 00:14:45 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tr4kq4d32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Oct 2023 00:14:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39G0EGIT016537 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 17:14:16 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39G0CSsU032329 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 17:14:16 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v20 40/40] libstdc++: Optimize is_scalar trait performance Date: Sun, 15 Oct 2023 17:10:24 -0700 Message-ID: <20231016001227.2717180-41-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Akwm3DZYGQj0UxfHgTrwXAxjuA87QpLJ X-Proofpoint-GUID: Akwm3DZYGQj0UxfHgTrwXAxjuA87QpLJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-15_09,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=671 priorityscore=1501 impostorscore=0 clxscore=1034 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310160000 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997480812710190 X-GMAIL-MSGID: 1779869643373648657 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>;