From patchwork Wed Oct 11 21:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp835748vqb; Wed, 11 Oct 2023 14:53:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbNEN02xjowYis9VrOx9f+lKWvN6gklYMjhoJZEOWftywYCZOnNJccaSDbkgYLLlbKa2bL X-Received: by 2002:a17:906:32cb:b0:9b2:abda:2543 with SMTP id k11-20020a17090632cb00b009b2abda2543mr19336881ejk.65.1697061195012; Wed, 11 Oct 2023 14:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061194; cv=none; d=google.com; s=arc-20160816; b=YqTFSFwVn0yhOB8XbibcjxDQ6/Wq7eYDRzNKaYf57gTB9of+9ubmrx4QO/yi9TM8rY +adoe18rvNn+XmZ4VtPfQMMqp5/bo+d7nGcgn03wWvikS8Ji7dFAk1C0g3tRhxh/0P6w Bxe8qtdIKUuy9IZ43GVrfOvUzZ7d2tnz51DuENdvxN73o2uo4PInKJXFAUerZArvpZJj RNUqdCVh+jzOAzPqL467ETnt/ND6X++MCPM6KKYw94och3gLgAB6LnVKbp7xPpAquUQr 2XqibCur3iZ5M10D90TkGQmJaA45M4LM6lZJtteBQQZRR5dXjJOFFXYUS5o/qCKcRcpx g0aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MKW1Ac2+4canAboK7rFTyrtkRq5Md4dhsl2QPGign68=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=oTBRrEwYlRp0TlUWif87pi+X70gGyRKCZeJP2XCqBEA/Ma4bBSAsAW0Xh1bNZIdT0Q ZT5/KPkWwEO5bHstt3mswfgY8lFZY+uKVv7/KmLUfFCCYtlkKc5DSErDUJ1tyro4q2Q4 5OukqjpJR7hWVOFY+WJ4DNK/27vfnWVwAMpBBE7vgUHS1nDVbw0lWrw9PcqvQYxtfSF2 BoQ8mmYRKloS7B4P53PaewIXHsIoAQVtA+J9PShibRR0/FhA5rDhHka0GCSZKfB/jJ9H AAwyoWzE/xxy3aW1xkUUHpYXY+wzUxT4ud0KkB3tqzYu8ttS6Y7O8c0UyaSsIHMmYzu2 e/Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EkuVczT0; 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 v5-20020a170906564500b009b27d4153d0si6544232ejr.104.2023.10.11.14.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:53:14 -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=EkuVczT0; 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 4E622385CC8B for ; Wed, 11 Oct 2023 21:52:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E622385CC8B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061141; 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=EkuVczT0ajfRyZE3k1kj/gce+YIuB+duuA1lrYJaiYWyH/n9mNKL9VY0mheFTK/dk 3K+WwfvRL+nKEqMAs0wdUp7AEC9u9fw3ZVzbtZh+deFS9V2lwRhCGL52DnyejtPr9L hR2mTDYR8WxqZsaI6S6+wujFaxy0sjqxvlFi5R/k= 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 6848B38560A7; Wed, 11 Oct 2023 21:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6848B38560A7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLoXNN027442; Wed, 11 Oct 2023 21:51:32 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq8fb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:51:31 +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 39BLpS8W030200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:51:28 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq53021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:51:28 -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 v17 01/39] c++: Sort built-in traits alphabetically Date: Wed, 11 Oct 2023 14:45:37 -0700 Message-ID: <20231011215049.1052142-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: AgjnT3A46uuH0nldeXwZknFToAPpIyll X-Proofpoint-GUID: AgjnT3A46uuH0nldeXwZknFToAPpIyll X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779497639605776976 X-GMAIL-MSGID: 1779497639605776976 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 Wed Oct 11 21:45:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp836497vqb; Wed, 11 Oct 2023 14:55:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSHCtlN0hcuX2mKETqq5/bGyBal1vPQplRkSlDndIYOpAijuxJVGCNsG0z9Cwc+YHOfg/Y X-Received: by 2002:aa7:c393:0:b0:530:74ed:fc85 with SMTP id k19-20020aa7c393000000b0053074edfc85mr18662885edq.3.1697061317443; Wed, 11 Oct 2023 14:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061317; cv=none; d=google.com; s=arc-20160816; b=lBNudWVuur7VePzqOgHD0AYM4OV6g6kiEGt14WiB/LNqgBmyE6YDIGT7MXK9f+iXj4 lU/NbqVnVDiDf6A8u5D5V399IvVs1NKw4lfJBgCPX93zbMwuppdVI+oVc3+sOt/ZrXSO pDV1/YebXf/OD1DwFEdjztxgVrIBs4j0i3QBWVokN/25EHWjJQeGoDmYFxHwxDlXg3xK /EcWjvo1viYCdDCo+k49ADHOqfyKVPf8IlHz9xY59rYmG0MGPFG+jJ933AvYMrjX9OqB GjgcVOaf4kAlpn/mrYI6YBJx42emPH4CU0vCMOinFhj1sB95avmHG7Z/JU26Sg/bAj1Y As3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=yR4diYa7jMe/OevEaxtxRYWENy8AZwKcFM+BuIIMDuc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=V+oKfZrq4SBekJH6hRsi5m+6K0X2PY5eHxyunW8QTwjJhJC215im0G3PHucOMdl4KA lEIq52bfuH4xOjKPwmLCFqqy19rfGwOdYsM1x8dUkDDwdK/5Hoim7EJw30sXZq30dpry V+tfLCd9e0YHXY1MxKIjDIWAOkVo9C1z21q2fdW8mxuXCTXopusOkuw3kqN6YVwG+yWL ROcmg9lm6X2x+TP6oC5CaybhMHOfU9iuMGfnpWJFVcxtXGh36HI9duutPA61rb8qLCUR Wx59sFxqeOPQdrNXR5Y0zAFH8Wkro1bXyNrtlNByOcOQTdBDJSiHPz8BALiilFY6osw2 O+WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OOFich66; 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 h7-20020a50ed87000000b0053defc8c164si674747edr.358.2023.10.11.14.55.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:55:17 -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=OOFich66; 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 B0D3D38319FE for ; Wed, 11 Oct 2023 21:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0D3D38319FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061216; bh=yR4diYa7jMe/OevEaxtxRYWENy8AZwKcFM+BuIIMDuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OOFich66Au1v5IQVhtaFnighx5lfUraU/0CAvYPnagaMnBUpx0304wNswuOAx29Yi tUMAnuWFp3zRAGsZao3g2s0o3FQ31JygB/P0iMgX4NTsPmAV1eGHKsoe9mLxSZ//0H Ucx9Ft8VTjkQyaECB96pNwfkFCEiky7nakv768qI= 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 6D61138582A9; Wed, 11 Oct 2023 21:52:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D61138582A9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLkv4Q032662; Wed, 11 Oct 2023 21:52:46 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyyqu1pg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:52:46 +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 39BLqMBk020310 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:52:22 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq54021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:52:22 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 02/39] c-family, c++: Look up built-in traits through gperf Date: Wed, 11 Oct 2023 14:45:38 -0700 Message-ID: <20231011215049.1052142-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: iW8VDBHOqOXa4NC4QU_9YlReUqAMBTsX X-Proofpoint-ORIG-GUID: iW8VDBHOqOXa4NC4QU_9YlReUqAMBTsX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1034 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779408747974559636 X-GMAIL-MSGID: 1779497768117774381 Since RID_MAX soon reaches 255 and all traits are used approximately once in a C++ translation unit, this patch instead uses only RID_TRAIT_EXPR and RID_TRAIT_TYPE for all traits and uses gperf to look up the specific trait. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Map all traits to RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. * c-common.h (enum rid): Remove all existing RID values for traits. Use RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. gcc/cp/ChangeLog: * Make-lang.in: Add targets to generate cp-trait.gperf and cp-trait.h. * cp-objcp-common.cc (names_builtin_p): Remove all existing RID values for traits. Use RID_TRAIT_EXPR and RID_TRAIT_TYPE instead. * parser.cc (cp_keyword_starts_decl_specifier_p): Likewise, for type-yielding traits. Use RID_TRAIT_TYPE instead. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Likewise, for expression-yielding traits. Use RID_TRAIT_EXPR instead. (cp_parser_trait): Look up traits through gperf instead of enum rid. * lex.cc (init_reswords): Make ridpointers for RID_TRAIT_EXPR and RID_TRAIT_TYPE empty, which do not have corresponding unique cannonical spellings. * cp-trait-head.in: New file. * cp-trait.gperf: New file. * cp-trait.h: New file. Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 12 +- gcc/c-family/c-common.h | 7 +- gcc/cp/Make-lang.in | 26 ++++ gcc/cp/cp-objcp-common.cc | 6 +- gcc/cp/cp-trait-head.in | 30 +++++ gcc/cp/cp-trait.gperf | 74 ++++++++++++ gcc/cp/cp-trait.h | 247 ++++++++++++++++++++++++++++++++++++++ gcc/cp/lex.cc | 5 + gcc/cp/parser.cc | 70 ++++------- 9 files changed, 419 insertions(+), 58 deletions(-) create mode 100644 gcc/cp/cp-trait-head.in create mode 100644 gcc/cp/cp-trait.gperf create mode 100644 gcc/cp/cp-trait.h diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..f219ccd29e5 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,12 +508,16 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, +#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ + { NAME, RID_TRAIT_EXPR, D_CXXONLY }, #include "cp/cp-trait.def" -#undef DEFTRAIT +#undef DEFTRAIT_EXPR /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, + { "__is_same_as", RID_TRAIT_EXPR, D_CXXONLY }, +#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ + { NAME, RID_TRAIT_TYPE, D_CXXONLY }, +#include "cp/cp-trait.def" +#undef DEFTRAIT_TYPE /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..a1a641f4175 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,10 +168,9 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT + /* C++ traits, defined in cp-trait.def. */ + RID_TRAIT_EXPR, + RID_TRAIT_TYPE, /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 2727fb7f8cc..a67d1c3e9f3 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -34,6 +34,8 @@ # - the compiler proper (eg: cc1plus) # - define the names for selecting the language in LANGUAGES. +AWK = @AWK@ + # Actual names to use when installing a native compiler. CXX_INSTALL_NAME := $(shell echo c++|sed '$(program_transform_name)') GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)') @@ -186,6 +188,30 @@ endif # This is the file that depends on the generated header file. cp/name-lookup.o: $(srcdir)/cp/std-name-hint.h +# We always need the dependency on the .gperf file +# because it itself is generated. +ifeq ($(ENABLE_MAINTAINER_RULES), true) +$(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf +else +$(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf +endif + gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h + +# The cp-trait.gperf file itself is generated from +# cp-trait-head.in and cp-trait.def files. +$(srcdir)/cp/cp-trait.gperf: $(srcdir)/cp/cp-trait-head.in $(srcdir)/cp/cp-trait.def + cat $< > $@ + $(AWK) -F', *' '/^DEFTRAIT_/ { \ + type = (index($$1, "DEFTRAIT_TYPE") != 0 ? "true" : "false"); \ + gsub(/DEFTRAIT_(EXPR|TYPE) \(/, "", $$1); \ + gsub(/\)/, "", $$3); \ + print $$2", CPTK_" $$1", "$$3", "type; \ + }' $(srcdir)/cp/cp-trait.def >> $@ + +# This is the file that depends on the generated header file. +cp/parser.o: $(srcdir)/cp/cp-trait.h + components_in_prev = "bfd opcodes binutils fixincludes gas gcc gmp mpfr mpc isl gold intl ld libbacktrace libcpp libcody libdecnumber libiberty libiberty-linker-plugin libiconv zlib lto-plugin libctf libsframe" components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc libbacktrace libphobos zlib libgomp libatomic" diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..c414d8f5a13 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -434,10 +434,8 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT + case RID_TRAIT_EXPR: + case RID_TRAIT_TYPE: return true; default: break; diff --git a/gcc/cp/cp-trait-head.in b/gcc/cp/cp-trait-head.in new file mode 100644 index 00000000000..9357eea1238 --- /dev/null +++ b/gcc/cp/cp-trait-head.in @@ -0,0 +1,30 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf new file mode 100644 index 00000000000..47e3c1af499 --- /dev/null +++ b/gcc/cp/cp-trait.gperf @@ -0,0 +1,74 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false +"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false +"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false +"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false +"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false +"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false +"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false +"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false +"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false +"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false +"__is_abstract", CPTK_IS_ABSTRACT, 1, false +"__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false +"__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_class", CPTK_IS_CLASS, 1, false +"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false +"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false +"__is_empty", CPTK_IS_EMPTY, 1, false +"__is_enum", CPTK_IS_ENUM, 1, false +"__is_final", CPTK_IS_FINAL, 1, false +"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false +"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false +"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false +"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false +"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false +"__is_pod", CPTK_IS_POD, 1, false +"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_same", CPTK_IS_SAME, 2, false +"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false +"__is_trivial", CPTK_IS_TRIVIAL, 1, false +"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false +"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false +"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_union", CPTK_IS_UNION, 1, false +"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false +"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false +"__remove_cv", CPTK_REMOVE_CV, 1, true +"__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true +"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true +"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true +"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false +"__bases", CPTK_BASES, 1, true +"__direct_bases", CPTK_DIRECT_BASES, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h new file mode 100644 index 00000000000..97ba8492d15 --- /dev/null +++ b/gcc/cp/cp-trait.h @@ -0,0 +1,247 @@ +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 4 "../../gcc/cp/cp-trait.gperf" + +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +#line 23 "../../gcc/cp/cp-trait.gperf" +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +/* maximum key range = 79, duplicates = 0 */ + +class cp_trait_lookup +{ +private: + static inline unsigned int hash (const char *str, size_t len); +public: + static const struct cp_trait *find (const char *str, size_t len); +}; + +inline unsigned int +cp_trait_lookup::hash (const char *str, size_t len) +{ + static const unsigned char asso_values[] = + { + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, + 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, + 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, + 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86 + }; + unsigned int hval = len; + + switch (hval) + { + default: + hval += asso_values[static_cast(str[7])]; + /*FALLTHROUGH*/ + case 7: + break; + } + return hval; +} + +const struct cp_trait * +cp_trait_lookup::find (const char *str, size_t len) +{ + enum + { + TOTAL_KEYWORDS = 45, + MIN_WORD_LENGTH = 7, + MAX_WORD_LENGTH = 37, + MIN_HASH_VALUE = 7, + MAX_HASH_VALUE = 85 + }; + + static const struct cp_trait wordlist[] = + { +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__bases", CPTK_BASES, 1, true}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + }; + + static const signed char lookup[] = + { + -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, + 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, + 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, + -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, + 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44 + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + unsigned int key = hash (str, len); + + if (key <= MAX_HASH_VALUE) + { + int index = lookup[key]; + + if (index >= 0) + { + const char *s = wordlist[index].name; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[index]; + } + } + } + return 0; +} diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..9eeb29adde5 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -260,6 +260,11 @@ init_reswords (void) set_identifier_kind (id, cik_keyword); } + /* RID_TRAIT_EXPR and RID_TRAIT_TYPE do not have + corresponding unique canonical spellings. */ + ridpointers [(int) RID_TRAIT_EXPR] = nullptr; + ridpointers [(int) RID_TRAIT_TYPE] = nullptr; + for (i = 0; i < NUM_INT_N_ENTS; i++) { char name[50]; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f3abae716fe..432c43400ab 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "contracts.h" #include "bitmap.h" #include "builtins.h" +#include "cp-trait.h" /* The lexer. */ @@ -1165,12 +1166,8 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) /* C++20 extensions. */ case RID_CONSTINIT: case RID_CONSTEVAL: - return true; - -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE + /* C++ type-yielding built-in traits, defined in cp-trait.def. */ + case RID_TRAIT_TYPE: return true; default: @@ -2854,7 +2851,7 @@ static void cp_parser_late_parsing_default_args static tree cp_parser_sizeof_operand (cp_parser *, enum rid); static cp_expr cp_parser_trait - (cp_parser *, enum rid); + (cp_parser *, tree); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6021,11 +6018,8 @@ cp_parser_primary_expression (cp_parser *parser, case RID_OFFSETOF: return cp_parser_builtin_offsetof (parser); -#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_EXPR - return cp_parser_trait (parser, token->keyword); + case RID_TRAIT_EXPR: + return cp_parser_trait (parser, token->u.value); // C++ concepts case RID_REQUIRES: @@ -11033,28 +11027,15 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, tree keyword) { - cp_trait_kind kind; - tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; + const char* keyword_str = IDENTIFIER_POINTER (keyword); + int keyword_len = IDENTIFIER_LENGTH (keyword); + const cp_trait* trait = cp_trait_lookup::find (keyword_str, keyword_len); - switch (keyword) - { -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: \ - kind = CPTK_##CODE; \ - binary = (ARITY == 2); \ - variadic = (ARITY == -1); \ - type = (TCC == tcc_type); \ - break; -#include "cp-trait.def" -#undef DEFTRAIT - default: - gcc_unreachable (); - } + tree type1, type2 = NULL_TREE; + bool binary = (trait->arity == 2); + bool variadic = (trait->arity == -1); /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11044,12 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) cp_lexer_consume_token (parser->lexer); matching_parens parens; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) cp_parser_require (parser, CPP_LESS, RT_LESS); else parens.require_open (parser); - if (kind == CPTK_IS_DEDUCIBLE) + if (trait->kind == CPTK_IS_DEDUCIBLE) { const cp_token* token = cp_lexer_peek_token (parser->lexer); type1 = cp_parser_id_expression (parser, @@ -11079,7 +11060,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /*optional_p=*/false); type1 = cp_parser_lookup_name_simple (parser, type1, token->location); } - else if (kind == CPTK_TYPE_PACK_ELEMENT) + else if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* __type_pack_element takes an expression as its first argument and uses template-id syntax instead of function call syntax (for consistency with Clang). We special case these properties of __type_pack_element @@ -11094,7 +11075,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type1 == error_mark_node) return error_mark_node; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); tree trailing = cp_parser_enclosed_template_argument_list (parser); @@ -11144,7 +11125,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) } location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* cp_parser_enclosed_template_argument_list above already took care of parsing the closing '>'. */; else @@ -11158,17 +11139,17 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /* Complete the trait expression, which may mean either processing the trait expr now or saving it for template instantiation. */ - switch (kind) + switch (trait->kind) { case CPTK_BASES: return cp_expr (finish_bases (type1, false), trait_loc); case CPTK_DIRECT_BASES: return cp_expr (finish_bases (type1, true), trait_loc); default: - if (type) - return finish_trait_type (kind, type1, type2, tf_warning_or_error); + if (trait->type) + return finish_trait_type (trait->kind, type1, type2, tf_warning_or_error); else - return finish_trait_expr (trait_loc, kind, type1, type2); + return finish_trait_expr (trait_loc, trait->kind, type1, type2); } } @@ -20081,11 +20062,8 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - type = cp_parser_trait (parser, token->keyword); + case RID_TRAIT_TYPE: + type = cp_parser_trait (parser, token->u.value); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, From patchwork Wed Oct 11 21:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp838069vqb; Wed, 11 Oct 2023 14:59:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFN2sItpvxsMrMntrX+RavyHgIcotvcAO/cO1DY3ew5kBlRRuTNH9JYLnQ66QeK0EfrtLZQ X-Received: by 2002:aa7:c998:0:b0:527:ab3f:4350 with SMTP id c24-20020aa7c998000000b00527ab3f4350mr19593467edt.38.1697061576544; Wed, 11 Oct 2023 14:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061576; cv=none; d=google.com; s=arc-20160816; b=pahTUcylu9RZ/YvYRryGCpQuQZbHerVnaYNlDRtjzxQ4QAsz43/fPvci1srfS8Jl+q kTM/1eQBYOpwc0/zVXd3F5ROheb2ciBsQmLpT4EDspw6KQppmDROWI74va2pTt9IJnHF 7c9jiY2Fwyyi7skLjK+dBmWvdRgLVCJQIBdc4SKhos69b8g8M3i0Pb6rpfveSWFHYMCa PHN9ruzDr9gwlf8zX+vFoj8b1dJknbNtSYY+3dy0bolmG2YfNRZalmp/6t7g4ljipzk7 ivRSGgnqPzAgzywur1PD4wanWemMw9h0LKOMXsi8U4lK+LhtB26W6nkF6OAYKNkXDDa2 YZEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=A+QpW2RW+MhQraNL0kHmj2hvnz/HJE31o+NReBlrjYg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=VnxIv5ViEfY1GrHDoawR/a/vfOu81k4MXhAZNaX0qXTvpDbA3V2zaw/5ka8dGuxq7b Hm6x/A1gmqvmUEJxmOI706C/cErddt99viqb+C6e7yMvSXTj0ZJ8IwP/44yEpjiFXm2F lZ7dfRP4Yge3kUnhRBo95fhKgqlo/S86gGxpSfapLicbJ3PY+tG5onRuanMwcevwKYcj jtAxGe6XBYPnLRtCY2/xmAbXXZlU/O18O2U8gdZ7LhyS9aNP3J/7MfQG9ko95mv0AF+C fjNTqWDFadQQb+2z2wxLYnXVfJEiNuH31W6dnrobXcb8pYVnNqBDpOwWXULOlNba4AA5 bzVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ytSCti0W; 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 w9-20020aa7dcc9000000b0053dd6152beasi1162302edu.200.2023.10.11.14.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ytSCti0W; 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 C80DB38618B8 for ; Wed, 11 Oct 2023 21:55:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C80DB38618B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061327; bh=A+QpW2RW+MhQraNL0kHmj2hvnz/HJE31o+NReBlrjYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ytSCti0WXTBQR+hvRz+UzZS58nrBPt/V2w5ZUBEtjigFMBfDQXUXirnnUhil4bR0y 4Xk2LRkg/4ekb8IqfgNsERyueQMuGCyu082yKNI8C1HxrSn6jnvUlwGA84BBfOK/iL fKCr7x++I0VbMrVXRP/SaMX6cxkPforp8frHg4no= 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 B3F7238323C8; Wed, 11 Oct 2023 21:53:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3F7238323C8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLo3h7024558; Wed, 11 Oct 2023 21:53:08 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2sm0r1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:53:08 +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 39BLqgJN030561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:52:42 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq55021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:52:42 -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 v17 03/39] c++: Implement __is_const built-in trait Date: Wed, 11 Oct 2023 14:45:39 -0700 Message-ID: <20231011215049.1052142-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: lqpnmp8Q-_RSwKr8fghKCca4AlDkdLhD X-Proofpoint-ORIG-GUID: lqpnmp8Q-_RSwKr8fghKCca4AlDkdLhD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 impostorscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1779498039532770822 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * Make-lang.in: Update key positions for gperf, based on automatically computed values. * cp-trait.def: Define __is_const. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/Make-lang.in | 2 +- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 202 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_const.C | 19 +++ 8 files changed, 135 insertions(+), 100 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index a67d1c3e9f3..7479e7dc00b 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -195,7 +195,7 @@ $(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf else $(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf endif - gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + gperf -o -C -E -k '6,8' -D -N 'find' -L C++ \ $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h # The cp-trait.gperf file itself is generated from diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 722fc334e6f..567dd35fe0a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47e3c1af499..47a5ec9ee6f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false +"__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false "__is_convertible", CPTK_IS_CONVERTIBLE, 2, false "__is_empty", CPTK_IS_EMPTY, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 97ba8492d15..c9005eee1ff 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -1,5 +1,5 @@ /* C++ code produced by gperf version 3.1 */ -/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ +/* Command-line: gperf -o -C -E -k 6,8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 79, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, - 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, - 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, - 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, + 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, + 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -104,6 +104,8 @@ cp_trait_lookup::hash (const char *str, size_t len) hval += asso_values[static_cast(str[7])]; /*FALLTHROUGH*/ case 7: + case 6: + hval += asso_values[static_cast(str[5])]; break; } return hval; @@ -114,116 +116,118 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 45, + TOTAL_KEYWORDS = 46, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 85 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, - 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, - 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, - -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, - 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, + 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, + 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, + -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, + 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, + -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 782aa515da0..23f1d1c249a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Wed Oct 11 21:45:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp837301vqb; Wed, 11 Oct 2023 14:57:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeaGmpqBNDXP82+ZTbcAJZz2yOUlS9UJ0yMsUV53os75ue+N8he5iD1ITlHTMt2Lm4eIAS X-Received: by 2002:a17:907:774d:b0:9a2:ecd:d963 with SMTP id kx13-20020a170907774d00b009a20ecdd963mr19903843ejc.44.1697061451565; Wed, 11 Oct 2023 14:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061451; cv=none; d=google.com; s=arc-20160816; b=ZQfKuET/cuzkUDTs3iKCx7V1B3C4Wkc5GboH5sMz3vbKp2ejw12BZ4NfCw5ST3cgaC xtiF0R9mlXDazx9yyA3woxvZsgj5jEqNPkQnVBkbwpna3jQX+BtcKUJlNWAVaJ0aJTAW aZKLtlr59C+DvK9Q9/B3gIByF5lFmw4KjFBpUAE/Tx5q10YK0sKzkj/LqSmIXRgEbL40 PJx7LPunbmyRQQOqo+QxWiE08ABv4K46nFSwNs/b7aIniCaTGB3skNk6Wj6JeClI8E+3 7iio44rUNXE5HOV9AL2RIqLekJ6dAv8Vn8kBkloPukcFWEENFoSnSLb1Ng6K7x32T7mV XOmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uTeMzdgrvjVD+t9jFUAjAyzikhYNsj2+OlzR1oee3YhvWTeaIiZt0MScUOIccNQyTl aGS5mAxNYdvdOGywBnyi9J5Ig8+vhFttBWdbuPkYifurdt7dUsBi2loalBTAAiu7bguf b2p1Yz0TaNbEqyY9FEXO8KVqRwjnGk3fwJYR1VAeRosPqaMsc01mDgpOfDJfX5wAp1cu 69mle5bqNBm5BtXDEaXUdmrHdMMoWgrLHxc7Xla7cJOlrjMcQ7Pihk3sjXBEyJYNNE8x ZoqJz+i4mnVDDudYGG0XhzTzRuwWxqwlRmtpJvDLAf4rqqTc9XSyUiUucP2le16+EYoj 9cbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xBCErTJG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y17-20020a1709064b1100b009b953b4b961si6497912eju.189.2023.10.11.14.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xBCErTJG; 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 1DFBA3885C3F for ; Wed, 11 Oct 2023 21:54:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DFBA3885C3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061271; 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=xBCErTJGne1m0ZJchN5D3Bgg3U3baBoI6ZEEu8m+hMwbdw+L7epkgNELJWCdVroGc 0ykdd449TMjahRAjtjXAuS+TCrZqO0s3R5J1Af1JpVFEL2XtWLqtjhJd7hC26yQ5zW hD1I5zRMmJBcH2+mmMrHx4NAteEDEVel6lO92LJI= 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 42BAF385CCB0; Wed, 11 Oct 2023 21:53:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42BAF385CCB0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLhmDd016078; Wed, 11 Oct 2023 21:53:36 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp3388p6t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:53:35 +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 39BLr4kR025320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:53:04 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq56021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:53:04 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 04/39] libstdc++: Optimize is_const trait performance Date: Wed, 11 Oct 2023 14:45:40 -0700 Message-ID: <20231011215049.1052142-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: AE26oUhrRCObwvKhfZHRPvnN1pyJx1-o X-Proofpoint-ORIG-GUID: AE26oUhrRCObwvKhfZHRPvnN1pyJx1-o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 mlxlogscore=837 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776995283749276021 X-GMAIL-MSGID: 1779497908441446879 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 Wed Oct 11 21:45:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp838489vqb; Wed, 11 Oct 2023 15:00:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjWpjEH0Vu6llQUMHdfz9aXqMwqpT9LAqIXbQSNrE3euYU5fvvCotlyJGekuiMECcygH3G X-Received: by 2002:a17:907:2cef:b0:9ae:3d17:d5d0 with SMTP id hz15-20020a1709072cef00b009ae3d17d5d0mr19151007ejc.31.1697061621571; Wed, 11 Oct 2023 15:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061621; cv=none; d=google.com; s=arc-20160816; b=UKazEKAZFL4TpMTfyLm5g+aNXd8gerYFIAcrdtZo71LYsBf/ebKT9zMVcjDkGqh9Sg US7qQSVPGnYBgFqNtVBij7lebYKkGcb0L7mxKXLKWo2tU3B78/gnmiQgIuGy0AB1haK4 kQogUVXd+OO+neEW9bCS/GS7vCQQj5Q4s7KJofdMpA2c4/wfcGQpzFPPeZ4E+DUKj9Vp rexFwd4RJhkNNwtVaqKg2+dPYKc0juvLQ9L+f7CsqO+bxsN71T0mVnTJn1n0bDtd31H4 jPes/C7Vf+LJWMm5gD1qRTFuet1D1SylFJw9wW5aRw6Vesz2PrmnUwtd0U0cepnqH/hF AVXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Klt9DR2CzNjQajtYyAj7JK1+2EREswkgQmszv0iGYwwli6xeJZv1NgYjzIqiXHYC4W RnAksoCfOeqGVL7Xrv3YirghZa+KWbOtdnkL4FqD/Bsus+77HGPIKjs/dW6YedyaHrfN ClcQUPLuTLfF64lejnClWMsVW5Kz24FWcb9/4CicUHvZNnteNodYT6CCj1CMsRe6kgHo 8ly1mM4l16lc6hVBzVtxuY6k+/l6V/q4zb95OJCUcvXkvQlceAgtT4jXYASFdWkLUDov Rg5OdeakhnCkfAG5SOXWHkOZEiMJImysYKaIe0fWTu+4eOw1dkxTUQE2RKiFqrsuFO6G B6Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tvqybkFR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e10-20020a170906248a00b009ad89a88a65si6538751ejb.282.2023.10.11.15.00.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:00:21 -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=tvqybkFR; 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 343FE38207F0 for ; Wed, 11 Oct 2023 21:55:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 343FE38207F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061351; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tvqybkFR0h+rb+BWp8GCq7aoHNLoDDTxZo75NWANvh/RUes2pG0ThS1DXqwLyFomt CJ13tbxX07fxkHuNddZrMwefFUQLuLtjT7gQEeVVujzXbHUxDyXV6jMrgB25/oBDqv hORFI1uXdsdPy4ya1HssrCAPMqlH4TT4XQMeZAPc= 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 7FB173881D37; Wed, 11 Oct 2023 21:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FB173881D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLmlZM029457; Wed, 11 Oct 2023 21:53:51 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp3388p9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:53:51 +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 39BLrLkI013664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:53:22 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq57021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:53:21 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 05/39] c++: Implement __is_volatile built-in trait Date: Wed, 11 Oct 2023 14:45:41 -0700 Message-ID: <20231011215049.1052142-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yGpBG_D0DPJopv5H382qHfuSZHaG5v00 X-Proofpoint-ORIG-GUID: yGpBG_D0DPJopv5H382qHfuSZHaG5v00 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 mlxlogscore=846 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996916785922643 X-GMAIL-MSGID: 1779498086668779511 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. * g++.dg/ext/is_volatile.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 38 +++++++++++++----------- gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_volatile.C | 19 ++++++++++++ 7 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 567dd35fe0a..f031e022541 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9e4e6d798a0..d786f47e60c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47a5ec9ee6f..ea7abda6c75 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c9005eee1ff..f462794d5db 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 46, + TOTAL_KEYWORDS = 47, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,27 +125,29 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 70 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, @@ -159,9 +161,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -215,19 +217,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, - 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, - 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, - -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, - 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, + 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, + 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, + -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 23f1d1c249a..73178540fbd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Wed Oct 11 21:45:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp838018vqb; Wed, 11 Oct 2023 14:59:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqVPjaXum9Zwr6Dh7nVoX7wHlMSr/FJIit1sSAlav99eu6UJbdQfSmu/jcvruXcn8V+aYn X-Received: by 2002:a17:906:cb:b0:9ae:4eb7:ae8b with SMTP id 11-20020a17090600cb00b009ae4eb7ae8bmr22480398eji.7.1697061569743; Wed, 11 Oct 2023 14:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061569; cv=none; d=google.com; s=arc-20160816; b=VEe6gcohzO+23cm72045ve+sTaY/89QXjqCdSaYw7KGQEv1WDcoLhy0bIv2pXqitqP 3OJnz94RxfSqUIKK1/Ga2XCniVRFEBtaawLiM9Bqop1h0VxnqNi09sXXmzYrRhZrmfNo bA4ZlH0aiBl5izX+tFCKGeRWr+u3tYWWyfG9YrCeye4rOnK4hD6lr0oa3NqVCPoJWFoQ 16ytayvHZeVTfhrUpEHQlUu4IGaQgIKYZzB4C2TQISXh8Fai2KTP1yWCIZkf6nxpyTtD ddeVklDkPvpWF2QwYm5WlHRFXeCiKmuHYfeXGXceZIw5w7lIVfw6a1CVyPegNOJMIa+z S0rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=RfYuu1IoyEOM1JnJEN3xgOr5cMmeWrDXimCJheigk1gP2N7+M2ovoLpFc1hLl6oFyw kO2ag2bFFUOhWTmcoSUO2v9NbhSbX9/oix1+DATnIEB7NlKdbNNwA/N9pqroqf/ubv5/ BezjbVJsbpvbvNQo8eDS98eO9QDlICX2CVZwVQhAy3IaNv2X+CBja9nAx4uNCboOVkh6 B6ERUclflc6vy5sydoiAbCPU35vUFJvZMyCipLS3tHHa9D/iMOawkAhc+EBP+mOGsOx7 kycmzou99mGgqWrqkEa3Bi/xq59gpYJTioTbMYHsGDIbCdGC4YX4b9MnrCVkLIAHK5Jx ozWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xtA4GeGf; 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 w22-20020aa7da56000000b00536177fb80csi7163301eds.596.2023.10.11.14.59.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xtA4GeGf; 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 AEDBF385C8B1 for ; Wed, 11 Oct 2023 21:55:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEDBF385C8B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061323; 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=xtA4GeGfGe0/Hlkkl0J04IflmFzG/sQI62jAsJnl6NTs5mskFrDjuKrgnqugC2JDs rYm5Ivtbfud0HsJnBBRQb7xpT/DTlpcoAXoWF3MAweyiGR2V4LqXIc2rC15qnLAau5 8Ho8j2/upsJgBxt7/E+e9vXF9/ta0DQyF1RDLgZw= 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 2B3593882ADF; Wed, 11 Oct 2023 21:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B3593882ADF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLqWMQ012870; Wed, 11 Oct 2023 21:54:26 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyyqu23c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:25 +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 39BLs6tJ020816 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54: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 39BLoq58021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:06 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 06/39] libstdc++: Optimize is_volatile trait performance Date: Wed, 11 Oct 2023 14:45:42 -0700 Message-ID: <20231011215049.1052142-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: QJRJc_EElGkR9pZbNTOuhwD7_IdOHpu8 X-Proofpoint-ORIG-GUID: QJRJc_EElGkR9pZbNTOuhwD7_IdOHpu8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1034 mlxlogscore=884 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1779498032516109714 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 Wed Oct 11 21:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp848044vqb; Wed, 11 Oct 2023 15:19:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQhxEZv3GxiZHnUpGPHTTiY0wML1kEHZqw949STKMmLxVqsPAfGUvLeuq2xH23FAwHiZGF X-Received: by 2002:a17:906:20d8:b0:9ad:e669:ff30 with SMTP id c24-20020a17090620d800b009ade669ff30mr19049143ejc.68.1697062780817; Wed, 11 Oct 2023 15:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062780; cv=none; d=google.com; s=arc-20160816; b=PhhnYLOyEs/SaC1e0ZrJA4w/+adgUwkVlr+5kZ3Ai5VdIylV2AmxUgGtn8Y58/PLcv /NjoC1bQ8hpC5o8KFW0LJDQIPdjhdWaY1w6Vrj44d95qBno/DWoAH046/BndAVLHZevM A6oBk2ejE1fp2WDzJ/SwPQKH8CRF1fqXsB9JGCLEdi/pwWq88Ffpmq72XUObZJYA94nD zIc5a2GZwg7XlgEOSu8Yl7chdg1+fKGSHcsZWrKNoOgspl7RY7BfhsDwJOkwlFK+WRRb 8jn70aDpr24AjQjeU8sPxfy/mnP9TNXXE8l7HUXAq/e4YQhzZhmNOvusLpOLrWBVoua6 islA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=0vKgv1CLUkqwaLnw1hoU83yVDgcLtCsk7KupKWVKvKpgqsuDj2lu06XLhAU8Zhu6CO EXtj4DGWRd5dFGhPpv2s2FodUM8VQJL1TWmKrCT3GiE7l7kGRF2pV0F0/X4w3npqb0oD UQJmNCGidVlbL8nbGM+xkMOKlwabmSh/pNjg6oAbZD8OiiQGj0LfV/iu8koLA3Ib7woB AKnBTttOcBSmgFuG97SSVEGAgnswrHJTMovA3fJkQJxHUu3Dya70YZE9XzJalJhQSpCl XY+NzMg+3buFS3DJUQu1KnRQ0vhfkFO0sK3fe0CjF9kigfl+273Q3z6fzvVcFJQTOl0/ YnYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YivvS7UA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g11-20020a170906594b00b0098d52a2bc16si7246865ejr.438.2023.10.11.15.19.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:19:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YivvS7UA; 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 598EF38A8161 for ; Wed, 11 Oct 2023 22:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 598EF38A8161 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061695; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YivvS7UAcYP7bhNQ8T6VVhhNADQ/w5Kl+ONWrFyjxyxYL4kFwQ6qW1SCMxMCmjfkF uEyPdgGvBgVy5uC88i7bLjaLhgaAfgwEcJ9Knq4Qp4y1+4tjIDuaIOt1S/kFFuAY7p hHYLhdrzYA71LWvkPu+hKifGyhuUCN6GtfMeqsZI= 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 C7D1B3888C49; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7D1B3888C49 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsGKY004179; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq9bd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLshbf027591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq59021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:43 -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 v17 07/39] c++: Implement __is_array built-in trait Date: Wed, 11 Oct 2023 14:45:43 -0700 Message-ID: <20231011215049.1052142-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mZAE-JNK_uMwloWHKSu-c2qKBB6iKpQv X-Proofpoint-GUID: mZAE-JNK_uMwloWHKSu-c2qKBB6iKpQv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=828 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1779499302064295793 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 148 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_array.C | 28 +++++ 7 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f031e022541..5e30a4a907a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARRAY: + inform (loc, " %qT is not an array", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index ea7abda6c75..fb162cac164 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f462794d5db..526e63dec42 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, - 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, - 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, + 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, + 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,108 +116,110 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 47, + TOTAL_KEYWORDS = 48, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -226,10 +228,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, - 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, - -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, + -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, + 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 47 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 73178540fbd..e1358afcb3f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Wed Oct 11 21:45:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp842302vqb; Wed, 11 Oct 2023 15:06:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvp78IbEQk8o0ZbjikT4V1FLc+BV1sKUm3ZLm0Ot754n8Wp+wWFrB+3919FR5PbwnYppix X-Received: by 2002:a05:6402:2813:b0:535:cbe5:a039 with SMTP id h19-20020a056402281300b00535cbe5a039mr18458672ede.12.1697061988872; Wed, 11 Oct 2023 15:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061988; cv=none; d=google.com; s=arc-20160816; b=gsNG7Ozzh7em70xBVbTWzBatIlv6brmKxp03kC8NLmcvhrnedKqvog/uVHkHG7O9Pt FuBSxAaRsuXhyrmbrUVCv27h28TFLiCkY/bGo5nu4spEBOwFtzZeW/cP12hCdk5fzd57 cXtm6u+1/dpkwtHoxwH4/z1n6+fOW+y8r2oPgb0QVH3BlqH5PKahuT+D8LYtxA9/yMee AagFz1ZS3zuM06vuhHr91h6HpXordPPPHFR9R53xo8trYLJupI6VIMNCcov2dVge4g2l I2uxIeyxWN7eMfzQbpVt/1eyFM/tk6eg/nNgSvLR88vO478u+E6DT4VkpiMkvDGivOyk PO+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jxVU+vFCEcmaTmJDzIJI5kzX+drBiE+t0JAosiQlTXhpC4+Le5l0i4lc4MbfH/Komc JT7CBaaBBPEv8YGJKfJlv3waCnncHQch/7u3gBfl8Q4UrC9GjM657eBuBlzMESdCkyoq r/UpVzLp/HzeobxEEX6Zvm66dqCW5eA7YYQNgXA3CmBfE43wGaP/IFICyjfursjjg3CA zggkXAQUxlbiQNO3RjuLHtWf2lWYGSwUoKuZyj2d5hM2zKCePy7L4jBxIT/mhQeW3D57 WVp0xgZ22SMZJmtiTLnWDfD/SobBqjc+LO45sOVaakueouad3k7lRKfiPUCGk5wM4e36 oE7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AHpM97Pv; 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 d21-20020aa7d695000000b0053d9fd52d0bsi1838349edr.169.2023.10.11.15.06.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:06: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=AHpM97Pv; 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 586D4395B06E for ; Wed, 11 Oct 2023 21:58:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 586D4395B06E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061480; 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=AHpM97PvIEjXIyTOcxtvsEzxeDDZ6UKC04pi3CJcRTAWJsoFmPhMHbRhHKWxnXg9Z oJ8WiHIBrrI2FoS+DVmyjBT23gm/jIFtuM2Wap3KypCIo36NXBoGPT7+eYKXMyhBFK ZA88pHmHHpdmbzq8ehDRuhtUSPpAgBZeJNNdfx48= 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 B4698388E816; Wed, 11 Oct 2023 21:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4698388E816 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLs1Uf013194; Wed, 11 Oct 2023 21:54:56 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2hws146-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:56 +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 39BLsiFV013998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5A021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:43 -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 v17 08/39] libstdc++: Optimize is_array trait performance Date: Wed, 11 Oct 2023 14:45:44 -0700 Message-ID: <20231011215049.1052142-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Lf8eQKgCD8KHt2Azejdh4uAMjmhcL2Xk X-Proofpoint-ORIG-GUID: Lf8eQKgCD8KHt2Azejdh4uAMjmhcL2Xk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 clxscore=1034 mlxlogscore=474 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776997263374731491 X-GMAIL-MSGID: 1779498471586067008 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 Wed Oct 11 21:45: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: 151595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp849536vqb; Wed, 11 Oct 2023 15:23:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX+dVgnp7pYxkVVI4V+JlYfRNlRppLSnymn00gfXUOPxn/IIZq0vvmsqICbTn9ps2qk0P7 X-Received: by 2002:a17:906:3e52:b0:994:555a:e49f with SMTP id t18-20020a1709063e5200b00994555ae49fmr21890135eji.31.1697062999883; Wed, 11 Oct 2023 15:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062999; cv=none; d=google.com; s=arc-20160816; b=L2Z5EbNQuCLlDIkfq2DOR6ehPztegsRTQgS1ZUK874AE3F6avOfkPYAve9ehRS4oco AMXChG9F7fxc9BvO220Nl3mJtKMPcMzJnA6w5eKuUWFYR62NfsSvFj+bX63tJsAZjI07 TCZDoJxcju9IyrQcso7A2GY6voc0sAjjxWU/BuvwZ+XXi708HEIvZ9512JvBDAiAMzrc lEt2EXDy5vHqrnraw74RmG/9DyHn0q/jXHpONKHQaUe7pa0PcjSK35dWuHhtykY9pLay OEG+W6wBfnf9qemZU6UFFtuyC5UvwKtxL3vpY48NLg9J/q6/tO7yY+9TR2hAj0Esv7Nu 6quA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Xa+RrTBopkODmZBidTC+iTgG1Plng3sbDwFOpblIC/nE1D7m7hkL5Lno8N9fNl9G0B vLAaMK/wT60EmzbrcCVQyp5+1zLzV4mtRQm3lWv10E2MTFlVAzezziC+Wv7JIg1LnsFu L5jhG/Foa6K4WmKw8kCw5/1g5x7wDVchk+RVvO5gGG9SWZw/vWH8CUNA86CkbHq0JVD9 oXLhb9YLGufFSF3gtisty8lIeiwNuxHWoanJUuzp3wsbGmgnClBoYMSRoDifxesjBGh7 3o/WGCmOmr6DFjO4gTZHjP+1IEKvEQXJ888kD9RfIlTvc9CXp6xGxmB3yq5pz8WNS3BT /57g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f15L0eOW; 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 k25-20020a1709065fd900b0097394940619si6549450ejv.984.2023.10.11.15.23.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=f15L0eOW; 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 BA6843943418 for ; Wed, 11 Oct 2023 22:02:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA6843943418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061767; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=f15L0eOWR43wbryCSjxtTrFFt42qrewYvIIhTI8kFbm72rhlSXpAPo6LlN+yiQdKW W9ls5IG6VFuY9HBiAS3JeiZ9jnzrAUFHeon4HdPZuQ4j06n5PELPG50aqeJSR76v/r bNcBqAHcvWaxcN1pNRjhNZflZb3JY8VQE9unVquY= 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 3695C3820559; Wed, 11 Oct 2023 21:55:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3695C3820559 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLofFw021211; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyjvu899-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:59 +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 39BLsif4027593 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5B021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 09/39] c++: Implement __is_unbounded_array built-in trait Date: Wed, 11 Oct 2023 14:45:45 -0700 Message-ID: <20231011215049.1052142-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: l1Eczq_sG3kbDCrvCJHXSKQqu_PF3GmY X-Proofpoint-ORIG-GUID: l1Eczq_sG3kbDCrvCJHXSKQqu_PF3GmY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 malwarescore=0 suspectscore=0 clxscore=1034 adultscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=650 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110191 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997094718165190 X-GMAIL-MSGID: 1779499532004821049 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 42 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 ++++++++++++++++ 7 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5e30a4a907a..751ac61b25a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index fb162cac164..a894fc8c74c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 526e63dec42..47060ffbbef 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 48, + TOTAL_KEYWORDS = 49, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,30 +125,32 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" @@ -161,9 +163,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -219,21 +221,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, - 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, - -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, - 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, + 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, + 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 47 + -1, -1, -1, 48 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e1358afcb3f..0a2699be476 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Wed Oct 11 21:45: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: 151581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp842717vqb; Wed, 11 Oct 2023 15:07:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvtlcHVLSyi1UNaVu7927s2LJuk0Hr4mdCkV9L0JPzHO8vzS4DKYeNeC5acm2GFVJcPT4h X-Received: by 2002:a17:907:7711:b0:9b2:a96c:9290 with SMTP id kw17-20020a170907771100b009b2a96c9290mr19761814ejc.33.1697062028119; Wed, 11 Oct 2023 15:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062028; cv=none; d=google.com; s=arc-20160816; b=vMkYlXWg8TYIHRGGf62c01c6ZGDz01Wtno/AFCMgkO5okjAF6ZTYg7Q89oGu6bZxAr +NSyWIXdDOE39Mt7hMeJ8teGiBJlozkvU0dmnHVUgopDSi9dUCnOIaQOU3eX5L0E+IqO CgewHXjcz6KVh4rCWwrYZU5jb8BslWn7OXe02egnjiiqe7syEMFK6C3EkDBcbeYVzDry VlZIseN+mwHperfm+brpf4tio4bc0uIsThumXSRs38zNMUGgYjtXCwyt/mlviZ0HZo1X F1/0N4IKUmPfiWqM5q+XaULAA+FtKgGcoNcI5++e8Cz+OBl5IqQn8bn2QMZwNBzKZFe+ Ddsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=sxCJqfespQOphCWXjnxqhjN/DxS7yIoW99hLM9RrR45RLhs1dqkZRIEM0GpKxHfq0u rLFnBnzIpXAM3ZycA3/fXQG6bFvWUIrNSXGpbAbhsmcz32zPtTofOe8TSjfhB/pcGK7V ZhkAxECxUezFkpbLu+Sz0io7EVNvAMKNhN/XyyeXDdQPbvFq1lEQocwxwfUWbLTfp/uU RNFlll7s4t9SRj0usAwWAImCc7QO8raaJ1D5WXm07SvjrE1RB3t33hnd5KVBcV+OHGCg dl6DSsSmfRVZlav+xwtAn1ejTMFYO8aQTlWFk19FOso+5fb0zjjnzYLCNWwihOZgo6qR kGOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UEfJT3td; 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 g20-20020a1709064e5400b0099bd53a0d3csi6761114ejw.178.2023.10.11.15.07.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:07: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=UEfJT3td; 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 2F0923887F64 for ; Wed, 11 Oct 2023 21:58:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F0923887F64 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061490; 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=UEfJT3tdCJfdwSnWilNaasAvXpc3h7xrecFLnkI0T90Z4bNpC/gYjsWp0z1B6VEGQ 8wxFLRAyetoH7DimG+6/bFr1I4gX/iV6lLSUUr03Q8irlwT2DbSjGbf8fZVhIcIbz7 o0RmeCNfNUN79JWinLpN3vrW1OqC7hN1Jr0/SJjU= 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 A9E1538207E5; Wed, 11 Oct 2023 21:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9E1538207E5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLnm0r029119; Wed, 11 Oct 2023 21:54:56 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnv34djc5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:56 +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 39BLsiuX013999 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5C021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 10/39] libstdc++: Optimize is_unbounded_array trait performance Date: Wed, 11 Oct 2023 14:45:46 -0700 Message-ID: <20231011215049.1052142-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iOYNf3qsstBCADHc49skStuYwST8Nvdk X-Proofpoint-GUID: iOYNf3qsstBCADHc49skStuYwST8Nvdk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=505 mlxscore=0 spamscore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776996817880022434 X-GMAIL-MSGID: 1779498513060324856 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 Wed Oct 11 21:45: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: 151587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp847618vqb; Wed, 11 Oct 2023 15:18:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGu115fHFw9/SIR36hsGw6JY0hTg+MhCL2uSOUt6H3hMJ05yo6cv113Uo1mZ6RgPOTmcJah X-Received: by 2002:a17:906:10a:b0:9ae:3e2f:4d00 with SMTP id 10-20020a170906010a00b009ae3e2f4d00mr23961723eje.70.1697062714951; Wed, 11 Oct 2023 15:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062714; cv=none; d=google.com; s=arc-20160816; b=E3TvVxaIovO+iBT0Fl0iLRufvTUPFoZ1fk37k7KSojDIUlYi/Y56mPLM7xeydPIxlG W2ljKsTSpmSeYfkq1vbKJjrCjdv/8ywOqSSnxHHRDJKRk5a6sOcsOnyPwHm6bwGzH4Bd DA2V9UPzjkScAyBQIFcHqe/W7PljErciog4+/rUhwFwrCKiO/TH55QfPilimGOBWY/FM llGOKpDHJvGxTxsAmbsSy8czL0rs5KEpeJLZdHEAG2qEhOrsK9Cy/XSpQmQLT9ZilYek fhr7CznaTE5Aed4qd8HhSu+Wv0ZSszB5mGZeQjIjMwyLwRjNAiLrvN+14wD13K/jyoE2 eBAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=EYCfF9fQ2DfoHkhV4v4K3oFfJKg0pFVG/7KrkP1IhXDQrP35ZoihJUQrA1Sws47m1S FLDTfPSQ8B9ZTjuzrAH/tlFLJ97nf0M+E15TZMJ2jnMvmMHY+Q9MnK4xwSi0zK97bMCn w4GRkTpn3pykXx22ZwTLVcm8hXRc5ZfWWVAXbC0wUHeYMiucz2dQ3ntS1vc9kGgqOF3M tMT2/1fUE1saCAnuE8DKn8s9x0E2YjuIGTd2Nvq6ukkOiinFUnTyl+fVTwzus3ph/F9x 7WIOyAm+fi1wmU0Qcq7ExT/fcyjlRl8K3NSEoZ/W5Rqu60Rwb6s1Gk2JJoVENmJqJxRs TIEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pRERk1Gs; 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 r12-20020a170906350c00b009a1b305102fsi6917415eja.78.2023.10.11.15.18.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:18: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=pRERk1Gs; 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 A59FA3875DE8 for ; Wed, 11 Oct 2023 22:01:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A59FA3875DE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061676; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=pRERk1GsuMn1Qs/0q4OY0N4qpVUqtB7C2z0AEQjBY7czeXtptqSkcv32o3a2hq2E3 KekInFu+n9uXGJEMrcipfrxgGf9y100AGvUnpXhxCg9fjmW08I3NqB6l6KEPwnL3YR 6qSbrGh/qTTaWp1PBeyg/8Q3bXTeIkVxzZYj+TGU= 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 D1D1238207F6; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1D1238207F6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLrE4E008876; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp3388pnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLsi0q027596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5D021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 11/39] c++: Implement __is_bounded_array built-in trait Date: Wed, 11 Oct 2023 14:45:47 -0700 Message-ID: <20231011215049.1052142-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: jcJ5QTPNgI_K1rpl42f-XJGg1yVafWgH X-Proofpoint-ORIG-GUID: jcJ5QTPNgI_K1rpl42f-XJGg1yVafWgH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 mlxlogscore=679 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1779499233430353595 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 86 +++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_bounded_array.C | 38 +++++++++ 7 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 751ac61b25a..d09252a56b6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index a894fc8c74c..90fcdc01de6 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false "__is_class", CPTK_IS_CLASS, 1, false "__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 47060ffbbef..f22a6e93618 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 49, + TOTAL_KEYWORDS = 50, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,54 +125,56 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -181,7 +183,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -191,27 +193,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, @@ -219,9 +221,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -230,12 +232,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, - 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, + 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, + 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 48 + -1, -1, -1, 49 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0a2699be476..32880754020 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Wed Oct 11 21:45: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: 151577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp840810vqb; Wed, 11 Oct 2023 15:03:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQPyjgqdNEQyFuachNniDPDx3T7B6HPA4glYFISQDvPAFGFKuIvLBKAiYslA+YoiCnicm0 X-Received: by 2002:a17:907:9802:b0:9ae:56ad:65a7 with SMTP id ji2-20020a170907980200b009ae56ad65a7mr23168055ejc.45.1697061827136; Wed, 11 Oct 2023 15:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061827; cv=none; d=google.com; s=arc-20160816; b=LEs/L9wRRtv1ccyz27tNlX8vqBYF/YJccYfqkAOPVLuMxVJ27kMqgAJDVZ4mzLTMzn 8cb6HHc0zjilBqa6LtIQggslngjNHyMfDqwNTV7AXn1Nb3ZeKbxLmasWMikZ6+rP3Zty RW5piAca5P3vC4KhhklFfAzfCzBP7RG5nx9kC5ZWjveIQCA2EdJH4EVMOVVk4JQMbhhu mkLgVXmomIpv7fvhxkcUSvKatTmeVRD8dLPnLFI1qDJWbItb77KnAKScxi7R7M8iQIO/ 5wEGTpRebAZwdg4RTP89faPBNs07RUg6fGXpUStqjRQzGJdo1pMTgW3GOwjaWd52USjT KkNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ClA5xQS4yHp4hHWYq0GhXEiiNRX2K6z0B+sEqbKH1kqUoH1arYb6bUqVBKmwJumXb2 e+wQeR6PI5TVHPgVHJSFe0+sRT4Ng+prANBy11uA8Ea+2uACZLl8t502ODhaJqq6CX2K qxPOmyMXMdI51kveGOuMCLHjYsAZaLck5i28XnckkCd65HRQfgcq66dvdPc6et7IezKu 4TZ9KVJ/tWiD4CTZ+rUe67733DlZR5OciXPvt4QMhg9w3qiE++1DxCxaMWxNAc59V78x 3QAey6qSfjJeO77picVo14rIjHytBWr6wzjgiaiWj/4sZrc5lDgAdHtPFs1Wc/c3NIWK oPgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=B5tuvfbt; 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 fi3-20020a170906da0300b0099bcd1fa5acsi6933183ejb.359.2023.10.11.15.03.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:03:47 -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=B5tuvfbt; 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 63223394D886 for ; Wed, 11 Oct 2023 21:57:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63223394D886 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061433; 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=B5tuvfbtRee4EmnBtdFnChacXzyKjqmMrUY1xm/ip5+sCgvn4Gzv3iZkoyJUfRutY 36+4SWNoXM10aQGjjDlSzisMWkzyumgVP+hpEg3X8Eg9DikmaoxigKsce/6QvTCLIZ UR6sbItPV3+9JLPkAY77iWPLRyP7XpvS9Rt7TkqU= 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 EC5583889E2B; Wed, 11 Oct 2023 21:54:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC5583889E2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLs2P8003866; Wed, 11 Oct 2023 21:54:46 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq99t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:46 +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 39BLsiR6031135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5E021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 12/39] libstdc++: Optimize is_bounded_array trait performance Date: Wed, 11 Oct 2023 14:45:48 -0700 Message-ID: <20231011215049.1052142-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ZsyiWAOuwej_xXWGRyhO_sg8LE1w7QIz X-Proofpoint-GUID: ZsyiWAOuwej_xXWGRyhO_sg8LE1w7QIz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=660 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1779498302861293451 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 Wed Oct 11 21:45: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: 151576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp839280vqb; Wed, 11 Oct 2023 15:01:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEblnpmRVcnW/ddeQkWGTnICSlwByla5pvryfaAF1DwtDRCIhF8lMumFHXWDe9aRN4SdZaH X-Received: by 2002:a17:907:8b8c:b0:9a9:f0e6:904e with SMTP id tb12-20020a1709078b8c00b009a9f0e6904emr16613914ejc.16.1697061689641; Wed, 11 Oct 2023 15:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061689; cv=none; d=google.com; s=arc-20160816; b=Fk9w5fLwIgnf5ZyBptLv0JCjzRs++liPPMV99tWTf/irTRUvPUrqm1fl9lQz0mxM45 DeqpRe0UIlPaTfNwMf4EzcGYBjyx853v39Ts9JLudA0/ao0UwIVX77nISOy0qsQC9+l9 KWQhzlzF3H0lnCbrC5sGLaMNUKvGhIC+ptV/4ct+bnb3UEGFZvlDZAH+RJgce49IHGNr KS9tSF1JI+n2h/8kn/C/kg8dm2D2v7pAE9/v4hHX0y3utZwKcl4bMmTEJe2x4KOajiYf NjGlX8bzLvMkfWpR8Xh2T3kzthrKD1YZY5XgQOA5npfkgG7ksEH0FV1MeiEUUoLIeFw3 rC/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=RnhAjGuqKnuMMQertamvXtDi3m3jjoNk+6HpXKLPnKMkXbutcHMVEVr9vpk19q7quv 4hvlBXO1fgAa0rnx1FtyO/IuOMpwtFC6S0/02aCxLIpw0XZHDrjyL/IhtCSNj5/+X+h8 1oxm3FGZw/pGeOq0+nPr6LhfNrWRKigD1y4C7/wvsZG6WG3sCXJ0/9TyW12/IW0ESc+S ghD/iKIfQNDSOQjCBd7WO3KkKCMbM9F1KewB5wkivGuEXPCvn6SOOBGNtnYRBlpNg+dh Fvzvb71jxguU9G0PbwdqnzZ7PiUYqI488u+Prc5zNHPNYKCapCWre/cgelceAlZk4gBS 33ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ntyQrQgD; 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 j24-20020a170906279800b009ae5788871asi6919460ejc.510.2023.10.11.15.01.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:01:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ntyQrQgD; 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 E11C938A817F for ; Wed, 11 Oct 2023 21:56:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E11C938A817F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061385; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ntyQrQgD3LBgXLlzyJxW7vytXMzKaeGx2e+d3AYX+tLdmESZcjzB+jStVwaEn5D6d iMymrK+4xa7SALhFiBzD8VhhslOMPL0Gt4rJSyN9Q2mgocs6vbAl6JYkGlrgiMJODH qSQn/Am0agZJvAxWQTTTZeHYHNtau0Th1OuPAMrA= 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 11DE23889E30; Wed, 11 Oct 2023 21:54:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11DE23889E30 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLofGM025288; Wed, 11 Oct 2023 21:54:46 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2sm0rqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:46 +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 39BLsjGf031136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5F021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 13/39] c++: Implement __is_scoped_enum built-in trait Date: Wed, 11 Oct 2023 14:45:49 -0700 Message-ID: <20231011215049.1052142-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hfybgLe43lESBQWhrGbuyw6aXhycmHv2 X-Proofpoint-ORIG-GUID: hfybgLe43lESBQWhrGbuyw6aXhycmHv2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=865 malwarescore=0 spamscore=0 adultscore=0 impostorscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1779498158012045932 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 161 +++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scoped_enum.C | 67 +++++++++ 7 files changed, 160 insertions(+), 80 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scoped_enum.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d09252a56b6..1c0b2e0f178 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3781,6 +3781,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCOPED_ENUM: + inform (loc, " %qT is not a scoped enum", t1); + break; case CPTK_IS_STD_LAYOUT: inform (loc, " %qT is not an standard layout type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6d6dff7a4c3..e0e3fe1d23f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90fcdc01de6..f3fd82ba549 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -59,6 +59,7 @@ struct cp_trait { "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f22a6e93618..9c18165eb68 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, - 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, - 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, + 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, + 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, + 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,56 +116,60 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 50, + TOTAL_KEYWORDS = 51, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -173,22 +177,18 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" @@ -197,47 +197,48 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, - 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 49 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, + 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, + 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, + -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, + 50 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 32880754020..f56ab031d5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Wed Oct 11 21:45: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: 151599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp850511vqb; Wed, 11 Oct 2023 15:25:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnsjgsHStUwaMn5UPkHQBU/NLCNG1/V8et/xFdkz5CG/8qBY/xEiiCmLvj21+eQIYSs68C X-Received: by 2002:a50:d0d4:0:b0:53d:a17a:7576 with SMTP id g20-20020a50d0d4000000b0053da17a7576mr5671178edf.8.1697063154085; Wed, 11 Oct 2023 15:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063154; cv=none; d=google.com; s=arc-20160816; b=upsYgLsCLQgxKcTvY2ALaVhB4K76YWlaP3KhRzhiD3oj4Aa+4ka7GHhAGrPjie0oN0 T6IYWw6x+Zm6hPQ7S8kJQJdslGFzazw5jI2rq7S17LD4ccpMhSjMVKpO6+hToAmNfYI8 V42bixw9B99K+RjIQfEzcMRjqisbIJQpKXWuTUuofPnf4AwY/XinT/hwUt/+qufR3oFd 2rfq0nZqmu6+An3mES00owl2nHQoQriWQgNZmLOWItbecnJnC2+kIRqqDDoxXsoRsUC/ l4JFxksUVSj8IqmklCZbWKxEcznRNaEnjL6gyFQV+Upq93iDHidAAErD/S5iKLjJnAuA gKKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=pFis6ofOgnVSDOMtJRZQPt10hHE3Ut/WEkW43W7QJK44I6GUT1g74gatejmi5+o2YF 1a7fCLBD8yNav5W+UxYe3f1bBTkcEZKlveZpC/S2GcbujJXHtYDwj6R0PI1YW9ipI1Z4 mGlua11XnZHBHSb7TuwzRo22sNPFnWGOFUjw1cfw/xVjH7cfBh7ssJxZY7SYbfpXaVqH cvp590Q9PWu8j5Nsg9gGKu77e0XVFxGwN+t5Qvo+gju9ychrWlFJ+l/3vL3r78hDsl3j z7nm2FVENGYNWy5C8jr3So5Yl/rqzkwdpCYsG19pbjocrQEyMrnysID2Ek6lZ+APF7l1 /Wlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=arT5ZClk; 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 o22-20020aa7c516000000b005223fbd4d87si6713988edq.503.2023.10.11.15.25.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:25: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=arT5ZClk; 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 0D8CC39D18CD for ; Wed, 11 Oct 2023 22:03:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D8CC39D18CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061826; 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=arT5ZClkYgQR3Ye+1abKI7RYhkAuvaqf8Wwipoz6sOE/nmwwvn9xVOxYwteFNIJWm FN9UvqRkLV40sgUVbHMw6tWSOoLx4FhoKjuZ8XIJpyiEtWkdPUvGZ6O/Q4kl5URadY PBAoWC+KzAstItjpD0X7PNb5UGeF26vo8vo7jVIM= 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 9529A385B532; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9529A385B532 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsi2v013297; Wed, 11 Oct 2023 21:55:01 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLsjsi025746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5G021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 14/39] libstdc++: Optimize is_scoped_enum trait performance Date: Wed, 11 Oct 2023 14:45:50 -0700 Message-ID: <20231011215049.1052142-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: gYZyoNdbjOSPffQwOIaPMDzqtG6ZZzKZ X-Proofpoint-GUID: gYZyoNdbjOSPffQwOIaPMDzqtG6ZZzKZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=890 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779499693797098671 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 Wed Oct 11 21:45: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: 151604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp851970vqb; Wed, 11 Oct 2023 15:29:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH29PjEcHRaHRIq2IWEw1MiAhDZI528CvX9CX3XxUEUhOiqK1/iPC6K6YrTJX6E/QeJAmSm X-Received: by 2002:a2e:9b55:0:b0:2bb:b528:87b1 with SMTP id o21-20020a2e9b55000000b002bbb52887b1mr19755138ljj.50.1697063390640; Wed, 11 Oct 2023 15:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063390; cv=none; d=google.com; s=arc-20160816; b=E+4X1pbqunJPBgS98lDB/GGxDpITGK5iKcxt/jbeZJ9zNas69hTLZaznwB6SdMyef8 ZdJTfZDVZA+XRKXIKmbj5ZzP2rPvta8kdMQQY12sAcmBnD8g7XL5VxM0ZEK1SUyYGlEd 1ahslQgwXNUwnYtxmWXVTHPTlraelwwKhjE5ZCO5EKBvaZqd3ih+7huqFuj2L4gZh2u7 zjgpPSGTD2GSGhyZVMUgZzbrYGChn/9q496t30IkoqO6wrjNl5mqPzLZYMiJHcBtK00e cgtLl4j5/28xq4c7rtIh1ZvIDPYeulx98GB4dKAgKFd3Fc7mSdPavAjX/0a4JTtSWjIu xHAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=akcbydKRHpkQZSHKEFqQL+cIv4iz7XgmeGK+tHaJgWQS8A/u4JEdYAfBl8EDdMrelq fC8kzvGGqMUOPmxor2HvAhyOFgDdEhRu29KFtg/U6j8zFxr6o9MQAdfkVYJgKr1/BRNr 8P0BJHe9J7x/cc4r5VrrwLOPBhLz8dMmPpRMTcuxDtCxMthxDNk9pD1pkkpL2FWmRWqv mWor/zlv//NvTsGs31ealmLkPme4pv+xZb122Yu4V/h3qMNovv0BmDKqqdcEq/WQov5g LL2LI7+xZHNfSr53kcD6+m1sNH6rrVFmlx7ZQNA17DZCJnMPIQiu2L8vAqCqXTN0jLAC c6Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lqNpY63M; 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 m5-20020a1709066d0500b0098dfdc3f2d9si6359660ejr.342.2023.10.11.15.29.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:29:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lqNpY63M; 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 AC2403954C55 for ; Wed, 11 Oct 2023 22:05:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC2403954C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061917; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lqNpY63M5n8hiL4pvaOZo8GwZeQIWmDLLqxe87GEi4SHJzY5zu9l6nIgHafbBQxdQ 1dy1Gy0c0UM2UP2toIc/Jw88bItv8SFF4l38DfwRv0zhIpJ3ZTDfmiAAYr86JjQO6V Atfn9jxkqluvtMY96KekMokumuNi8LznVdgvKfB8= 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 D865E38319E6; Wed, 11 Oct 2023 21:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D865E38319E6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsxNk013549; Wed, 11 Oct 2023 21:55:04 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyu4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:04 +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 39BLsjuL000641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5H021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 15/39] c++: Implement __is_member_pointer built-in trait Date: Wed, 11 Oct 2023 14:45:51 -0700 Message-ID: <20231011215049.1052142-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ueKwTP_h8grpBvXNGLMK79ZangDwL3MQ X-Proofpoint-GUID: ueKwTP_h8grpBvXNGLMK79ZangDwL3MQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=952 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1779499941507425773 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 153 ++++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_member_pointer.C | 30 ++++ 7 files changed, 120 insertions(+), 75 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 1c0b2e0f178..f0d3f89464c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_POINTER: + inform (loc, " %qT is not a member pointer", t1); + break; case CPTK_IS_NOTHROW_ASSIGNABLE: inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index f3fd82ba549..3775b11283d 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 9c18165eb68..dfd60cec6e6 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 111, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, - 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, - 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, - 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, + 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, + 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, + 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118 }; unsigned int hval = len; @@ -116,69 +116,67 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 51, + TOTAL_KEYWORDS = 52, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 117 }; static const struct cp_trait wordlist[] = { -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -187,58 +185,63 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, - 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, - 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, - -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, - 50 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, + 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, + 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, + 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, + -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, + 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 51 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index f56ab031d5f..6c4880d8a33 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Wed Oct 11 21:45: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: 151586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp846283vqb; Wed, 11 Oct 2023 15:15:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsB2WVM+Mbb8qYntW47PAhtc5g/lzS+NDZBuCB7Iz7QjzBSvBnBMEmwd9G0FP9fPQ3v52B X-Received: by 2002:a17:906:11:b0:9ba:13f1:5a67 with SMTP id 17-20020a170906001100b009ba13f15a67mr11363034eja.75.1697062528387; Wed, 11 Oct 2023 15:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062528; cv=none; d=google.com; s=arc-20160816; b=pYnAk9jRnZorwxjxqyaHQL/p5K3DvWeUoNLKpaQo52T2JXCfxT7bAjm33sFgo645fL pwix32ClPK3pNw+pOMOBjjC/T3zj5LoVJlJmZQqZKPdqSd/yQlVmKeWrXtpGBnONxHIp wmDYNZMHsfBhBCOiOPv35stQwdIvUTcLAZ+SSx/AldyDG6Ssw4hDLclMlwb6JokwH5u1 6oU2k6ytGiU+GWKTRYtv/QROMFt+Vo8sdG7YT9I4IAjoOXF9frr8/AE/px/u63FP/6Dm yBivTXe/BzJI3DeidFDDFJ/tsgciOwa/v4Ozqf6jzhqZuws1/6lCJDT1suS5qbl6p/+j qZhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=B8XYT27LWBnTx0DOokZpwCwZngVrw3KkC8iendD9X+OEtdk2/uvJqkTUy8lqvTAGzv HLI/fAwxxA92MpT1NpdZtq73jRzFxRvSl6swanGM3z6Z+sBI2L4nAqjnGu69C4Wr7z1R SDu4zW+LguoRKPbj5gYsKJpSZF4ZFddnKtklL/mVRO1wtqDJ0WgzoAJqlGJ4+O0RVf0B /vVcemAfq1o232mcbRMSMTKqIICz7IsAz5f8mHlrAgI5P71x1Y/nH00rBhSA7WdjCJ4u t8dpIR01Vq2COPGhD8+ZKq3j2ldkqhFoF8sC1bUCKjurULkRStRSWGMAGFvrE8gsbc+D B5Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=anDpk4kI; 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 i9-20020a170906264900b009a59b604305si6609635ejc.406.2023.10.11.15.15.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:15:28 -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=anDpk4kI; 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 8F109388733C for ; Wed, 11 Oct 2023 22:00:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F109388733C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061622; 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=anDpk4kIRItd/gXgh59yPOOGY6S6Rx5YBiefIJXXclI872CbRf8DPmAMC4XAvnyMv AEyA2HCBV/ZYn1KOpNchUWbLehYDgz96/H+SeG49yWLWZaScFeesnYtQ+cxOFHT4O7 QpZxe9zZx68nM8jQhMvs/N+eLb89pzGjIwJCzuiU= 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 D607538245BD; Wed, 11 Oct 2023 21:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D607538245BD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLdgP5001673; Wed, 11 Oct 2023 21:54:58 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyt9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLsj4F020898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5I021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 16/39] libstdc++: Optimize is_member_pointer trait performance Date: Wed, 11 Oct 2023 14:45:52 -0700 Message-ID: <20231011215049.1052142-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: e1IKyz-6WkNgPyEJttXAgiHkisWU9V5T X-Proofpoint-GUID: e1IKyz-6WkNgPyEJttXAgiHkisWU9V5T X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=580 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1776996307296308519 X-GMAIL-MSGID: 1779499037509758139 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 Wed Oct 11 21:45: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: 151579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp841363vqb; Wed, 11 Oct 2023 15:04:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV+bnybY0eeA3HYZQR9B7TdACOtpeMYSEUOXuOjWBNYBDEs7GJwaCxzsxx8ExWJtX1hqIQ X-Received: by 2002:aa7:dd0c:0:b0:538:15df:d12f with SMTP id i12-20020aa7dd0c000000b0053815dfd12fmr18808798edv.18.1697061883480; Wed, 11 Oct 2023 15:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061883; cv=none; d=google.com; s=arc-20160816; b=hXiWfuHXvnEV0YTY74CMkJ+3nkNANPR0KbtwQfQ6+WCzOgE6CbdVrB0lDu//7aJHBt Xu1vgL8HjUzUa4uAOcl5oMRNJox3dfNLzzAsprew/1D88FiBxyfnnBGFjdhPA8vyBHko ZInVLuf3aDBuZ+QegXCQ44sjU9UuxlQbz7rpT3gR76SH+NgmkUuPyzsBpnvIP3P6p845 oSuvfX9KOnSK+LeSSMuzGLnvvMDirLYGSOzs+TOOzoeefFn805GcaNy1UAKRALY99nU2 PF4rROQC7BNVNERn29ELquC+jQbDIuVr9syyVvJWolBWP4JTdWAhout/JMsbqW6oy9a/ Bang== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Ri82fNzY+pH4kKZxvCqFiPgpcseI0lEFU5Vm3koqTt5pbChWPR1pEt8sUXuyPFuQHt 1czuv5mLUcsWELVnRsNlDfZaM1mj200g08MpzpHAmacDqM6masON+v8ape/1+jtWCJMi 8DHtcMIAvAzfCp/6O+mO0BJeziwjN2DV8O46d4dFzq93i+tVHrVfyvWkvplOwvMbAjGT 5Rr1YbX0eDhyaCyRiPhNSAbLuJ6CIFFd/tsPYTz7b469bWFyQUzklyCOjC3deTNPLbth T2T6SJiYkSqcpt40O4XU2zqqgGVDp1EKR9Ukouh1tEa5VSbbVrkTsKEz3SxhYM96ncSK ct9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Km359HpB; 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 e23-20020a056402149700b00536031525dcsi6609035edv.308.2023.10.11.15.04.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:04: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=Km359HpB; 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 BDFD33952521 for ; Wed, 11 Oct 2023 21:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDFD33952521 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061450; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Km359HpB6n9sRHr6+SCan4l4mmOotwzqoII5xJA2m+R3mFVjF6Ldec3xwELYXccZE h9vcVKgRTmE0Z9gFaOi3FVB/50aLYKdkGsraU2UrfAH5dVwX8YFQEcd0O+AUVUkhJe V3xCFCMNnmJUHtxS3BWFI81fjuToYw9unLxikH0c= 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 968103821FCD; Wed, 11 Oct 2023 21:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 968103821FCD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLp0YG003721; Wed, 11 Oct 2023 21:54:56 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp3388pna-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:56 +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 39BLsjGS014002 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5J021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 17/39] c++: Implement __is_member_function_pointer built-in trait Date: Wed, 11 Oct 2023 14:45:53 -0700 Message-ID: <20231011215049.1052142-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: RPigWjdfBwmjz1qja5fO5-Nq6jLbZ44w X-Proofpoint-ORIG-GUID: RPigWjdfBwmjz1qja5fO5-Nq6jLbZ44w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 mlxlogscore=777 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1779498361539304113 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 176 +++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_function_pointer.C | 31 +++ 7 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f0d3f89464c..d0464dd4f6a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_FUNCTION_POINTER: + inform (loc, " %qT is not a member function pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 3775b11283d..b28efbab322 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index dfd60cec6e6..d3d4bdf9799 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 111, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, - 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, - 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, - 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, + 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, + 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, + 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -116,132 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 52, + TOTAL_KEYWORDS = 53, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 117 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 75 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false} +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, - 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, - 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, - 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, - -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, - 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 51 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, + -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, + -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c4880d8a33..4d521f87bbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Wed Oct 11 21:45: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: 151596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp849951vqb; Wed, 11 Oct 2023 15:24:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGg9er47GpN2HGPV1R2mJkfEY6Z3Oy+z8OIIJreRP3mH7N2iMjoLE3E9XGP2MB8y2rhsg7c X-Received: by 2002:a05:6402:42c9:b0:53e:df4:fe72 with SMTP id i9-20020a05640242c900b0053e0df4fe72mr45398edc.32.1697063065901; Wed, 11 Oct 2023 15:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063065; cv=none; d=google.com; s=arc-20160816; b=l8cMdXBpJADXyf/4VvZWK5FhiAyphAYNRnBf91NgZWpUI+Er5PIVNVBhekgjMZqW60 cSpuJV0IweBYiGGbbJZrjtbEwK36k5SaHTT5zdwXA6zRVAoCGcKIVn3pAQi9vVfrEYEX n173Ac0WZiZi5uXSiMV50D5q5D4iBvr9/dPXmRnqTxz5tMBe6f3X4Zb8OmK0huJrY97E iYdDGlHyWj1zH43OXqwKhpZc5KAC1qr5ptEFRpAJIdF/IFRre4id4AZ9w0pj3YDm2JSG eBvQ4VEt4voi1MWon/7CT5fzq8YSXCtVSs9sicwtrFQoW221V2KjCfQzf7AyT8d0ap6C 9pUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=AXAPwknW43y2pjLEKMDYqpQLA/PnLwEIkVG7QR9dmQaJX6EQIrzryRieGoJM8OfJu7 WKPE5s55ILtliumfFyOuCndBIlKA3tlxc1xLp1MV7yp07hkTGaM8ZL/73SJzgpuUgtXN zy8x9ZgzT5lHDluUztywWAntLG7pgoI/kHWqWHkYg6c6wZBYxoM6mHWo30c1fojnz8xz rE1rsUBhv92ZeKkQ8diveLFH8maaDqL4q4ukHIwxBm7rrc7UnLEpfH40VMtjKUam54aq sRxsdjoaBsaiRVfvBsU0P1sEAdgXipI/1+TOkVmwGGhuDL/PPpO+8KCZF/tYUaOlkTjA AB2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Nd8DmXdj; 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 f20-20020a056402005400b00534627acd6csi7006390edu.278.2023.10.11.15.24.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:24:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Nd8DmXdj; 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 715843948A4D for ; Wed, 11 Oct 2023 22:03:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 715843948A4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061794; 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=Nd8DmXdj1SsC55jvRFFoFO9cFSte6CgzFCftLEzSxZ5gvikH3zwa2vYGML0Lhczs0 3y+qH8jUwmEA650fWWVAWsg0NTbwryDm564rA3ACpoJA6ayxuKJYm9jGNEF/30M+6I uoVlSPZc+xWeBOMpCnT2O2MOn+pAdEqXiW/VRCks= 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 E0BF03889E30; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0BF03889E30 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLnwc7014322; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2jx90fk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLsjDM027605 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5K021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 18/39] libstdc++: Optimize is_member_function_pointer trait performance Date: Wed, 11 Oct 2023 14:45:54 -0700 Message-ID: <20231011215049.1052142-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: pd08R0kV8o-CFOA5cjt45Nr1UMKJILEE X-Proofpoint-GUID: pd08R0kV8o-CFOA5cjt45Nr1UMKJILEE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=542 adultscore=0 impostorscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1779499601576751294 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 Wed Oct 11 21:45: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: 151597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp850091vqb; Wed, 11 Oct 2023 15:24:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaJ4BDN30X92oqm9o3kup0ymPzib8CwCC2beK7U8pzx/iK/H5VcJpKL8xz6AyIB0p6VyDQ X-Received: by 2002:a17:906:13:b0:9ae:519f:8276 with SMTP id 19-20020a170906001300b009ae519f8276mr19032186eja.73.1697063085342; Wed, 11 Oct 2023 15:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063085; cv=none; d=google.com; s=arc-20160816; b=dXaTw2n5OMxcWRGFXWVBuBrvYTb0m0881xrixVqdNMqFk5Azo9xnixZSpcQhzEGTNC /C2Boxx3b4iE5TyLYoRfSROHazYHnl1cZyVRcWUyrEvb2vmq72Oxh2KNbuJACSRr6kF2 5mL37BynqAIJrhITxgskH3+CMkvAO23Ca7qL1efcc/VOcCQgsQrq4wStk2bC7lkHKLhA DeEEgVkvGJ7ENMwAHaMX4YcSk26g+m5AdubA0fbFLXuKqvyOXQoyK2zkXK8UaNlvX/ut o5Ic51u8ERmWELzKVNcKjNHNWWeBWx5AhzkFkMTLC9uDep6RRFbd3ZEdi+l2okZg1xAi uivA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=mOXkOgyb4+KDsYu1KHXeUOi2PFuDI5A8rSgwDUQPWvm9DmRkjouUkSm0lXFhR1yDpZ tTt79rE3E4B/X67z5fEGBKtrACwVfpdjGQvkU7+LZqlNfrJTtkAkzA6RhXdZA+ZkdpL+ L/MKaO24zCmL3moFVoknX2ozggP5BMRrFHfCaATJ6DX/fICWC2gCyGSGh77YxQF1visC n/o0HbiqhSms++3g2Yyzzf1x+hG0KQKERCg2tl8IeZzUt5GdQNScygx6mdevmFgic3km bJufbLVTqpUotnvsT64lzVWFx87uqhb7cmNNZo3UaOyG7NkHtKEBQ4X0N96HGftGtv44 W8xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KYp0zk93; 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 pk13-20020a170906d7ad00b009b56540b83csi6896611ejb.897.2023.10.11.15.24.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:24: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=KYp0zk93; 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 7D0803949087 for ; Wed, 11 Oct 2023 22:03:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D0803949087 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061802; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=KYp0zk939YXNQky7wb3GUIhcx6WJFFa2XitV7Dna2mJ0LrxIA4L9tDZy7Mek6nbxF /Vz/ZLNLcswulhZGNldyJ3bYjX6nZneRG747zgo/rEj/r/OuYzmYmLHciUQAnujkkS r5FsMOhbVSHVrml2XTcYFg7zaCtBK5BhwA+aEDHQ= 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 69BDC386C5AC; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 69BDC386C5AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLovOg009233; Wed, 11 Oct 2023 21:55:00 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnjfffch2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLsjXY025747 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5L021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 19/39] c++: Implement __is_member_object_pointer built-in trait Date: Wed, 11 Oct 2023 14:45:55 -0700 Message-ID: <20231011215049.1052142-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yWDeUt7xlpAe5BXVyxkcNN1QfQfQukNU X-Proofpoint-ORIG-GUID: yWDeUt7xlpAe5BXVyxkcNN1QfQfQukNU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1034 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1779499621719284040 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_object_pointer. * g++.dg/ext/is_member_object_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 62 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++ 7 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_object_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d0464dd4f6a..98b1f004a68 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3759,6 +3759,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_MEMBER_FUNCTION_POINTER: inform (loc, " %qT is not a member function pointer", t1); break; + case CPTK_IS_MEMBER_OBJECT_POINTER: + inform (loc, " %qT is not a member object pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 897b96630f2..11fd70b3964 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index b28efbab322..32199a1fe9a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false +"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index d3d4bdf9799..799fe2b792f 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 53, + TOTAL_KEYWORDS = 54, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,57 +125,57 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 76 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,25 +185,25 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, @@ -211,12 +211,14 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" @@ -229,7 +231,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -240,8 +242,8 @@ cp_trait_lookup::find (const char *str, size_t len) 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, - -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 + 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4d521f87bbb..9cbb434d4c2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Wed Oct 11 21:45: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: 151601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp851087vqb; Wed, 11 Oct 2023 15:27:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF18Wq3aWPiOHHpuKLAjMVe3wOQJ15PePcFeGSW/EXqy7N+IN9cqEmgCTq2P+6K+fb0O6VN X-Received: by 2002:a5d:500b:0:b0:323:15d7:900e with SMTP id e11-20020a5d500b000000b0032315d7900emr18435707wrt.53.1697063240324; Wed, 11 Oct 2023 15:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063240; cv=none; d=google.com; s=arc-20160816; b=B1ZkzurBT+Wg+5nbbLahVxHdB1A0a0pRakSWckAzJUysTKctIeYU/daEyVuvdaOjMW LD4g/SiNIWYGwothJXfEINsqpy0uRbG0aqFmamOZipRZj5Ge+CakIpSlYpbpme90n+go gpt5eWuLPNOZwwQZpowjIXi/G/L+vfmes/mJYA3+Afrl+0t1rsiG+Q2PB11OKVX2rJ8M ReySRXjqq0q6FKPJLfp7o7BzMjwsE2mzUJ9/3+BdYtZbxXNl+RgRt23kdo+S1uD8/drS 6zQGLU/SX65EzBifIzz6po6mj+IQ1Q1hkoxfn5uGrGJCOeob2cq++QvOscw1Qsg9QMoh SCQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vEeRLvStxVYJwtgEUEMUFxPXkamVIFGktZMAjO8TOau5ZEDP1akCDTkUkorwddDJGS 41E4rbkmq32NL60JGTUPxAh4Tk/q4c8CftW+IYiepiyuwVUadKpfjK+bQk6y0wuNPiUK 4HBv9arEEZjonWS9wItDIqwNiDyQG8YFkVlRH2HLeSD6Sr96bqiTnAehciF4+UDrgxDA zhoBs5FhQU4CZf2w4Ffk6SXj+qGP0RNqRdpwYBvIJaOshNkxpNQoNPSPOyamoTms3+NZ x3tlEjIAgOEy2Dt6qdlpYEruC45Hc95b/PlptJypjOPUWJNxkQnrIx+d06AB3emy9a23 h3fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vxQmFW+g; 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 c26-20020aa7df1a000000b005381520ddc3si6935798edy.418.2023.10.11.15.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:27: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=vxQmFW+g; 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 45DF3398BE91 for ; Wed, 11 Oct 2023 22:04:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45DF3398BE91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061860; 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=vxQmFW+gjB+BUfwYMLu5TY12F6ClIkSGE1GG5gCnxRPFH7Zh59m+4AHwYMFBhd9Fi HKjqai6C8JX6ysi2pHKgS8XeEgE8iElIX8RVoIUBNxZhScUD++VOBup0fiYgYXA3ea 0zFzthzUvmXmVGHKHI0qJMt6/dX+j6VPcfsetIms= 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 70E98385E012; Wed, 11 Oct 2023 21:55:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70E98385E012 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLr8v2013898; Wed, 11 Oct 2023 21:55:04 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyyqu29r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:03 +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 39BLsjaj000642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5M021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 20/39] libstdc++: Optimize is_member_object_pointer trait performance Date: Wed, 11 Oct 2023 14:45:56 -0700 Message-ID: <20231011215049.1052142-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vh840b_mcYrPhIRoxTZhECMEP8nFEP35 X-Proofpoint-ORIG-GUID: vh840b_mcYrPhIRoxTZhECMEP8nFEP35 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1034 mlxlogscore=718 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776996522370919550 X-GMAIL-MSGID: 1779499784500701976 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 Wed Oct 11 21:45: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: 151585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp845142vqb; Wed, 11 Oct 2023 15:12:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5Is+KaOeBavX2SCbOWjp7vJFHFD25u8z3f7SFT2ziOqx0xv/P7HPJK6pUXE1zzHIXUPUU X-Received: by 2002:a17:906:3ca1:b0:9ae:55f5:180a with SMTP id b1-20020a1709063ca100b009ae55f5180amr19117608ejh.9.1697062353232; Wed, 11 Oct 2023 15:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062353; cv=none; d=google.com; s=arc-20160816; b=ecPQJ4wh7jxlZit55MNnCzpNK5L+6t2UgjAQ9ftROk0ErVM4I1KhAHuS9lGK4swqvE Z6Dn7YhhtqH7hYw8GhN3T7F9LVOtXe00XUiBpcnjOvEtenSBS9ys7jyAsJGdaAFcgMun +rBNus9HPvVUJAqIV/fe+zm3+lkSP/9JmNY9+R6+tIKB+XpOJw1vUaSI7TkSLS4f4kAV p+Gel9gGkFsLawNS2rCOGYrwnqvduHO5W80XvcE13aKLrLzw1jkhU1jFQWOsXo+8zt0L ysUWzRmvCTeqBsNtr1MCtlxCf3tq6kY4JJYlLAxmyBVXjoirE0/tcSQ4ClDzoHRObqYw /0vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Jlc5ItFUnGLmJP9+KEdJIAXgTTQVGExd2TgqklnsnD/ZXz85blOw88v10c4jR6xeiz rZS1ml8HQj+gIj08shq/oRtYOQiMpjbt90PWm9NA0Q/iwYhh57QAhpqtOsaGl7HLj5Ld PJcRXLzmjGcXCcBsp3r8xSYCVEnaZ0eITpZlfsJU+lRHFuWkGNvu7evnPRfWhCHefzyw x55cSsjFkiQaiPkIAJDilO8LgNWwyOKWPaVgiK8TNj6yBS0aBg3PB03sH0y25+H1HGM+ lrWmb2uo3KM9jhnc2RsPwTnMSD9CxlvDgEUkJ2IpQQezczjDsahXyhgme9uaioSc0pmT vbaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ykL9nESO; 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 l12-20020a170906078c00b009b2dcd8834asi6685091ejc.243.2023.10.11.15.12.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:12:33 -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=ykL9nESO; 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 95EAC38560B9 for ; Wed, 11 Oct 2023 21:59:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95EAC38560B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061574; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ykL9nESOLOYhW4IImTCnbm5vge+fAZZQxuyWBfxWZRbzlfz1H+Q8OpCuSCpKmOMOO Q7bkLqDrLgl84Aawlm3X93LqyUWcEP3WvUu5rfuxVX7kiElCHcFRjNCl6x5akiaQXr 3EbS0h2AADi6eyTOKfKu5MU/oamF8bbofLkmdtcg= 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 D6046388C035; Wed, 11 Oct 2023 21:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6046388C035 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLkpeI011201; Wed, 11 Oct 2023 21:54:58 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2sm0rrs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLsjOU020899 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5N021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 21/39] c++: Implement __is_reference built-in trait Date: Wed, 11 Oct 2023 14:45:57 -0700 Message-ID: <20231011215049.1052142-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -_4UZfGWDlcNyEQE73eHpGP4wbsiI4Af X-Proofpoint-ORIG-GUID: -_4UZfGWDlcNyEQE73eHpGP4wbsiI4Af X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=915 malwarescore=0 spamscore=0 adultscore=0 impostorscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1779498854252738410 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 113 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_reference.C | 34 +++++++ 7 files changed, 104 insertions(+), 55 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 98b1f004a68..5cdb59d174e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 11fd70b3964..e867d9c4c47 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 32199a1fe9a..5989b84727f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 799fe2b792f..f0b4f96d4a9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 94, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, - 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, - 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, - 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, + 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, + 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, + 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101 }; unsigned int hval = len; @@ -116,58 +116,58 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 54, + TOTAL_KEYWORDS = 55, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 100 }; static const struct cp_trait wordlist[] = { -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 77 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -175,7 +175,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,7 +185,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -207,15 +207,13 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, @@ -223,6 +221,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,8 +231,10 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 82 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false} }; static const signed char lookup[] = @@ -241,9 +243,10 @@ cp_trait_lookup::find (const char *str, size_t len) 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 + -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, + 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + -1, -1, 54 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9cbb434d4c2..df720459458 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Wed Oct 11 21:45: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: 151612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp854628vqb; Wed, 11 Oct 2023 15:36:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1Epp9Lcit0Z8WG2v3wErAUZ+aZ5wjlR0ChZCIBUs70exgZbr4voH/LPeonQfrqzp4clOG X-Received: by 2002:a17:906:32d5:b0:9ae:6388:e09b with SMTP id k21-20020a17090632d500b009ae6388e09bmr20855298ejk.40.1697063770837; Wed, 11 Oct 2023 15:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063770; cv=none; d=google.com; s=arc-20160816; b=WK/dsWIDqSZW2tZej2nvqhG2zvYY66/m9uUjI8ZzaBbxy7XSfv/adk9ileyCvGs3kq AGpqsf5FmphGqhM3Sh9u2wKGg0JbBLRYAjqcuIq656gjRutGNub1SR8Uc6Xo5AknPzi3 6OlbTZXat7qvGcMwUKouNjwSjz19Ir+Br3luz41wYItINaCNB91bDu+0jEZtbeFxJ/y9 XKGjMOpD/7XT0VmzuCtViY0bVJG50UpAMcDv52CaZls6XOWhP4XhyT1cJCT27axPzYsu De3nPc3XZmrBKTUXvU1/9PvKBFOaVGR9dHpT9s0cCq9vgSl1KPpjkXKSd2KVoCkgZvNf IsTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=O0MkBw3TyKWnp3jtnzD2N41wRV/OY111R4OwfYLqarLXSfPC6qr7ntZQUG/bTzTeRq jYkQGgB28Tdh2GzYVRi4VL3dInCcGM02kyPVqjDE1rRMjT8UcWg8uoeB1nURLGI4xPJV pt76ir3bz46SuIU86ey5gkQomRo4Mknzb///4iv+PAWkG6OrYGFb82eyLByg19prtU2q JxaEHzvTo4K5KEFB0dVFHbKrCEIt45AdxE1oXfvpccB24v/pFA7X/L1l41fg9ryGsubz d4u3boHx48MpgzHb598tKIg11PijkUv12zdoC9s5U62JwupcKlOHTU4SfLWidMQ3pKpF FCtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rDqhG+k6; 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 g26-20020a1709064e5a00b009b2fa1c02b5si6560011ejw.1029.2023.10.11.15.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:36:10 -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=rDqhG+k6; 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 31BF6396DC11 for ; Wed, 11 Oct 2023 22:07:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31BF6396DC11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062074; 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=rDqhG+k6mL03CcNUaxQ5A41xj4ueHhFzcHJTzEW/bELWIRJkwChYvmsb+6q/7BMF1 qm7QFLbK4NT4i1XJYY97DkytZkwN099g53KFftosocQq4oxZs1vjDhsZVQINMKoziQ jvadLm9daX0AIDz1UDexKRwABztkKnAgxtcEV7mc= 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 159133893656; Wed, 11 Oct 2023 21:55:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 159133893656 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLr8v5013898; Wed, 11 Oct 2023 21:55:20 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyyqu2cf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:19 +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 39BLsj2s031150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:45 -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 39BLoq5O021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 22/39] libstdc++: Optimize is_reference trait performance Date: Wed, 11 Oct 2023 14:45:58 -0700 Message-ID: <20231011215049.1052142-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: BgWg9V9iZB4uOqb2HXKOcU2Ggd-qrc0m X-Proofpoint-ORIG-GUID: BgWg9V9iZB4uOqb2HXKOcU2Ggd-qrc0m X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1034 mlxlogscore=783 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776997499735714658 X-GMAIL-MSGID: 1779500340686927472 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 Wed Oct 11 21:45: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: 151608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp853775vqb; Wed, 11 Oct 2023 15:34:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFO3PHHILqEPNZXRR+rqr1cKBgRjus9QDk1G9emodfOL7D4yhBuLAxrqcgyIhS8qOhdekll X-Received: by 2002:aa7:d1d0:0:b0:530:bdb0:6cb3 with SMTP id g16-20020aa7d1d0000000b00530bdb06cb3mr19185465edp.28.1697063644230; Wed, 11 Oct 2023 15:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063644; cv=none; d=google.com; s=arc-20160816; b=nAwHl0InOEwO4pVFOKOilPe4alF+wRQWzga5wmp2YVIF40xGocS0wYPSdZj6bPmw5b u2SgfHMk8RsvZbCbYTiF9qChs1MxIHNc3cgjrGwF+XUJzqCZKVc4Sp/SUN3Ue171uEqf 6UHuzHKIdtha44CKtf5IBepVwtEQltvQDAY9VLbyx2jbdfMAq1ewp7TgUjJMMIsbPVPk MIFPqV3bVkjkqIhercaxiRpEypSfWcDs6zuWFnKoa6dvtk8oHMRlC1eMo/HPymL2+n5y A9gUU6iMOEoLKCmrE3iRocCZ9L/0h7oUQvDnFtYPgvZLMIl/koZ3VD9e9TfNX8ZqUjFB 1d2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=XC5GKo7trqeftw1be5qBVzmcox5R0P5mKJYXeJnhKZNbiGpc0gyiujexYBjr+ZuuBS zqcpNKM5LiIZw7mzwNcck/inZCCxTy49kkI3xzR2RPCCmUDMJpYQbrmu9cVP2Ulb9FAH ykd57V9lUUqhjkqicPEAfwktEG1QlH9cAPcN9wLhVSiQLn0ajhOb3n8BwSYZKmup2XZK Q193sQMf26gho05vBTNBlDOdDfFZnRBuhOZtDlKYzXyV3xS/rX1JdR0JeO4LxdFHy4ev CcjLJur1F+y+oQ8SRNRbeo8PP/l8NB4g7XBtwetJtAchgMmDuMpY0nCkFFTUSzHHy/3h IlHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Plp7pfOr; 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 p24-20020aa7cc98000000b00534497b764csi6615194edt.287.2023.10.11.15.34.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:34:04 -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=Plp7pfOr; 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 652D23A9226E for ; Wed, 11 Oct 2023 22:06:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 652D23A9226E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062010; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Plp7pfOrng0Bklnkm3O7lkH7AxR+TuhdhjwgF6TdngyBPQQFh6EHOZRq95hmbp7Bt uuzYSx7od7fz1+iSEYDPaWIIOtlgBGs+KiXiQlIIY1K5s3pZThsmWb+Y/rdlTJKmIW CuO/uzQeydM+iizCgJCfTQbSBsFPMgZaWzqe3hDI= 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 4BDAF38319E1; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4BDAF38319E1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLZxYG011635; Wed, 11 Oct 2023 21:55:01 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyhu387x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLskaS025748 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5P021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v17 23/39] c++: Implement __is_function built-in trait Date: Wed, 11 Oct 2023 14:45:59 -0700 Message-ID: <20231011215049.1052142-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: MadbYJ-jmLa3ujASZIvWKr6DukFj1Q1c X-Proofpoint-ORIG-GUID: MadbYJ-jmLa3ujASZIvWKr6DukFj1Q1c X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=936 clxscore=1034 spamscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995319714743541 X-GMAIL-MSGID: 1779500208068565765 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 143 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_function.C | 58 +++++++++ 7 files changed, 143 insertions(+), 70 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5cdb59d174e..99a7e7247ce 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3750,6 +3750,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5989b84727f..771242a7f45 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -50,6 +50,7 @@ struct cp_trait { "__is_empty", CPTK_IS_EMPTY, 1, false "__is_enum", CPTK_IS_ENUM, 1, false "__is_final", CPTK_IS_FINAL, 1, false +"__is_function", CPTK_IS_FUNCTION, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f0b4f96d4a9..b6db58e93c9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 94, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, - 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, - 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, - 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, + 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, + 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, + 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,113 +116,113 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 55, + TOTAL_KEYWORDS = 56, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 100 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 78 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,10 +231,12 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false} + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = @@ -242,11 +244,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, - 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - -1, -1, 54 + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, + -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 55 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index df720459458..4b8e80f3e62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Wed Oct 11 21:46: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: 151607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp853410vqb; Wed, 11 Oct 2023 15:33:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6b8iuKJr5PALVdc+ZxbOTf/bSbUmoMBKkKiC6K6WOE3QGaIiNDK8EeeBFruwvO0oFEk35 X-Received: by 2002:adf:f491:0:b0:317:e5ec:8767 with SMTP id l17-20020adff491000000b00317e5ec8767mr18543256wro.21.1697063589732; Wed, 11 Oct 2023 15:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063589; cv=none; d=google.com; s=arc-20160816; b=Xsd50KiTDADinCJiJb6zLZdJF+c8OuG0A8TzhIDVDmyr5TNFepkZURvKHanK9hJAzR 1Z+SlxhEJtFanHFZyshn71VIM5xXB1fGDzcJX9BAo6Aa5i80r7oL+bB7ApbnIAWit5Tm al/gWeTv6YHAar4dRuD11acSUwAEijAG5Fsbi/eE1DPAly8kduy7vkrN60tvuIY/awx8 qrtWze7asTJZjakb2EqAZG+n2uOc9x221ExV9koJ30V3bmyjOEyOdhWaLS5ak3kAiTQV pWzhtQ8WlM7M1+VryWHBAwlvsXEqI8IjiK043Z9e0QmZ6pJh1hu7rMmmCZ3roHFzSNZ6 +pcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=nc8Pe/y6VY/cS0wrn1R17gxQ9bKfWTMGhT8fhwLjh5/WTRAByVCyBSYfR+gYEF0SaE o1gv3s/0fO7CmBlvfuJRr2l19c2xcozCqgEnM5hywfDIV6lOVnJewTPqzRrG0GYfAVMj /hZzbKh+dXlURl4H2Oe9MfCvrSqnwEuaeFjYUKvDKE33szJeniDGpWxMOFG8xV3fKn9I DTAU9pGbyuOti5xOH0LPI+e1fZnO7JUPe+YXVwtwgdi/Ddl65z0hwubfwWGeF858if7P 2UvmwhcQcfpBQ7w48k72sgRtl//nqFHI62sKdwxd0MoSqpiNp551nGlV5yNALlS3BX1x HbtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iw9vinaI; 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 bo16-20020a0564020b3000b0053dfea8afc5si284723edb.234.2023.10.11.15.33.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iw9vinaI; 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 0564C3887F4E for ; Wed, 11 Oct 2023 22:06:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0564C3887F4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061989; 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=iw9vinaIBYgvYuW9JoV7kJxmX8w6i5ooPiY0CUgSh4t0vYNsPtQEfB3HVRRqXC5oX Cj2OsQ2iDd5XLsXgkc9AFQRxsvVPRKwTKSlneh+Vr7X6dSCpXwos8m2LQFQGb4fh5A zgnIVDoDgFG1tH9uXtV+otyPRfZ/gjRR7llh/P5U= 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 03AAB383138B; Wed, 11 Oct 2023 21:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03AAB383138B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsi2x013297; Wed, 11 Oct 2023 21:55:04 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:04 +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 39BLskfw000643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5Q021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 24/39] libstdc++: Optimize is_function trait performance Date: Wed, 11 Oct 2023 14:46:00 -0700 Message-ID: <20231011215049.1052142-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _zW-tMs8MshyHd83v86n8_GA-ozqPWxV X-Proofpoint-GUID: _zW-tMs8MshyHd83v86n8_GA-ozqPWxV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=583 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779500150423997524 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 Wed Oct 11 21:46: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: 151610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp854554vqb; Wed, 11 Oct 2023 15:36:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+Is+vyX8L/f3bYmHDdQ7a0yQE7/oRq3CvYtEXghXJ8MtrTx2rmx1MXriHwlZTRqoBnZ+f X-Received: by 2002:a05:6402:50d4:b0:53e:1f6:c694 with SMTP id h20-20020a05640250d400b0053e01f6c694mr412307edb.42.1697063759914; Wed, 11 Oct 2023 15:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063759; cv=none; d=google.com; s=arc-20160816; b=ubb4go/oCcIckHJxriopDTJP8IcBJFtSMXf5E1V19ougwzIWZZ/Q+oOYpDJwWK/fJI f6w42ECsHjFar48RiXkdga4tj2p0QqNP0s3Gpu2UKKCofBlrCKE5XxpBk0YgVyu8hDkt QdkQKhyFPkwHgR5vC4TG+/HrRzgldpnDtPzy2KCb2v3ielNXe0+hcAzcFugeLm3UQNhn LO3PPC1u5xsR4hJO1hXBznjDKr7S9d9ddM6N/w8Vjyq+w+PBEK1wraxtTrmB1PQaPkyi oJDE+cqEN+nnO2lFx7l88aHiQI7qJ/cUiQBBeUXNXLQ/eCEBsIrFCNAkOwuYLIwhCdUp kBLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MsCohika3SnUJAbzU04IVOQEQVXck/sNepo7qePh20gK187N2MtHz0sCW4LpcofAGB YROTskxZiTmSpVO4iMvxomhJ5566TnXpTy32GMuGp+Ehvs97TEv/1SIuAqyP4BlRmHRS RubQdiPo2VC+jL9Kl1wLsQjwz5+EeGt5p3ko81zPMZnTfo4wy5MFFJ881HCA1bApdXLV hzpCW+s6r/PS3mwfuQ5CcETqdJjCr51IiAZ32ajdO0Ei0JcYM2xaFwVuH/ZZcw5JGndA pNTNPnvgI6L/HTLdTJ2o1aXcvWjrkYLx5R4nGgD7JIZOcAnCl6+CaxUBAP0YFvPowXp+ HZOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ggC50MMu; 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 g25-20020a50ee19000000b005349360bae0si6758194eds.12.2023.10.11.15.35.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:35:59 -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=ggC50MMu; 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 C589338494EF for ; Wed, 11 Oct 2023 22:07:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C589338494EF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062067; 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=ggC50MMuj0L5l/g0f3vXRRdS247aiT/jn4nfuhNh6tMaCAFRL/Tr68IEaYnx2XhIF 2I6fQVSKmEaF2ZTFt1SWN0znuEnaXjHhQYvu8nrlM9hYNuZBAT+uQQB2v7qNraDor0 24bOA01WwzQ1DqZ+aRmt6bXmxTcz2ImdA0rzefIc= 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 BF61B382055B; Wed, 11 Oct 2023 21:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF61B382055B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLri9N027907; Wed, 11 Oct 2023 21:55:04 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2eb93u6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:04 +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 39BLskPE000644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5R021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 25/39] libstdc++: Optimize is_object trait performance Date: Wed, 11 Oct 2023 14:46:01 -0700 Message-ID: <20231011215049.1052142-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: n3VFaxE__VxCbvQAexHr_jKOcMNIWmiA X-Proofpoint-ORIG-GUID: n3VFaxE__VxCbvQAexHr_jKOcMNIWmiA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 mlxlogscore=794 malwarescore=0 lowpriorityscore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1779500329545021233 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 Wed Oct 11 21:46: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: 151603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp851368vqb; Wed, 11 Oct 2023 15:28:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjCrSGB8NxQTGep4oLKTBCAkuDdry7hm+hAgVZyZj6tY0G00SmvHwoGsXGbJd+53V3rhMU X-Received: by 2002:a05:6402:d57:b0:53d:ecb9:53a2 with SMTP id ec23-20020a0564020d5700b0053decb953a2mr2152026edb.36.1697063294366; Wed, 11 Oct 2023 15:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063294; cv=none; d=google.com; s=arc-20160816; b=EPHm0ZaURd1kqz86epS3YPrEaMZ7aFHZW1afmY6G3/EzZb4HJkEHl8Pc+D5l0UWqDY H7AAh+4FqDgW/RcbLlSfD9lSwSWntONS9x49jPVCL58FPgBR6kdcRVneQ9C5+HaH38/h tmRcSSUxnDOVDPlpiocS9nMzUH0EQmagtfK4UM3w1IIbgI18oY1WYqNazJdYtPsiY42G gOMU7jPa0hIRtMn9NYIdAFfvpE/daueUALP6HovgPSfcqH8IumWklBxHpXSX+xjI7xtN 8Pgu59tulaTF7azedQ3tD+UuKS9bwZpqL+YGRuJzRG6aXNIK2dVvCReNdjHdZW7zu+gR vVYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wwPWRg3RXfKlL6qs8EXZnBjCuPGy/y8E3l1Ls1CVn9gjlgth+OrHUO16QRGBGZFB8p NpU6wmjyVQ039Z31rS0q9AH1C9KHOfv7zGtGyYp8o4xpEdmQHb7YbHXVYr5GdWEK05E6 iCfISJxKeJr5p9vVjX5B3GUsR/Xn/81WNdhTSTqg65UkrvLvT2cXQcO7ACNOAUV9nMcK Pw7f9S3A8nxoat+O+Ml04d8Jg2rfiwlZql9ngbvNWwGi2uiO5RjX0J7/ht/Af1gkxpHf d+JgdZ5MqNKcuDX+cg+Hzk7Ir0/mROSj4BikETKQq4l+ESp0aXunHDEinzPAgH8W2q7x VVzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VOdTlHI8; 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 b19-20020aa7c913000000b0053d9f5393f4si1795114edt.21.2023.10.11.15.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:28:14 -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=VOdTlHI8; 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 CD9733907BC2 for ; Wed, 11 Oct 2023 22:04:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD9733907BC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061882; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VOdTlHI8C6DJOYUrfNDWWCZqdYIkMNyJfePqETBahm/snDX32AmOGGFdMy/o1ekmn 2EMDA1d0W/xYTSnzp8sgNmmkhQR+UnyzUQ+cmzlfYw3CgpkH9zKpKj0IF3MSH60JS7 wj1yQt7DSUX+B8+saZbFJbcoWODkDOfBD5IVC9Gw= 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 2C8813858CDA; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C8813858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLrJkj002490; Wed, 11 Oct 2023 21:55:00 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq9bm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLskoh025749 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5S021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 26/39] c++: Implement __remove_pointer built-in trait Date: Wed, 11 Oct 2023 14:46:02 -0700 Message-ID: <20231011215049.1052142-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jpcniFOI_F45I9GHkfSKmIOcULtAIUGz X-Proofpoint-GUID: jpcniFOI_F45I9GHkfSKmIOcULtAIUGz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=585 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1779499840755610911 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 32 +++++++------- gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 6 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index fa79bc0c68c..2add97ae749 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -97,6 +97,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 771242a7f45..8fbd67788d5 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -77,6 +77,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true "__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_pointer", CPTK_REMOVE_POINTER, 1, true "__remove_reference", CPTK_REMOVE_REFERENCE, 1, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true "__underlying_type", CPTK_UNDERLYING_TYPE, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b6db58e93c9..ad2c2a2d250 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 56, + TOTAL_KEYWORDS = 57, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,7 +125,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, @@ -137,17 +137,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, @@ -235,21 +237,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, - -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 + 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, + 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, + -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, + 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 56 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Wed Oct 11 21:46: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: 151605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp852901vqb; Wed, 11 Oct 2023 15:31:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFw6T6fxz2OC7scFEEZboW9yuTWxDsLGBHBuB05ovlw/vDFQeDjVJf2uA3iPY6T1J/oL8Kc X-Received: by 2002:aa7:df13:0:b0:534:2e79:6b02 with SMTP id c19-20020aa7df13000000b005342e796b02mr19954387edy.39.1697063512550; Wed, 11 Oct 2023 15:31:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063512; cv=none; d=google.com; s=arc-20160816; b=mwWbHJIwnYz8mIymYKHac+B6PEkpsfYtM56uo6QOmLt673/hYzMld0fz02OOwXWHHc WgPgXJsyv/yxhWBL/Ja1o8VhfFBD2VIYgIJh/n7KVBp2hdu5ofsqz5ZknaehPq4X3Ady uTS4g6+BUNw0AOg5OuMKRlgBRiYjWU8+7VvFDp3p49tXI5z2CdOTYxzFJQ6Ugacv/Wm7 SmdgxbWXYv6ZW4ZdssEpTgbdsyTfD9o57d/uTFR6kcPeU4K6a5GsTXcR8mmTgK+t7luu v01agRCmNRlmWCfykHpyi4AeKFHstcoLlF9DaYfMl2lw5BS1WiP0RlbZi890j4/bVVyx ZmFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=z4g8PY3cRQY7J0+HwZdN7Ecxr1sXZLIk7z5Bauiae1wGSmOdollLVhwUsnW3wQy8Pm zpUrUnlBnnSCdv+VTOWbO0rztQ9W0jyzQ8D6T4OKp0SJwiqpnyfWaO68bfiLv+3kcX+1 ee4XcNFCaaaHD6dvd24oYGfQqB/C2Kgz44aNc+xBvPtM9ZJvR1CD+8LKDuCqchHT3iBf /LH6zgX94abDJYdC3VJkSt0nHG+f/dDouKs4DQAum6gZyqpIRWi74A/TLdw+X8tN2t5x woS+BjGRXgcqzISTJada7Zwoaz5RhSS19pB4C/lRewfbORWO5xISz9SAYWZfzENFa4ZI cjIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rx0XW0kr; 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 q11-20020a056402032b00b00536b154c634si6589953edw.260.2023.10.11.15.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:31: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=rx0XW0kr; 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 E2A4239584F4 for ; Wed, 11 Oct 2023 22:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2A4239584F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061958; 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=rx0XW0krr0AOXqLCjBC7mQMVjOtlh31LgAsje2y51rz6Hn11rdiGQ8/rQiIHcBQhk mbcEWv6MOJILb7tklYaTiLAc1BW6p7i7gkkviJRCf+1kIHNhnttyuryin9LsNAN9W/ gYTQlWyq8GSeJyFKz97PANmLoeNKlQHaSVD0ra+g= 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 498FC382055D; Wed, 11 Oct 2023 21:55:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 498FC382055D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsH3P007576; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2sm0rrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:59 +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 39BLskOv027608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5T021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 27/39] libstdc++: Optimize remove_pointer trait performance Date: Wed, 11 Oct 2023 14:46:03 -0700 Message-ID: <20231011215049.1052142-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Z_-VOi978jUcmlCRIYUqTBV7xfl8sR8K X-Proofpoint-ORIG-GUID: Z_-VOi978jUcmlCRIYUqTBV7xfl8sR8K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=541 malwarescore=0 spamscore=0 adultscore=0 impostorscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779500069356470531 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 Wed Oct 11 21:46: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: 151582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp842780vqb; Wed, 11 Oct 2023 15:07:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFD2W2P72CBp2DLbQna+Te4A3nts4x+LNwHfzvU6lC/47AOCRmXX3+1L499ctVH6e09gdYK X-Received: by 2002:a17:907:b1c:b0:9b2:787d:b326 with SMTP id h28-20020a1709070b1c00b009b2787db326mr20141346ejl.16.1697062035530; Wed, 11 Oct 2023 15:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062035; cv=none; d=google.com; s=arc-20160816; b=JOiZrZq94b9t8FYq2eDaQMn9ipKUZ69FtNpRxETE9UhuO5uoBV8+6v/vfk1U7Qc3+t FTiWGfUQYYmGT7f37AqAIkv7CcAAgEeZ5//gcxwJMAQlqM35dVaqSESzwCR2Px5WGLOS p5pFmGEXISjHhQaW0LJVRVVEOhTpSRrGSxg8kz/19Wivz8Y0JqtUuAx4KeJLPWk2RGlq sxXMqwNuH8kVZJYR5U1dNlX/h+K0F3JC8vA9rHDo/xEScaf45DRRCzbiSRZAs73r+G25 BXnmi9mbpvWnJRa+gK7fn2X3M1UaAE7MRlwyV3jcWhjIfCowPQb40epWVGNU+nS+PS84 +yPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Zw7FcACt6fwTyEV8BsBIJpmWN8IBoXWy5KwvLOECg9s=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uLEnSubVvauOuc2WhGQ5Lc3t/xsAMRO69JMTKLHgIQ2JzR46W+iLbIoqcCNs7PvdXQ UcLdg82z54oBZ0K5IPe1D5309W2omodDeWOpjvsk4W93bAOnOdOcUs2wSawgQqXN3i4h rAoxIHuovsbKlFwHZWWJhU38FmEu9ltsAhlcfTeUYJxUV8MSnivA+pA28ybvmWv4Jw1E DQrS9FaP5HvalCLnAtRO0hm00VOYUYE9rjKTnewhHFzyM0TGBHr1RXm2KoOZuUouDqCU xDbhbfN6OrLWr7hSiLROL0h8WjReVHh7xScGVjFTUga8HdWj3oGGMqYk2Z6GZ8D3GQiC SVIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dX+9CLjw; 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 s8-20020a1709060c0800b009b274cdf9d3si6686723ejf.367.2023.10.11.15.07.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:07:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dX+9CLjw; 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 EA6F53831E24 for ; Wed, 11 Oct 2023 21:58:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA6F53831E24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061492; bh=Zw7FcACt6fwTyEV8BsBIJpmWN8IBoXWy5KwvLOECg9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dX+9CLjwk6zfqE/Jk4aM1KtZBWTJuGrboxK0RxlEzbweU92YiW79T2vkNA5xnfuLK 3ymtTqpzjr5gxdJbUGAQdXLDDP3xrLVWC3O6mtZ0my9XB7TezHWLW1tALcpssP48Yd sapDSL+u75qknR9PgX1t1aCLK1bc5S7w1vhsjUik= 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 D8CE6385CCB1; Wed, 11 Oct 2023 21:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8CE6385CCB1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLrnP0021781; Wed, 11 Oct 2023 21:54:57 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnjfffcgj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:57 +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 39BLskmg014004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5U021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 28/39] c++, libstdc++: Implement __is_pointer built-in trait Date: Wed, 11 Oct 2023 14:46:04 -0700 Message-ID: <20231011215049.1052142-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: hX9PZ-C7haEmXOltsU-c288-N5fTzJuR X-Proofpoint-ORIG-GUID: hX9PZ-C7haEmXOltsU-c288-N5fTzJuR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1034 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995712601902354 X-GMAIL-MSGID: 1779498520916186413 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. * g++.dg/tm/pr46567.C (__is_pointer): Rename to ... (__is_ptr): ... this. * g++.dg/torture/20070621-1.C: Likewise. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Rename to ... (__is_ptr): ... this. * include/bits/deque.tcc: Use __is_ptr instead. * include/bits/stl_algobase.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 155 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_pointer.C | 51 +++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 22 +-- gcc/testsuite/g++.dg/torture/20070621-1.C | 4 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 6 +- libstdc++-v3/include/bits/deque.tcc | 6 +- libstdc++-v3/include/bits/stl_algobase.h | 6 +- 13 files changed, 165 insertions(+), 101 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 99a7e7247ce..c9d627fa782 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2add97ae749..c60724e869e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 8fbd67788d5..5d40e04f91c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false +"__is_pointer", CPTK_IS_POINTER, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ad2c2a2d250..ab783b161c7 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, - 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, - 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, - 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, + 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, + 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, + 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,78 +116,78 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 57, + TOTAL_KEYWORDS = 58, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -205,23 +205,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_array", CPTK_IS_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, @@ -236,22 +240,19 @@ cp_trait_lookup::find (const char *str, size_t len) #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, - 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, - -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, - 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 56 + -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, + 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, + -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, + 57 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 168411f6700..83ed674b9d4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12412,6 +12415,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcab0599d1a..efce04fd09d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..f08bbf6fd7b 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -192,13 +192,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -226,7 +226,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char @@ -1202,8 +1202,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; const bool __simple = (__is_pod(_ValueTypeI) - && __is_pointer<_II>::__value - && __is_pointer<_OI>::__value + && __is_ptr<_II>::__value + && __is_ptr<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); return std::__copy_move<_IsMove, __simple, _Category>::__copy_m(__first, __last, __result); @@ -1294,8 +1294,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; const bool __simple = (__is_pod(_ValueType1) - && __is_pointer<_BI1>::__value - && __is_pointer<_BI2>::__value + && __is_ptr<_BI1>::__value + && __is_ptr<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__copy_move_backward<_IsMove, __simple, _Category>::__copy_move_b(__first, @@ -1426,8 +1426,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_integer<_ValueType1>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1515,8 +1515,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value); + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, __first2, __last2); } diff --git a/gcc/testsuite/g++.dg/torture/20070621-1.C b/gcc/testsuite/g++.dg/torture/20070621-1.C index d8a6a76b6b0..b05136163e8 100644 --- a/gcc/testsuite/g++.dg/torture/20070621-1.C +++ b/gcc/testsuite/g++.dg/torture/20070621-1.C @@ -18,7 +18,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -49,7 +49,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { template inline bool __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); + const bool __simple = (__is_integer<_ValueType1>::__value && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } template inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..be0689096fb 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -17,7 +17,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { + template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..3711e4be526 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -364,14 +364,14 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // Pointer types // template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -390,7 +390,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index a212b8a6940..08d888ee8af 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1273,7 +1273,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr>::__value + && __is_ptr<_Ptr>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with @@ -1329,8 +1329,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr1>::__value - && __is_pointer<_Ptr2>::__value + && __is_ptr<_Ptr1>::__value + && __is_ptr<_Ptr2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 2f5a4bd4fd4..d1438429487 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1217,7 +1217,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple = ((__is_integer<_ValueType1>::__value - || __is_pointer<_ValueType1>::__value) + || __is_ptr<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1380,8 +1380,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with From patchwork Wed Oct 11 21:46: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: 151611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp854560vqb; Wed, 11 Oct 2023 15:36:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtqrt1cAJ3k0J9sFZIxpq2ZQOt/xWjTIvkXvKzbrM1DZZ1TlWArhfJRoMXxeSYf/pgDvba X-Received: by 2002:a05:6402:890:b0:531:140f:335b with SMTP id e16-20020a056402089000b00531140f335bmr18213925edy.31.1697063760359; Wed, 11 Oct 2023 15:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063760; cv=none; d=google.com; s=arc-20160816; b=cwjp1lOAuBT/WLVv5xGSN1D65pK63iID/a8AJa8GXGuikRILMCiF+OEEG95A3EzDHr qPWCLqW/FNOZhAp8fSIL9A7icc+PJwUnq4TGZGyfiQ0uB+mOXANrL9VFEa3PNGvwCCHX Uqo2QNrJGAaDWtImUCd6/ppeRKNSimrZIUSv29DkwUvnjoKv6b2bcm04woDxbihTfZ2c vzKbqY223yzhorC7m020HaRPUb34G3JX9UjgRqG/nncEX8TzuvlExOWcyP3Y9pdJx1f+ 5i6h+Hzb8zdFS4l8W+o6UzSGckWwT6Bj4goUoT3PO/k01IFbE0hBopMz81b0DbHunNM0 Gngw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=skAw4Jhy82+x1irMe4Yr4xNON7tSnT1q/Trx5PmCZ9SsoZXwG4lZC4sP77/3rpDUns LsW1oGmCQGBar4gH3udisw8gunZXrlz656gQY/1nq69sTqDE1GE8qnQNv160g6lByHCW Cire93qkI7t05voisKhoyWVu6ybPZZhYQcugu4lpWmoZYngZBjfbw9VxaE6y5Rcl7Smh 7GsdApC46nKiwvyAnvl/1HDgx7/tcXPQnZ1KGNPmx48csRml/ARUnXn7tNKAD0u8B0hn yp8KhazpbSxulXfbe63hQh+5SKlKsTZFRw/qfWXVpQZ54WxuoOcQ0U3VyUl9WFIDvqdo R59Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PH149jha; 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 g9-20020aa7d1c9000000b0053627dac8c5si6667706edp.205.2023.10.11.15.36.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:36: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=PH149jha; 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 2F5C7395C06E for ; Wed, 11 Oct 2023 22:07:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F5C7395C06E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062068; bh=nbl1p5UrIi01bZgpYpquplRxZT76qfWxPUDtpQbQXVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PH149jhaX1SWjlIeMG+0tFsVWKPKqZiAbmTXZl95KBM//+Wk1qq+ZZkwJiteK/bpE goV3jnpmGmCA/fcT0YyHOP60zlkvnb8XETd3IFfPd/usYj1MJNDD8RtdMqAzhKSOXw dxnu5BzQvdVSzJEpdh2YlYEVv0QP854kTNmiIqdA= 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 F35DC382055C; Wed, 11 Oct 2023 21:55:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F35DC382055C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsGKh004179; Wed, 11 Oct 2023 21:55:20 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq9f1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:19 +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 39BLsk3a031152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5V021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 , Jonathan Wakely Subject: [PATCH v17 29/39] libstdc++: Optimize is_pointer trait performance Date: Wed, 11 Oct 2023 14:46:05 -0700 Message-ID: <20231011215049.1052142-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ZrEU9ArwoZb1cX6qh90JVxPRgL8i84dN X-Proofpoint-GUID: ZrEU9ArwoZb1cX6qh90JVxPRgL8i84dN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=487 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776997371839653001 X-GMAIL-MSGID: 1779500329073416261 This patch optimizes the performance of the is_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_ptr): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 3711e4be526..4da1e7c407c 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_ptr : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_ptr { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9c56d15c0b7..3acd843f2f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3254,8 +3268,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Wed Oct 11 21:46: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: 151606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp853147vqb; Wed, 11 Oct 2023 15:32:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTdtW5w1wfd/pipML3svahPvOKOOdLEMcm4FKE2gLCbMK1pFF+qtYdXuNO6N764iR0TlL4 X-Received: by 2002:a17:906:314c:b0:9ae:6a60:81a2 with SMTP id e12-20020a170906314c00b009ae6a6081a2mr19926531eje.25.1697063554312; Wed, 11 Oct 2023 15:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063554; cv=none; d=google.com; s=arc-20160816; b=mEGIAQ8txWfuFJEsCbhSq90fv7tG4KvnFLPiAdP1QtCFpSmeitBXFs0u5L2aBt5lHD UPKL3nphLoEQY+k5pwuo1/qRDQTfIQ5Uk5HKVZZs+Kv1drFNdfBLdEOCpTTZYIZKtSCg +rXwdroQQYYcsZKmN1Iba7ngVOmC6++BD5DEIgW+OQmgkRZ5jCniPFf8C/4kMdOYalgr 8lwWe3upZNTsXUH9NbKxqh6/1nHUGDYjGuQTr8eRSTlP+EZ/RBWtmtLDckKx1NQErIDg WdaDd9mEdYKEjW/4C5vfVcFHzqbXE4UuuZ/IeG6GFs3G8tBlj/I6+Gs8+xHVBKuLdHom LMNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=baVu198/1psUePyf/ZegfP+yD8pWyaMpK+a0owe1Fcs=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=tgTOBnlUxrAG612ixrEEpWO/rKZBNH7HOXv6jkHCNmq0ktavEJBwRVAYRe6iO72CGm Fs2wyzr8jFd4ZQrURiWV8tM3j1ruwjeR7NHpL8h6cTQuMoTz7wCbeKIxQLTeD1FSg/P1 YeLk0ybey+GLIiXUljGJulA0tgjP2KV8JkEVEkUuuNTTtZWGXBJhDbWhziO0BB0eg1ub OIg2be3sAjSMLOiYsoljA2Qg5/bqKyhPRQTbHnfVbfVF74maZ7h95PdE1U2TQwXQLWfz NLvBrsigAGnMOCI/Uu4DmtSDHn15Od++9cALPa9BVMB2/PMJAaAZ341Re3N09uLWEC0e i6xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AjT2WAIq; 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 kq15-20020a170906abcf00b0099cb0abecd9si6988116ejb.802.2023.10.11.15.32.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:32: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=AjT2WAIq; 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 170C5396C43B for ; Wed, 11 Oct 2023 22:06:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 170C5396C43B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061976; bh=baVu198/1psUePyf/ZegfP+yD8pWyaMpK+a0owe1Fcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AjT2WAIqhqnOFqk6aI00d8Gk+8owx9N+WRojG/Oxj30n9P4jcWHDRyoDuYivb62rA O3yy4E/r0fyUbeiBbJZyWznWKtEDWQhPs79L/jhp6lFMFC0ltAPP2U5KUpnQwH2Zod XCaX3rlsGZh0bsoZVcKZY1YupeSqy/jf2QKBPDdg= 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 DFB74385DC3A; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFB74385DC3A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLhmE6016078; Wed, 11 Oct 2023 21:55:01 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp3388pnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLsk37025751 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5W021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 30/39] c++, libstdc++: Implement __is_arithmetic built-in trait Date: Wed, 11 Oct 2023 14:46:06 -0700 Message-ID: <20231011215049.1052142-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: A4-8c1SnXapTGHx7m8fckb_SsTbZ3i5h X-Proofpoint-ORIG-GUID: A4-8c1SnXapTGHx7m8fckb_SsTbZ3i5h X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1034 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995829201979099 X-GMAIL-MSGID: 1779500113622476449 This patch implements built-in trait for std::is_arithmetic. gcc/cp/ChangeLog: * cp-trait.def: Define __is_arithmetic. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. * g++.dg/ext/is_arithmetic.C: New test. * g++.dg/tm/pr46567.C (__is_arithmetic): Rename to ... (__is_arith): ... this. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_arithmetic): Rename to ... (__is_arith): ... this. * include/c_global/cmath: Use __is_arith instead. * include/c_std/cmath: Likewise. * include/tr1/cmath: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 184 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_arithmetic.C | 33 ++++ gcc/testsuite/g++.dg/tm/pr46567.C | 6 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 4 +- libstdc++-v3/include/c_global/cmath | 48 ++--- libstdc++-v3/include/c_std/cmath | 24 +-- libstdc++-v3/include/tr1/cmath | 24 +-- 13 files changed, 193 insertions(+), 146 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9d627fa782..3a7f968eae8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c60724e869e..b2be7b7bbd7 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5d40e04f91c..9050c36f105 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ab783b161c7..31fd5075f2d 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 97, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, - 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, - 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, - 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, + 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, + 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, + 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104 }; unsigned int hval = len; @@ -116,130 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 58, + TOTAL_KEYWORDS = 59, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 103 }; static const struct cp_trait wordlist[] = { -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false} }; @@ -247,12 +249,12 @@ cp_trait_lookup::find (const char *str, size_t len) { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, - 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, - -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, - 57 + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, + 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, + 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, + -1, -1, 57, -1, -1, 58 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 83ed674b9d4..deab0134509 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARITHMETIC: + return ARITHMETIC_TYPE_P (type1); + case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index f08bbf6fd7b..79d304e0309 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -217,16 +217,16 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; template struct __is_fundamental - : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > + : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index be0689096fb..da592b9fd23 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -25,9 +25,9 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { + template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4da1e7c407c..51ed5b07716 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -389,7 +389,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // An arithmetic type is an integer type or a floating point type // template - struct __is_arithmetic + struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; @@ -398,7 +398,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > + : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index 6461c92ebfe..a0ddc1dbbeb 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -1259,8 +1259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1285,8 +1285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isgreaterequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1311,8 +1311,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isless(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1337,8 +1337,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessequal(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1363,8 +1363,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type islessgreater(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1389,8 +1389,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT template constexpr typename - __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value - && __is_arithmetic<_Up>::__value), bool>::__type + __gnu_cxx::__enable_if<(__is_arith<_Tp>::__value + && __is_arith<_Up>::__value), bool>::__type isunordered(_Tp __x, _Up __y) { typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; @@ -1401,7 +1401,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #else template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -1411,7 +1411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -1420,7 +1420,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -1429,7 +1429,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -1438,7 +1438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -1447,7 +1447,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -1456,7 +1456,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -1465,7 +1465,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -1474,7 +1474,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -1483,7 +1483,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -1492,7 +1492,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -1501,7 +1501,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/c_std/cmath b/libstdc++-v3/include/c_std/cmath index 588ee1e6dc4..c1db699ecdb 100644 --- a/libstdc++-v3/include/c_std/cmath +++ b/libstdc++-v3/include/c_std/cmath @@ -467,7 +467,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #undef isunordered template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -477,7 +477,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -486,7 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -495,7 +495,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -504,7 +504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -513,7 +513,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -522,7 +522,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -531,7 +531,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -549,7 +549,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -558,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -567,7 +567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { diff --git a/libstdc++-v3/include/tr1/cmath b/libstdc++-v3/include/tr1/cmath index ba1b60cc945..2e80f1d0d00 100644 --- a/libstdc++-v3/include/tr1/cmath +++ b/libstdc++-v3/include/tr1/cmath @@ -307,7 +307,7 @@ namespace tr1 /// Function template definitions [8.16.3]. template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type fpclassify(_Tp __f) { @@ -317,7 +317,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isfinite(_Tp __f) { @@ -326,7 +326,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isinf(_Tp __f) { @@ -335,7 +335,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnan(_Tp __f) { @@ -344,7 +344,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isnormal(_Tp __f) { @@ -353,7 +353,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type signbit(_Tp __f) { @@ -362,7 +362,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreater(_Tp __f1, _Tp __f2) { @@ -371,7 +371,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isgreaterequal(_Tp __f1, _Tp __f2) { @@ -380,7 +380,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isless(_Tp __f1, _Tp __f2) { @@ -389,7 +389,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessequal(_Tp __f1, _Tp __f2) { @@ -398,7 +398,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type islessgreater(_Tp __f1, _Tp __f2) { @@ -407,7 +407,7 @@ namespace tr1 } template - inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, + inline typename __gnu_cxx::__enable_if<__is_arith<_Tp>::__value, int>::__type isunordered(_Tp __f1, _Tp __f2) { From patchwork Wed Oct 11 21:46: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: 151602 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp851330vqb; Wed, 11 Oct 2023 15:28:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDeDWAt16mlQ9h9E/NEE8pu9y8GhmPyiL3Svjt1JJaMH+Ze6hIRmC10P11dei33qb8059L X-Received: by 2002:a17:907:75ee:b0:9ba:2da5:d9d7 with SMTP id jz14-20020a17090775ee00b009ba2da5d9d7mr7177929ejc.40.1697063285447; Wed, 11 Oct 2023 15:28:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063285; cv=none; d=google.com; s=arc-20160816; b=rpkSdb2OIJmzz6t5EbEym+jGNQN6FGoBgU2lXUpItmiwwDfLP6ealQVoZQNk1Q4ycd jmLKc3NrP6bU+rCriap585iiEJBTZ9k+FYCKCZQrWnPRkAyw/6pUYIOVgDzOdkIqTuG8 3SSCwpIT9S8A8UNja2OLiC0OYweMPqsN4mX2U4HAX3UIarfaLHycOcH4XlXNA0XIgvha 2HW1jp7pY3N1jQiLYfvv1DS4mZvzYjsIQK/Mxwz9cOg7GKtI+hPSQaxAc0+kmt/296+X KICyKP+bebXbifwy4lZTlaRIk+JrVYFWjY/L227z25pp4CYaPu1dpggDGD19LCd0FfK/ IKxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lnKbywuL1IjYxEdI2cFJJipRQhRjpnwWG0vWQI4Fy+dt670WhiV66BcmTxPp7tVSIq VNXtyNCZ/jM2HUNezQIDaYkJHXOeoQ3FL9iprfe+y+JAXSNGsNxf3gXCf9QpIeHyGhXA wl/tAuQawXqNk5R6xy/HO66Jv/iqVLaEKluGKEbCHYZaRrLOXkH488vxwDy9u+417wy8 tuEYCMe9pgMHoADGdsJWlZ20Qk9oNRE5d1KQ/riv+UD7R2rm3wcLHKvvYURgNTc2pIoe q5s6x5+VLihqgtLvviPbArI8ofQAqroNsJlVyuLzdNJgE1CRCNIU0C6m91wfbWZ1sVmz UQGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Zn1aGZCf; 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 o25-20020a1709061b1900b0099bcf34927fsi6968126ejg.640.2023.10.11.15.28.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:28: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=Zn1aGZCf; 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 7A5D23953836 for ; Wed, 11 Oct 2023 22:04:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A5D23953836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061879; 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=Zn1aGZCfUBvnyMIRjBvF552VCOKQIpEN/QV3MSL5iCjeARZ8sg2ua/VigHsi2NgKX sXp3GqWsow0mLpabN9bUJWWm//nosc2YW7ih1TJn1rnjCTzNFdfNd/XLaXtNBQRae0 ZhdLdJgux03JLDulvzZRauDAFsKAQxyQyBlS6pTk= 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 C48A7386C5B3; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C48A7386C5B3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLpYtO023761; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2eb93tm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:59 +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 39BLskHj027609 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5X021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 31/39] libstdc++: Optimize is_arithmetic trait performance Date: Wed, 11 Oct 2023 14:46:07 -0700 Message-ID: <20231011215049.1052142-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: aJ7JYMygT5SK4Cuv0cduitoZMZMQIrQU X-Proofpoint-ORIG-GUID: aJ7JYMygT5SK4Cuv0cduitoZMZMQIrQU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 clxscore=1034 priorityscore=1501 mlxscore=0 mlxlogscore=543 malwarescore=0 lowpriorityscore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776996488688417878 X-GMAIL-MSGID: 1779499831708046707 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 Wed Oct 11 21:46: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: 151598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp850460vqb; Wed, 11 Oct 2023 15:25:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEn4oI65LWpD/Y77DmtkYlwUlP8GhKPShyCRDELpEInV85SsiCPWLZT2e36afNjNeYraNto X-Received: by 2002:a17:906:1011:b0:9ae:696c:2c43 with SMTP id 17-20020a170906101100b009ae696c2c43mr20698075ejm.28.1697063146040; Wed, 11 Oct 2023 15:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063146; cv=none; d=google.com; s=arc-20160816; b=b2fg9NDlVSOFqg8nkCV9dRIylLNL8qcuH9AFvJBK5iUGwrRxgtnIACoVvaS/dn+0mB 2JfLYZHRl0zD0M05GGCU1XjA7WaOHREKiryV2MWntVzefmc8ebb3KxvnkbPuX3cSBsq6 7cHO/ofZ9WGmky0HBOwdLkyqLawhNhPU4qWmYQIrRJAuXlf+DVAhZge/L23pLyNz58hC HvWxuizPWwPcJhAQv9dSRswkEvgMSWbLX7T0XjruqPjqubZGoH0qWf73PjOizxjf4bVh R/Q5ofgRIKk1q6rUin090MMAwpBUyEgFmAlkPU0AhUSQ8g8e03PrFuvJ69bbucJsW2AE w8+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MrH3d+jD33Ooj8AWlnk9xdc77EVc9WbC7ehB9PLnTZ2fywAfPXV+Ug2k/PNKLPuzWR ZRdeC83w9kKGnNHvVSGXZ3a7DNDeKXESPaOl8ujrYd5dcn5mZTwZkkkojE7RYSk0TubU xnkiqewsAFzjLjlav2naWPPWOSHXpNHpAtAdM1S99wNddUP3eNeSXnLx2a4TIR26d/W+ 3VwHq1pFaumnF23cfmpRxIQu4e3udbEcwMSfyY243ux3almS/9RWb5F//JIR2vuaaAn+ A2ASQzQtvmU5spf04V/1YX7xXaY2btOAPiOwl92vSclHiQq4bCkFFJ3q9whToBRY+nUx X1Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iXv3kmd2; 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 z11-20020a170906074b00b00988565fbf63si7120289ejb.437.2023.10.11.15.25.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:25:46 -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=iXv3kmd2; 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 06A193999013 for ; Wed, 11 Oct 2023 22:03:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06A193999013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061823; 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=iXv3kmd2gYJVcxE/+eTcCWBOG1Dk3lIyS/0/fnmdn8OEepZQGQ31n7INmhVWwA/bz em6bMizbdozeYR+V9uL/bJPanGTzYXd/ohu5EtYhCSdQwbLvfFoPf6qjB7Xwwn0NHG Lei4O7nTyBsrp8Tk3ap7QX1KURxayiQhOsJ0BPTg= 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 9B1D638207F0; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B1D638207F0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLnSgb004028; Wed, 11 Oct 2023 21:54:58 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2hws149-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:57 +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 39BLskaW020904 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5Y021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 32/39] libstdc++: Optimize is_fundamental trait performance Date: Wed, 11 Oct 2023 14:46:08 -0700 Message-ID: <20231011215049.1052142-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Jt1WwiU7Qvw6ZO-HC25EUa7mm5saRyn5 X-Proofpoint-ORIG-GUID: Jt1WwiU7Qvw6ZO-HC25EUa7mm5saRyn5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 clxscore=1034 mlxlogscore=657 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1779499685587474811 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 Wed Oct 11 21:46: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: 151613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp854975vqb; Wed, 11 Oct 2023 15:36:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/AQo3IRAmwIGUFf5yygD42UpuVo5oRc8LzOfh/rKgAhRr4cr/4kGX5kWDA/JEdIrfh4r0 X-Received: by 2002:a17:906:73d1:b0:9ae:420e:73a0 with SMTP id n17-20020a17090673d100b009ae420e73a0mr20593236ejl.69.1697063819426; Wed, 11 Oct 2023 15:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063819; cv=none; d=google.com; s=arc-20160816; b=nWs4C83HjfPDNqICU7EevpWYFOWydZjLLPVu4xmcrX4Oom/XfG0M8+tneK/T+pt2KJ 6NEQ72nvJyumTr5ZEtKJGQOUs16csjDEIm+9Rrg45FGxunN/iffpEDMeJ/vdaB7cxvy7 0S2yxTFSvgLu8GByktgIPF/8znP/D1mYuWORfE5cRgmnoT2wHt38GIpQ9QhquLPh1eRN ZOXffp+3AddJiBH4wA27BwqgKObj7n6QbqB8KJrMD50P9sNaetbAVBsehDvdwPNYBEuD E/vYkApDUi+iQNvPjsPvVUhfE9ZBdBi812LkJHudSUzbfho3jHE5yVJJRocI7/nqwuHM UIEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=B7suHgizBmvR5sDoov8bTULsAf0ltHzeePzbih4bheaelEn4xKCeuEaPHTeFUbZ0Fa jjtm/bsP2SMzOM3qqUG/M6clKmfIaYsalTms0xr/B6Qxlu+PjXm+nrCpI5Ok1dR43LmQ vkIYvGAl7QPGQe0R/jjMn23ASw5Xny2QryiqO/p91uagbmRXi+KlvNKN2UxYoNKW08WE k19gcsKkVG8ERTz9sBRE1qI8prLeD4vkkcDi/NPOUWv+Go/O4fEhSt3WJn1tzf+64e4P R5qqfToLBvdXSh+r8t+gqpNAuP43eBbSy0Hsav75FvAnTH4R8QoZyoNNBI5Df4K746CV qEnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="T/Fqft3m"; 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 sd23-20020a170906ce3700b009b2cf4131d6si6682275ejb.541.2023.10.11.15.36.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="T/Fqft3m"; 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 8120F395C069 for ; Wed, 11 Oct 2023 22:08:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8120F395C069 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062132; 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=T/Fqft3mEBQUsoCyp2dITll3l5iYx91Av6i3ginGOgEfMqB5/t9RPu6M4ExN5BkBi dWhVuY36vvI7nNNCvu+CYkk6mF4AxBcXhqCGhhKIxi8F6c3gRIkaRmrwsFAj+883ji SpnNLM4o/ABGcy0+EMrRBW2wEJFz26xX6Qgbe/dU= 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 6582B3875466; Wed, 11 Oct 2023 21:55:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6582B3875466 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLsSOp012791; Wed, 11 Oct 2023 21:55:05 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyu3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:04 +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 39BLsk3p000645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5Z021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 33/39] libstdc++: Optimize is_compound trait performance Date: Wed, 11 Oct 2023 14:46:09 -0700 Message-ID: <20231011215049.1052142-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 348JUK6bgJFV8sSNSf5VzpisoFDkHKe_ X-Proofpoint-GUID: 348JUK6bgJFV8sSNSf5VzpisoFDkHKe_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=597 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779500391459897877 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 Wed Oct 11 21:46: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: 151590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp848566vqb; Wed, 11 Oct 2023 15:20:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeYTp4hJU9GFz50m0gkSNgOLXJHL763KEWyZ94MgYQSAAM7NaO6Lmt5UuLTpAYJShX4adz X-Received: by 2002:a05:6402:31f6:b0:525:6d6e:ed53 with SMTP id dy22-20020a05640231f600b005256d6eed53mr18789844edb.27.1697062848013; Wed, 11 Oct 2023 15:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062848; cv=none; d=google.com; s=arc-20160816; b=Hv8Ov8RI7MX245Jt6uNGDoG2e1gDei+k25QwXVaLs4R4pneu912McqEaROKNjbiSWE Ei+wTGwnGX0ja8n03SqQTjUBprUDM8xlkU4rS+IX57vGqDn26+jzyiAvaW1BV5bWD/Gr /kYoSEh1ZAZxK8XvlOyyTDZGMSjdJ6PjJBq2U0AvPMZbIOmL3FWsZIQXftNaVxxoARIv 45GexUfFVoPsOUNHQpJIWGFzCiP1ObtEan4Bp8IAZRZ8dmeqg6ZbUtiKk0Sl/divqc8n XBVc1J6XO8tIQceYH2Y0jbT0x4cevET4gsQVINYlFGYfPISqsAZ6Gy4ek1XXcSmBAQS4 MA/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xY2jUlJ1LrWalbu/ehbwmvya8thPyIM5v37O6oWxUJjkDxwDYivj12avSuEpklcmjz kqIOM4Ty9+e4qThpX8H2addPbCanP2tyjf36vg0otM8T0O8If+E0fgPfD2PgOs7qc1gQ 2IFckkD6GcroYxnoiYR5HnD7kD1HnlWtQRgmH+ifp4S5kcEevVUM614tlu+5ggeMB0pG CK3L+Y/pLlvYMDTM9Q+9nMysJFbuGZVmyW1W0FJfrpl5MWEnYf3MxXrOuLQ3dYH3uMMm 1aJJrWmHbfIWHDxzzhgzL1DqXxR88r47n/OUIgt5Qf/VWUHSinn6RjxbFzQiC3QM0jgv OyTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=aOE3ghni; 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 fj25-20020a0564022b9900b0053be52feda2si3237688edb.6.2023.10.11.15.20.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:20:48 -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=aOE3ghni; 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 BD7003882AC4 for ; Wed, 11 Oct 2023 22:01:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD7003882AC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061714; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aOE3ghniC38nw23tbat2AJvSlBjQxAhNxluKpi2CQmkH7y5XplSRjrwIsAsat7/38 S7+W/HOVg4+35yNnxxFrms6E4Sg+1w4kumZ3e/AFX4lovO3A1fEC367MRyvfu6pj/A r0yg9bFvVjTOjV+iiqCc0Myx/gb392YOfEzTLLjU= 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 D60E2388E81E; Wed, 11 Oct 2023 21:54:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D60E2388E81E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLgci3001698; Wed, 11 Oct 2023 21:54:58 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyjvu891-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLskT1020905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5a021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 34/39] c++: Implement __is_unsigned built-in trait Date: Wed, 11 Oct 2023 14:46:10 -0700 Message-ID: <20231011215049.1052142-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: kljTASpq3D8ez3wxOA7OczSDpJAJPpCc X-Proofpoint-ORIG-GUID: kljTASpq3D8ez3wxOA7OczSDpJAJPpCc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 malwarescore=0 suspectscore=0 clxscore=1034 adultscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=860 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110191 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996278564175547 X-GMAIL-MSGID: 1779499373251614919 This patch implements built-in trait for std::is_unsigned. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unsigned. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNSIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unsigned. * g++.dg/ext/is_unsigned.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 118 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_unsigned.C | 47 +++++++++ 7 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unsigned.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 3a7f968eae8..c28dad702c3 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_UNSIGNED: + inform (loc, " %qT is not an unsigned type", t1); + break; case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b2be7b7bbd7..0603b4a230f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -94,6 +94,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_UNSIGNED, "__is_unsigned", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 9050c36f105..90d05bca5c1 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -74,6 +74,7 @@ struct cp_trait { "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_unsigned", CPTK_IS_UNSIGNED, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 31fd5075f2d..75ab2b5edfa 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 97, duplicates = 0 */ +/* maximum key range = 129, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, - 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, - 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, - 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104 + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, + 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, + 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, + 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136 }; unsigned int hval = len; @@ -116,46 +116,44 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 59, + TOTAL_KEYWORDS = 60, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 103 + MAX_HASH_VALUE = 135 }; static const struct cp_trait wordlist[] = { -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 86 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, @@ -165,11 +163,11 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -180,7 +178,7 @@ cp_trait_lookup::find (const char *str, size_t len) #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, #line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -207,6 +205,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" @@ -223,8 +223,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 70 "../../gcc/cp/cp-trait.gperf" @@ -242,19 +242,23 @@ cp_trait_lookup::find (const char *str, size_t len) #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, - 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, - 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, + 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, + 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58 + -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index deab0134509..14387821b85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12250,6 +12250,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_IS_VOLATILE: return CP_TYPE_VOLATILE_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4bc85f4babb..3d380f94b06 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..2bb45d209a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Wed Oct 11 21:46: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: 151584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp844354vqb; Wed, 11 Oct 2023 15:10:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaT0Xtn0DvKOm3WHRp2bGWLa0ODmSQAZHGCfoieXCE9pO6X6phvPaQgzbHX0bKiotgFzKw X-Received: by 2002:a50:d0d4:0:b0:53d:a17a:7576 with SMTP id g20-20020a50d0d4000000b0053da17a7576mr5643900edf.8.1697062246536; Wed, 11 Oct 2023 15:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062246; cv=none; d=google.com; s=arc-20160816; b=Jf/MSLrVRU8XgaAWfo3Zgw2SZropw3Wi8/NVrdHl8HV7oc1jOKtqBsoxsKCS+L/QKi IEOuTU3IvpF7F9jnLLnyD2DjOLHQlzF08oLPrc1bMVgA74MGSsVhoedMrqwR8KQHLJtP XfRUDjesnytPqLrVVtze0C/ouxPUzV9KjyM3Nd4pj7Ljl8mxEdkxbZmTF6hhpGXn1HS+ 6iphd32uAwE9WruyjM1+cY9zsejVbw08ZEIPsHNiAMlzkb9+qFBVt+9JVXMUmxgmydmH v5IjQN0mzYLCqvvmR7xZt0+bF88zygU3ZXTkEAm4LvhzfoIknEpM6p8y5st/Cpsd7gh/ 74/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=OojgHYdoZ2rNEbr9HY2sF2duLmcdRKiiE7iMfM5r3aGsFZDeb8Ojig3JbDP3x+EXRo VMwftsSCsSwoBgWMOiZbrSn1+L1/Po/agigK2FlbHZtJYNUf90ElSexGnec3lD2JlJMu tYyYYU6BQE2D/NmUWAJVOy5tUBp/WFhMOeT6PPIm3EC1QwaZB+0octOFWYOD8lnCD058 F+iXGT0XUtZqMAJOFSNeg9Lob/VgZ9rRL8aXYEPN7vtFbbyMyyJPBlW8y6lasgvMGojP aQ9fPd3/7TneJuiQOI1s32tltzgxhZE5HWVzWGc0A4PJe+Ln1iRoEXCfsyF2qurzAHcE YCZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CgyYeo9v; 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 n9-20020a056402060900b0053df87f8304si407832edv.528.2023.10.11.15.10.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:10:46 -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=CgyYeo9v; 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 A3768381DC1F for ; Wed, 11 Oct 2023 21:59:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3768381DC1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061548; 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=CgyYeo9vjvfDFjlmQyIOPo/T6qGEdaGai2TTllNwY9yb5IDm0T5ZTwk+AcitaBQ2a 0cCHWZfU21QhgRh94cy9czp8onh8BA7OA3V+NjmG3kIk3xlVUhA0m7Ajay1sRfsJk+ pWJqfr9M2N0Ch1aC6cVkSh2QYF/PuS9/BNgbBsLQ= 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 AB5453861889; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB5453861889 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLpMRr006695; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnxt7kyt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:58 +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 39BLsk1u020906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5b021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 35/39] libstdc++: Optimize is_unsigned trait performance Date: Wed, 11 Oct 2023 14:46:11 -0700 Message-ID: <20231011215049.1052142-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ejzwVfDjFsJnYJBuIpU-YQHUjR7UXX1I X-Proofpoint-GUID: ejzwVfDjFsJnYJBuIpU-YQHUjR7UXX1I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1034 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=751 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1776995061376064333 X-GMAIL-MSGID: 1779498742124872442 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 Wed Oct 11 21:46: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: 151609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp853879vqb; Wed, 11 Oct 2023 15:34:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoyJlrcmQ2+CRDMFSxoZEOi8GOGshL8FSMvcQbOz6HY+zfq0sFzGJgiEkFeWJuAHuNRePi X-Received: by 2002:a17:906:209:b0:9a9:e5bb:eddc with SMTP id 9-20020a170906020900b009a9e5bbeddcmr21550209ejd.16.1697063657713; Wed, 11 Oct 2023 15:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063657; cv=none; d=google.com; s=arc-20160816; b=XNKsFHc96C8WOEf20dLZCTP3kexIihMmKzT1cZ8wCqdIE0x4auTlhH9+xooS6rseSt QJ7YLqSVTgganJOg9ReXu/zntRtQpz194nCDiabE5woRHUMVUUjadM2zyu1mNkulnpJw csu/iAjSf0W2lyNlfgswkq8r9079q30gP1H/0UyGFoEs+RXvzk26Gbp8z33ZoGHwkriA 678fGeEVMfjML6Y0brgfxO2wneWbyPR7O/d5lJ2va1M2EooJou8j0hmgZGdePoNHS4bO HNuRQl51jBnAo9HMiJd0tkjmSkLEADJAbrojEjHV6bSknbSsajlTYjcXR14X43Nip1C+ OOyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MvxE1C8WtX6t/vNlmycNSpOrQHQJhLjVX0DErHPzoac=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=UZNg5uPamthPNHjOOOywZnYt5mMskSJ20skXkGGiNsFYfbFj8mx3hIP8HWVppxs499 bkw2++dhPH/Tj/zsq+a9mdIM7SxdrwBLuI0VKdYUVSpRcEFyXRF2aPOSxJ4J4ZB9dfx2 1XCljykJt+GpTqquB54BFvX7ZLcwCBX7okCNlLaASoDx6UZLvbXkRPHsrrBqP1tL+VO2 oeL7jcPvjjm9ABiuyXrHSyYeTSGBuMx4+ESpOhkI/FrcrFksk5POMh6Zei6hsidJ9icp 726UrBuAFHHlOaSPorMhQo6DY/9Q5hGFLNt+y/I2JlTphYTzSUNfb/lkGObcqGBuyaEs yEcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gZEBgQZa; 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 k13-20020a1709065fcd00b009a5f7fb51cdsi6914091ejv.873.2023.10.11.15.34.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:34:17 -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=gZEBgQZa; 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 4D99139C0AD6 for ; Wed, 11 Oct 2023 22:06:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D99139C0AD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697062016; bh=MvxE1C8WtX6t/vNlmycNSpOrQHQJhLjVX0DErHPzoac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gZEBgQZaIaUFzKQNLDQWd71BvI/xt1Jekc1Piek05nLU7VRfmP51duvHvr96i4LL3 cDGr7jJdoT38Jx8zp6cI/pYaxA3xpx3NhR2PlyFKjGFATir/Bl2xZBaVqKNKl9NMHm UqHJuRI/1RGTDxZB4hebxC81PV+VCblMuLTPfOvM= 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 2D9453875468; Wed, 11 Oct 2023 21:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D9453875468 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLqO3d026934; Wed, 11 Oct 2023 21:55:00 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnyjvu89e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:00 +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 39BLskkr025752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5c021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 36/39] c++, libstdc++: Implement __is_signed built-in trait Date: Wed, 11 Oct 2023 14:46:12 -0700 Message-ID: <20231011215049.1052142-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: em4KEbVMksFkyy75qbZXr0-VYmXvxXiG X-Proofpoint-ORIG-GUID: em4KEbVMksFkyy75qbZXr0-VYmXvxXiG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 malwarescore=0 suspectscore=0 clxscore=1034 adultscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110191 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995210539754822 X-GMAIL-MSGID: 1779500222188436702 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. * g++.dg/tm/pr46567.C (__is_signed): Rename to ... (__is_signed_type): ... this. libstdc++-v3/ChangeLog: * include/ext/numeric_traits.h (__is_signed): Rename to ... (__is_signed_type): ... this. * include/bits/charconv.h: Use __is_signed_type instead. * include/bits/locale_facets.tcc: Likewise. * include/bits/uniform_int_dist.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 211 ++++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_signed.C | 47 +++++ gcc/testsuite/g++.dg/tm/pr46567.C | 12 +- libstdc++-v3/include/bits/charconv.h | 2 +- libstdc++-v3/include/bits/locale_facets.tcc | 6 +- libstdc++-v3/include/bits/uniform_int_dist.h | 4 +- libstdc++-v3/include/ext/numeric_traits.h | 18 +- 12 files changed, 186 insertions(+), 126 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28dad702c3..b161c9b2c9e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0603b4a230f..b0faa4c8937 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90d05bca5c1..de0ba162e7a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 75ab2b5edfa..6d1078de2fe 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 129, duplicates = 0 */ +/* maximum key range = 119, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, - 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, - 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, - 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136 + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, + 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, + 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, + 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126 }; unsigned int hval = len; @@ -116,149 +116,150 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 60, + TOTAL_KEYWORDS = 61, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 135 + MAX_HASH_VALUE = 125 }; static const struct cp_trait wordlist[] = { -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 83 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_signed", CPTK_IS_SIGNED, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 36 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 37 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, - 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, - -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 + 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, + 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, + -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, + -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, + -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, + -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 14387821b85..5e6b2ca37ac 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 79d304e0309..c891aff20f4 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -403,7 +403,7 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { { static const _Value __min = (((_Value)(-1) < 0) ? (_Value)1 << (sizeof(_Value) * 8 - ((_Value)(-1) < 0)) : (_Value)0); static const _Value __max = (((_Value)(-1) < 0) ? (((((_Value)1 << ((sizeof(_Value) * 8 - ((_Value)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(_Value)0); - static const bool __is_signed = ((_Value)(-1) < 0); + static const bool __is_signed_type = ((_Value)(-1) < 0); static const int __digits = (sizeof(_Value) * 8 - ((_Value)(-1) < 0)); }; template @@ -411,21 +411,21 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { template const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; template struct __numeric_traits_floating { static const int __max_digits10 = (2 + (std::__are_same<_Value, float>::__value ? 24 : std::__are_same<_Value, double>::__value ? 53 : 64) * 3010 / 10000); - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = (std::__are_same<_Value, float>::__value ? 6 : std::__are_same<_Value, double>::__value ? 15 : 18); static const int __max_exponent10 = (std::__are_same<_Value, float>::__value ? 38 : std::__are_same<_Value, double>::__value ? 308 : 4932); }; template const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; template @@ -1513,8 +1513,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value - && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed - && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed_type + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed_type && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index 20da8303f7a..1acf1e46e4c 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -46,7 +46,7 @@ namespace __detail // This accepts 128-bit integers even in strict mode. template constexpr bool __integer_to_chars_is_unsigned - = ! __gnu_cxx::__int_traits<_Tp>::__is_signed; + = ! __gnu_cxx::__int_traits<_Tp>::__is_signed_type; #endif // Generic implementation for arbitrary bases. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6bfff7d6289..38a6920abe9 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -470,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL bool __testfail = false; bool __testoverflow = false; const __unsigned_type __max = - (__negative && __num_traits::__is_signed) + (__negative && __num_traits::__is_signed_type) ? -static_cast<__unsigned_type>(__num_traits::__min) : __num_traits::__max; const __unsigned_type __smax = __max / __base; @@ -573,7 +573,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL } else if (__testoverflow) { - if (__negative && __num_traits::__is_signed) + if (__negative && __num_traits::__is_signed_type) __v = __num_traits::__min; else __v = __num_traits::__max; @@ -914,7 +914,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL if (__v >= 0) { if (bool(__flags & ios_base::showpos) - && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) + && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed_type) *--__cs = __lit[__num_base::_S_oplus], ++__len; } else diff --git a/libstdc++-v3/include/bits/uniform_int_dist.h b/libstdc++-v3/include/bits/uniform_int_dist.h index 7ccf930a6d4..73b808e57f3 100644 --- a/libstdc++-v3/include/bits/uniform_int_dist.h +++ b/libstdc++-v3/include/bits/uniform_int_dist.h @@ -258,8 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using _Up_traits = __gnu_cxx::__int_traits<_Up>; using _Wp_traits = __gnu_cxx::__int_traits<_Wp>; - static_assert(!_Up_traits::__is_signed, "U must be unsigned"); - static_assert(!_Wp_traits::__is_signed, "W must be unsigned"); + static_assert(!_Up_traits::__is_signed_type, "U must be unsigned"); + static_assert(!_Wp_traits::__is_signed_type, "W must be unsigned"); static_assert(_Wp_traits::__digits == (2 * _Up_traits::__digits), "W must be twice as wide as U"); diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index dcbc2d12927..c618f211775 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -67,15 +67,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: these two are also available in std::numeric_limits as compile // time constants, but is big and we can avoid including it. - static const bool __is_signed = (_Value)(-1) < 0; + static const bool __is_signed_type = (_Value)(-1) < 0; static const int __digits - = __is_integer_nonstrict<_Value>::__width - __is_signed; + = __is_integer_nonstrict<_Value>::__width - __is_signed_type; // The initializers must be constants so that __max and __min are too. - static const _Value __max = __is_signed + static const _Value __max = __is_signed_type ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1) : ~(_Value)0; - static const _Value __min = __is_signed ? -__max - 1 : (_Value)0; + static const _Value __min = __is_signed_type ? -__max - 1 : (_Value)0; }; template @@ -85,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; @@ -161,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -170,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; @@ -210,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ibm128> { static const int __max_digits10 = 33; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 31; static const int __max_exponent10 = 308; }; @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ieee128> { static const int __max_digits10 = 36; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 33; static const int __max_exponent10 = 4932; }; From patchwork Wed Oct 11 21:46: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: 151600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp850950vqb; Wed, 11 Oct 2023 15:26:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkC2bKJwEduzEJG8SMQrILFte1f+oNX83mGfHDJ7fVbd4VWEUw9ChnbgYyuhEU9Vvh1pqA X-Received: by 2002:a17:906:844c:b0:9a5:cab0:b050 with SMTP id e12-20020a170906844c00b009a5cab0b050mr18756655ejy.13.1697063217273; Wed, 11 Oct 2023 15:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697063217; cv=none; d=google.com; s=arc-20160816; b=LmzKN7eqjZg7UnyL16s9AwyPRLNhtAFbYYWoomGCFjPa8NWGDjCL/MAXS5y+wgGbFJ AQrSEE14edTlpfKr460b4R5VEKAjXd3117rEjSA/nFfPUdpL44NBlYxLMDSIWHYbiprJ szTctMdgsNjMGsyzOffCiH8FoRG45ZYPQJq6GyPEGNA8+7CWSX/FVsU3MqNqWXkTqL2O AP6cYzwa2fOUPf1Jb0Z70dKNHg816DCj3xQgT4odrVsl5XHuUAqfZk/UIvUJV2Ma0xsZ NLkkSv1/wMll8cC6KhSmlhm8huHFrBmUIPJW9dFPKNN1vSDT1MpV/NW/ToQpCPAX36/C bSDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Mk1fYvg5zbhufzbDzMxGGqAjPZLdfE243o7gmOf1nSPZPGXGfu6F+rEeWgjXYYLho6 WcyitbtaCJ9Z5k6PM5i5eiKZza7eDgw+Bgh3MPiDF0m6neBlVTXn49lhcbQXh/YTF7eh G4SzTGd7iQqli8Y5nl4cvs0hn1/weoPyzcHxPimHyzRDjV95M5BsszhPc/7i1MR9crWY 51xTx9L8ExAhQEyldN1nwhLMfXmFfOkQX4pNLUcUBgDGUkWJ7WuIAQPwHwqi1SkGeQKw dVWG/56BAQXQOX5KFHEMxzGSMAM7WxH/K9U26CQUijk1d64BP2tUmTKdUCLPhTGWDbkC Vz2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Zj2QYLfz; 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 bq20-20020a170906d0d400b009a1a248ae6fsi7036966ejb.876.2023.10.11.15.26.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15: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=Zj2QYLfz; 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 6015B3952000 for ; Wed, 11 Oct 2023 22:04:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6015B3952000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061851; 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=Zj2QYLfzGmUaX3KynMo8h9Mq7U+G6cSJ3q1KCNi5oNJKuUCnylkYKVu4rP3NvturN HwQjgawt+76jR7WqgtIgjz0HfUuKVz9A+oFk1lUT8fgL3wL3UnklyMNwT37ikPTxH6 FeermD7bwoC/MLv0vQYAMYwKUOKAgIQAaz2c1oVk= 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 0927E3820550; Wed, 11 Oct 2023 21:54:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0927E3820550 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLdvxj004289; Wed, 11 Oct 2023 21:54:59 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnjfffcgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:59 +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 39BLskHZ027611 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5d021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 37/39] libstdc++: Optimize is_signed trait performance Date: Wed, 11 Oct 2023 14:46:13 -0700 Message-ID: <20231011215049.1052142-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: HWvFfoXTYq0XzcmPr62GtG6rBfBo1j9P X-Proofpoint-ORIG-GUID: HWvFfoXTYq0XzcmPr62GtG6rBfBo1j9P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=608 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1034 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110192 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: 1779499760038640576 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 Wed Oct 11 21:46: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: 151578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp840841vqb; Wed, 11 Oct 2023 15:03:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH734cMzF7FfNmbVqYuNbwqgma6TAXWRNjM0wJPj8hFRNvta2izYerV5MAZ7ip1bkwdBeHI X-Received: by 2002:adf:a44c:0:b0:32d:86a:1b69 with SMTP id e12-20020adfa44c000000b0032d086a1b69mr5262679wra.66.1697061830776; Wed, 11 Oct 2023 15:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697061830; cv=none; d=google.com; s=arc-20160816; b=dsI2voRsLrCiOLYTjUb3HMDdzLFmUE/HotytMUiWAe2curg+930CA9E3IaqWWCY89D tOZBhAazMeQ0yE5AGXBcTseJwbyEBA098FftIKsTDZhZlagQ3DX9cMcrXQXgIsjOti6p vuaNPI34a15aG9lqr/XRmYnKyU740WN0yH+vXzlisccoeGAnViRxVUFbvfYw0dkkLSwc o8KPaDvOQ/hDBdQfD0U7VPEd716281YCqo7s35cGqZK1dkSj6Djjh4kE8v6yD/rL89zc /isAkqgw40Mzqg2TD3JvqBhlYDYd4U1GPVXK0Ob429P6bdkpfrf5MR593kcgKkses4u2 Abew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=u3IHJP5wQ7IBv9sRa6bDnOneo4iJ+Ipa3EdItoNbops=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=P62TCzI3Yj7i1/y7e8IMd7AQ5+gbvp22UivBNQe7PB6cjxQkHKleT4OqbV5+06t030 xJZhhKpH45aWZRw3ke3Px5dUZgak8cu48pOFaXqh6azeByMQKn1ntGzmY7F2kl1DzPKy 3AzFeR6UMKbVrYK2Ep0EUZRuy+bBCVeQdp2NunVcvttenjjP2W1Z++BajZECCZVLjn2x DlxKB8f2XfBTZaELcDfVipHLnDbSsQy4vqrRgzaVOghhO0TTVRvvkM6qDueTqiA9MkS4 qbGFg4g/nk+AXb4/eaZ4Q9Dq+m9lFuQQ08SygYrVJpuVnoosViCKoKY84RcJ1dZ8t96I g7jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NvDCD3hR; 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 o1-20020aa7d3c1000000b0052fb42bee81si6614884edr.609.2023.10.11.15.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:03:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NvDCD3hR; 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 560F3394D8E0 for ; Wed, 11 Oct 2023 21:57:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 560F3394D8E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061434; bh=u3IHJP5wQ7IBv9sRa6bDnOneo4iJ+Ipa3EdItoNbops=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NvDCD3hRoFmIxqJURR/6tNXTR6YSDcLEO1/LCkkfnEbmswmkWuoWd8b03clHE2FFw ZAtLGslZyuMmH2jrDlbUpqtDSkx47ui9PTVuCdh40d7PWyob/BOkx/9N5v/aCGJ6jp Pp92VqAL1CpA/pKHhgU0TJxi28QIRQUqvD7PeSgE= 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 9FB1B38207E4; Wed, 11 Oct 2023 21:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FB1B38207E4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLs2PA003866; Wed, 11 Oct 2023 21:54:56 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tnpvsq9b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:54:56 +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 39BLskOG014006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5e021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 38/39] c++, libstdc++: Implement __is_scalar built-in trait Date: Wed, 11 Oct 2023 14:46:14 -0700 Message-ID: <20231011215049.1052142-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: yxOt5GLgbLsewn5VI2hcgQqNvSpKKBLw X-Proofpoint-GUID: yxOt5GLgbLsewn5VI2hcgQqNvSpKKBLw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 clxscore=1034 adultscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995829165627138 X-GMAIL-MSGID: 1779498306391017583 This patch implements built-in trait for std::is_scalar. The existent __is_scalar codes were replaced with __is_scalar_type to avoid unintentional macro replacement by the new built-in. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scalar. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar. * g++.dg/ext/is_scalar.C: New test. * g++.dg/tm/pr46567.C: Use __is_scalar_type instead. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_scalar): Rename to ... (__is_scalar_type): ... this. * include/bits/stl_algobase.h: Use __is_scalar_type instead. * include/bits/valarray_array.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 186 ++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scalar.C | 31 ++++ gcc/testsuite/g++.dg/tm/pr46567.C | 10 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 2 +- libstdc++-v3/include/bits/stl_algobase.h | 8 +- libstdc++-v3/include/bits/valarray_array.h | 2 +- 12 files changed, 150 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b161c9b2c9e..78f100d2745 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SIGNED: inform (loc, " %qT is not a signed type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b0faa4c8937..08a2780c929 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index de0ba162e7a..ef51c713c58 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scalar", CPTK_IS_SCALAR, 1, false "__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 6d1078de2fe..8c68af420f9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -78,10 +78,10 @@ cp_trait_lookup::hash (const char *str, size_t len) 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, - 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, - 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, - 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 40, 126, 25, 21, 50, + 0, 0, 30, 10, 126, 0, 126, 126, 25, 5, + 50, 0, 61, 126, 10, 10, 5, 0, 15, 126, + 126, 5, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 61, + TOTAL_KEYWORDS = 62, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,141 +125,143 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 84 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 89 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 68 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_signed", CPTK_IS_SIGNED, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 33 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 32 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_scalar", CPTK_IS_SCALAR, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, - 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, - -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, - -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, - -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, - -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, 6, 7, 8, 9, -1, -1, -1, 10, 11, -1, 12, 13, + 14, 15, 16, 17, -1, 18, -1, 19, 20, 21, 22, 23, 24, 25, + 26, 27, -1, 28, 29, 30, 31, 32, 33, -1, 34, 35, 36, 37, + -1, -1, 38, -1, 39, -1, -1, -1, 40, 41, -1, -1, 42, 43, + 44, 45, -1, 46, 47, 48, -1, -1, 49, 50, 51, 52, -1, -1, + -1, 53, -1, -1, -1, -1, 54, -1, -1, 55, -1, -1, -1, -1, + 56, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, 58, -1, + -1, -1, -1, -1, 59, -1, 60, -1, -1, -1, -1, -1, -1, 61 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5e6b2ca37ac..be345f9aa47 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_SIGNED: return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; @@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index c891aff20f4..393f936ea72 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { : public __traitor<__is_void<_Tp>, __is_arith<_Tp> > { }; template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; template @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, ++__first) @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index da592b9fd23..4d2ef002e08 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arith : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { + template struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template inline typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) { } - template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { + template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (__decltype(__n + 0) __niter = __n; __niter > 0; --__niter, ++__first) *__first = __value; diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 51ed5b07716..16980f5b356 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -397,7 +397,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // A scalar type is an arithmetic type or a pointer type // template - struct __is_scalar + struct __is_scalar_type : public __traitor<__is_arith<_Tp>, __is_ptr<_Tp> > { }; diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index d1438429487..4e334da0832 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -914,7 +914,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -925,7 +925,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1063,7 +1063,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, (void) ++__first) @@ -1074,7 +1074,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_scalar_type<_Tp>::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 222fd5fd900..558817329ce 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void __valarray_default_construct(_Tp* __b, _Tp* __e) { - _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e); + _Array_default_ctor<_Tp, __is_scalar_type<_Tp>::__value>::_S_do_it(__b, __e); } // Turn a raw-memory into an array of _Tp filled with __t From patchwork Wed Oct 11 21:46:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 151589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp848415vqb; Wed, 11 Oct 2023 15:20:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhgD4KLq1Te8ZG0nLY3R7JkUpAa6wrIy/ZZuVphpcsc0I6NwTsrYpF7ptUyIj9R7XDP6KZ X-Received: by 2002:a17:906:23ea:b0:9b7:37de:601a with SMTP id j10-20020a17090623ea00b009b737de601amr18217817ejg.49.1697062826296; Wed, 11 Oct 2023 15:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697062826; cv=none; d=google.com; s=arc-20160816; b=MxlxeD4ZyAwEugKfBMH809mn6+Qr9MyMSPINykPFCW62SKJgcSKjWByNeT7ts/meZS Xq75cV9kGkNVyx9p/xlSVXlW9e9WWhexaqcUPmXASatFhhFxO+9t7THnWSFDVQFT5bYS lQN5lsmbG8FkIUd0YKIV/KwPDLmsOu3WHyOk3qFz+ddXX24vV2lS3eZCgdxrdxv5LvET dF1r+IsyX5NdwrTuE3ZfbUGX3kd8W0cEAOzciNpVUREsSJOcqXR5u6fuZmqyHPA7I0hB PkPaBofegd++25F0YuyoDMnba+fj86+7I4abaFV8BNd58NV46xRGJEwY3Y+QeNXcoHon Hpjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yPPqHplE33ES5uPCNOG5OVpY2LaS+1afB07UD9n3FC7Gk1wj/mc6EEosFZeSBsXOgq CDoPxUnKbGiXZkhZxRkBsxp6Nr++OIEbtz1pMn2cFmsdzLN1LFY3sqqTmC55cW1qVxuz atztnFgxIa2BF25zIXgQBxZJRfQAFyEmk6PeDesuID5E8KMiP6WabTeCQP1r6FMz+crE p7TmMpub1YJkf9ap+OGu2NiGHx4y/iuKFgTF/39sGQXO/ShV3p7n9ywNfbEMOvJAEYlU mcizbx3Vh3SVaFLUd3iv2QCYoiYSzoZFfIcvuSuSzTrpJc43mJ7mR3utUZhBxvj1P1Bx tOuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Npe6NC4T; 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 j25-20020a1709064b5900b0098e2a30ec3asi6678237ejv.385.2023.10.11.15.20.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:20:26 -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=Npe6NC4T; 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 0DFD63A4E9F3 for ; Wed, 11 Oct 2023 22:01:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DFD63A4E9F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697061709; 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=Npe6NC4TknXX1PCP3wIoNdTkoTygTIDjrd3yMxOcL2Y0IpyG+kbQ+YjyhmbdoO+pk 5VOJfsPcASUS4pNctvNacP0re9ZHqu0WO9DE0J+YfXu0hpCJOuvkmoQ5mL7HoNDn2p 0pCXcixNtkIm9GnaO9qazaOXwsejE7l8oWuQ1jtY= 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 E64D93888C42; Wed, 11 Oct 2023 21:55:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E64D93888C42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39BLiE8o001354; Wed, 11 Oct 2023 21:55:20 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tp2jx90jm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 21:55:19 +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 39BLsk2r031154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 14:54:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39BLoq5f021017 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 14:54: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 v17 39/39] libstdc++: Optimize is_scalar trait performance Date: Wed, 11 Oct 2023 14:46:15 -0700 Message-ID: <20231011215049.1052142-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011215049.1052142-1-kmatsui@gcc.gnu.org> References: <20231010221520.3680267-1-kmatsui@gcc.gnu.org> <20231011215049.1052142-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: TiHZGfv_H71OZ-tHy0lONhvIjsxJ38jZ X-Proofpoint-GUID: TiHZGfv_H71OZ-tHy0lONhvIjsxJ38jZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-11_17,2023-10-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=672 adultscore=0 impostorscore=0 clxscore=1034 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110193 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: 1776997480812710190 X-GMAIL-MSGID: 1779499350051221927 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>;