From patchwork Fri Oct 13 22:37:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2191284vqb; Fri, 13 Oct 2023 15:41:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0dbubpj3cbDmp4yCIYkA7fvA9D0IaeHo943WRsViELjCuQD6B3dsnR6uWa+V+WRCkIhQa X-Received: by 2002:a37:ad0a:0:b0:774:212c:3dc9 with SMTP id f10-20020a37ad0a000000b00774212c3dc9mr27287632qkm.44.1697236893570; Fri, 13 Oct 2023 15:41:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697236893; cv=pass; d=google.com; s=arc-20160816; b=DLqYTQEJbfccxIwO1mMs3uVVVa4QWQlvLw1x9WLmtMNkk6IHm48PunFoiwTq6nko7o AMPMKS+oAJpUNExATOvuF4wq9GNwB0J9QNDsWGqErh/Xwd7iKKzYp20CniPRvlNZK1is AoZZnEuxWWnaDmPZoa3rqxHRzFVGIZlbXU/aIdAg5ncxZ5Cnel0jqT/sA+MnbUwj8kdU i5HWn4PW54D7WW9+KiQlb5SNxtZ0GqaHeBjeeXmyAVcgRO1/CDrvM24tyAnMw2j2yUKu o70g2Nlh6qrb8Z6Jj56ycLAd7RnWTrvCimiAAUrJ3O+t5AGpfOTDOGkfX+mzb0IG+kag +dcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=MKW1Ac2+4canAboK7rFTyrtkRq5Md4dhsl2QPGign68=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=A0tpfK1HJ1hNvgJgOpAkySmgPQdauJwEdPjrgZKVM42vg/pKIRD0LAq+WlnQp+ROvd shbyc3I9N6ieDLZYwtkPVhVTkTFcp67e2Mn8wJY6GD62nBwvw8ie9i4lOF6x2iXofw/x SpM7D3+ARwEI5tvK3ULTwqdTe6Xws6mhOgbtCu5Hp8fmGsw1Og0c+FDOoIlDQ932kwzL s1C2jF+VL9wg9l3gqlq8uq0wwsPCzrS/EMxCRdA6r9Nm7nSDQxSqdWBL73xKOj5ApK4J NVnECL4io6iF5nCFxsCqXY7GL4J08QK/sS9SLMa7wWmHllF87PWzi4F3WABs9V94VImj 6EOg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cXqpNPZy; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x14-20020a05622a000e00b00417b768db1csi1953564qtw.609.2023.10.13.15.41.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:41: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=cXqpNPZy; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 378133856951 for ; Fri, 13 Oct 2023 22:41:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 378133856951 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236893; 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=cXqpNPZyho50TLtOPKOPTUNHQzGMDGpQ8Fdyndif+22Eho1d4OKi8Wpb4GFQ3Gs+f L0agcK2I+3joUAXsfMlUootb0QOaBQvQRgmORoUbyZeAy+uWtenVnfuFDdM1iKxwfK nD/OWyxOStA5YnI0UvAgM7IQ/7vx/ionH/vaEUvU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 125C23857715; Fri, 13 Oct 2023 22:40:46 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 125C23857715 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236848; cv=none; b=tcwWnIO3K4e25JAk3DRUvTRmh5ssEE88cQShLJHuUBafGm/V4twIA96o+fp4JjhaRxtQDQfseQtZ/Epogsk7PG0DRL22WljZCzEZgbywL7s6+E4Q9qsIxaKoV6F5feRL4NIrsvf2YiIYCKDvo6tJxsnBgmqzht9C0+N6aU6klpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236848; c=relaxed/simple; bh=ueEU7MagjimKlE470j5C66f9EXtFDtKqz5Vv0AXZdoI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nARZS1QI0bLw+JWkbL1ZBqOnBMt8CTLeWfkigHhnEd5BRDbnPEpC/o19QnwogE9oMN/PF7wxap6BkLmjvKWxKtdj4yLtZRL2bviPwgCTBQiTMNiFfhXEli4J88yGZdY4AycDec/5zEDnYezpvaxupkbFKV2FwgJHpBGofW9j65w= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 125C23857715 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMSiAo005025; Fri, 13 Oct 2023 22:40:45 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209m94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:40:45 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMeSUT002795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:40:28 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1E016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:40:27 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 01/40] c++: Sort built-in traits alphabetically Date: Fri, 13 Oct 2023 15:37:15 -0700 Message-ID: <20231013223957.1634024-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Etx33ZiTjClhlsjjrsOZyQG4Da4vO_f2 X-Proofpoint-GUID: Etx33ZiTjClhlsjjrsOZyQG4Da4vO_f2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779497639605776976 X-GMAIL-MSGID: 1779681872952994736 This patch sorts built-in traits alphabetically for better code readability. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Sort built-in traits alphabetically. * cp-trait.def: Likewise. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. (finish_trait_type): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Sort built-in traits alphabetically. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 68 ++++++++--------- gcc/cp/cp-trait.def | 10 +-- gcc/cp/semantics.cc | 94 ++++++++++++------------ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 70 +++++++++--------- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9e4e7043cd..722fc334e6f 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3702,18 +3702,36 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_HAS_TRIVIAL_DESTRUCTOR: inform (loc, " %qT is not trivially destructible", t1); break; + case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: + inform (loc, " %qT does not have unique object representations", t1); + break; case CPTK_HAS_VIRTUAL_DESTRUCTOR: inform (loc, " %qT does not have a virtual destructor", t1); break; case CPTK_IS_ABSTRACT: inform (loc, " %qT is not an abstract class", t1); break; + case CPTK_IS_AGGREGATE: + inform (loc, " %qT is not an aggregate", t1); + break; + case CPTK_IS_ASSIGNABLE: + inform (loc, " %qT is not assignable from %qT", t1, t2); + break; case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not default constructible", t1); + else + inform (loc, " %qT is not constructible from %qE", t1, t2); + break; + case CPTK_IS_CONVERTIBLE: + inform (loc, " %qT is not convertible from %qE", t2, t1); + break; case CPTK_IS_EMPTY: inform (loc, " %qT is not an empty class", t1); break; @@ -3729,6 +3747,18 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_NOTHROW_ASSIGNABLE: + inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); + break; + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + if (!t2) + inform (loc, " %qT is not nothrow default constructible", t1); + else + inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); + break; + case CPTK_IS_NOTHROW_CONVERTIBLE: + inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + break; case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: inform (loc, " %qT is not pointer-interconvertible base of %qT", t1, t2); @@ -3748,50 +3778,20 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIAL: inform (loc, " %qT is not a trivial type", t1); break; - case CPTK_IS_UNION: - inform (loc, " %qT is not a union", t1); - break; - case CPTK_IS_AGGREGATE: - inform (loc, " %qT is not an aggregate", t1); - break; - case CPTK_IS_TRIVIALLY_COPYABLE: - inform (loc, " %qT is not trivially copyable", t1); - break; - case CPTK_IS_ASSIGNABLE: - inform (loc, " %qT is not assignable from %qT", t1, t2); - break; case CPTK_IS_TRIVIALLY_ASSIGNABLE: inform (loc, " %qT is not trivially assignable from %qT", t1, t2); break; - case CPTK_IS_NOTHROW_ASSIGNABLE: - inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); - break; - case CPTK_IS_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not default constructible", t1); - else - inform (loc, " %qT is not constructible from %qE", t1, t2); - break; case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not trivially default constructible", t1); else inform (loc, " %qT is not trivially constructible from %qE", t1, t2); break; - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - if (!t2) - inform (loc, " %qT is not nothrow default constructible", t1); - else - inform (loc, " %qT is not nothrow constructible from %qE", t1, t2); - break; - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: - inform (loc, " %qT does not have unique object representations", t1); - break; - case CPTK_IS_CONVERTIBLE: - inform (loc, " %qT is not convertible from %qE", t2, t1); + case CPTK_IS_TRIVIALLY_COPYABLE: + inform (loc, " %qT is not trivially copyable", t1); break; - case CPTK_IS_NOTHROW_CONVERTIBLE: - inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); + case CPTK_IS_UNION: + inform (loc, " %qT is not a union", t1); break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..0e48e64b8dd 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -84,14 +84,14 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) -/* FIXME Added space to avoid direct usage in GCC 13. */ -DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) - DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) -DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) -DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) +DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) +DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) + +/* FIXME Added space to avoid direct usage in GCC 13. */ +DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2) /* These traits yield a type pack, not a type, and are represented by cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 80ef1364e33..782aa515da0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12090,15 +12090,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && classtype_has_nothrow_assign_or_copy_p (type1, true)))); - case CPTK_HAS_TRIVIAL_ASSIGN: - /* ??? The standard seems to be missing the "or array of such a class - type" wording for this trait. */ - type1 = strip_array_types (type1); - return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE - && (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) - && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); - case CPTK_HAS_NOTHROW_CONSTRUCTOR: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) @@ -12107,17 +12098,26 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && maybe_instantiate_noexcept (t) && TYPE_NOTHROW_P (TREE_TYPE (t)))); - case CPTK_HAS_TRIVIAL_CONSTRUCTOR: - type1 = strip_array_types (type1); - return (trivial_type_p (type1) - || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); - case CPTK_HAS_NOTHROW_COPY: type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) || (CLASS_TYPE_P (type1) && classtype_has_nothrow_assign_or_copy_p (type1, false))); + case CPTK_HAS_TRIVIAL_ASSIGN: + /* ??? The standard seems to be missing the "or array of such a class + type" wording for this trait. */ + type1 = strip_array_types (type1); + return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE + && (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) + && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1)))); + + case CPTK_HAS_TRIVIAL_CONSTRUCTOR: + type1 = strip_array_types (type1); + return (trivial_type_p (type1) + || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1))); + case CPTK_HAS_TRIVIAL_COPY: /* ??? The standard seems to be missing the "or array of such a class type" wording for this trait. */ @@ -12131,18 +12131,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1))); - case CPTK_HAS_VIRTUAL_DESTRUCTOR: - return type_has_virtual_destructor (type1); - case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: return type_has_unique_obj_representations (type1); + case CPTK_HAS_VIRTUAL_DESTRUCTOR: + return type_has_virtual_destructor (type1); + case CPTK_IS_ABSTRACT: return ABSTRACT_CLASS_TYPE_P (type1); case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ASSIGNABLE: + return is_xible (MODIFY_EXPR, type1, type2); + case CPTK_IS_BASE_OF: return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) @@ -12151,6 +12154,12 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONSTRUCTIBLE: + return is_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_CONVERTIBLE: + return is_convertible (type1, type2); + case CPTK_IS_EMPTY: return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1); @@ -12166,6 +12175,15 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: + return is_nothrow_xible (MODIFY_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + return is_nothrow_xible (INIT_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONVERTIBLE: + return is_nothrow_convertible (type1, type2); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12196,24 +12214,6 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; - case CPTK_IS_ASSIGNABLE: - return is_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_CONSTRUCTIBLE: - return is_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_ASSIGNABLE: - return is_nothrow_xible (MODIFY_EXPR, type1, type2); - - case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - return is_nothrow_xible (INIT_EXPR, type1, type2); - - case CPTK_IS_CONVERTIBLE: - return is_convertible (type1, type2); - - case CPTK_IS_NOTHROW_CONVERTIBLE: - return is_nothrow_convertible (type1, type2); - case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12326,9 +12326,9 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ABSTRACT: case CPTK_IS_EMPTY: case CPTK_IS_POLYMORPHIC: - case CPTK_IS_ABSTRACT: case CPTK_HAS_VIRTUAL_DESTRUCTOR: if (!check_trait_type (type1, /* kind = */ 3)) return error_mark_node; @@ -12348,12 +12348,12 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - case CPTK_IS_TRIVIALLY_ASSIGNABLE: - case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: - case CPTK_IS_CONVERTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: + case CPTK_IS_TRIVIALLY_ASSIGNABLE: + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: if (!check_trait_type (type1) @@ -12372,8 +12372,8 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: - case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_UNION: break; case CPTK_IS_LAYOUT_COMPATIBLE: @@ -12436,25 +12436,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { - case CPTK_UNDERLYING_TYPE: - return finish_underlying_type (type1); - case CPTK_REMOVE_CV: return cv_unqualified (type1); - case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return type1; + return cv_unqualified (type1); - case CPTK_REMOVE_CVREF: + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return cv_unqualified (type1); + return type1; case CPTK_TYPE_PACK_ELEMENT: return finish_type_pack_element (type1, type2, complain); + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..2223f08a628 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,9 +8,21 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif @@ -44,12 +56,21 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_convertible) +# error "__has_builtin (__is_convertible) failed" +#endif #if !__has_builtin (__is_empty) # error "__has_builtin (__is_empty) failed" #endif @@ -65,6 +86,15 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_convertible) +# error "__has_builtin (__is_nothrow_convertible) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif @@ -98,51 +128,21 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif -#if !__has_builtin (__underlying_type) -# error "__has_builtin (__underlying_type) failed" -#endif -#if !__has_builtin (__is_assignable) -# error "__has_builtin (__is_assignable) failed" -#endif -#if !__has_builtin (__is_constructible) -# error "__has_builtin (__is_constructible) failed" -#endif -#if !__has_builtin (__is_nothrow_assignable) -# error "__has_builtin (__is_nothrow_assignable) failed" -#endif -#if !__has_builtin (__is_nothrow_constructible) -# error "__has_builtin (__is_nothrow_constructible) failed" -#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif -#if !__has_builtin (__builtin_is_constant_evaluated) -# error "__has_builtin (__builtin_is_constant_evaluated) failed" -#endif -#if !__has_builtin (__builtin_source_location) -# error "__has_builtin (__builtin_source_location) failed" -#endif -#if !__has_builtin (__builtin_is_corresponding_member) -# error "__has_builtin (__builtin_is_corresponding_member) failed" -#endif -#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) -# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" -#endif -#if !__has_builtin (__is_convertible) -# error "__has_builtin (__is_convertible) failed" -#endif -#if !__has_builtin (__is_nothrow_convertible) -# error "__has_builtin (__is_nothrow_convertible) failed" -#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif -#if !__has_builtin (__remove_cvref) -# error "__has_builtin (__remove_cvref) failed" +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" #endif From patchwork Fri Oct 13 22:37:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152793 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2191410vqb; Fri, 13 Oct 2023 15:41:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZrSjcNCNfMo/ka46NO1qys3iPAfryVhU/nqZBDO03lMfF2vW7K3IoguGW/9VLJivm5vbM X-Received: by 2002:a05:620a:2a13:b0:776:f5bb:f2fc with SMTP id o19-20020a05620a2a1300b00776f5bbf2fcmr24900417qkp.9.1697236918581; Fri, 13 Oct 2023 15:41:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697236918; cv=pass; d=google.com; s=arc-20160816; b=gfJrth3K4OdsFCj2Pq3PBORX0k86rGsO/3VRgOHq7bnbETbrNVAs1xWXbxZBJfBlRn 8OIbwBqieQexZrD4GgMlJ6Iub1F4l/om/THu56hF3pVz06zdCxxyWkDyfdSscr9nntK1 4LY7CSGylg15U058X5X+AwdDWd7OKDRZZD5xtID6salBYgR2zfbRM3ucGc2/rUHtAPvS 8PTPOtBdJw4W9Kb0atawJWHeKWK69uuXWOzU+7U6/mSDkRnG+HcM2JeUNlDQDe6PFMY+ e2Q7oIxRYWsCsA6HyVo53j1iest6n0VE0kijGAqgMONn83LHrqBwNhGTnqfnT06lWBhO T/Vg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=/Jev4dHfWGTZBaPM5+Vcm8mAYdnbFOU63YsXlC6lIHo=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=BCU4te99U1uEuOS3qfXS2ohjQqvvbOnYW8IqwgxH45RygM6D7qm5PJ7/Bmxhn+OlvV qHAcTc9QK6WrsOVkl9Anb8de+n5uCcSgqD/6z84bygZlxh/ZDnmf5w9S5FjXfTDJ2Mfb WnV9s+C+pvOumqZXTBdM4R2gCn2K56Kg8Pt0wYxRE4GoiMf2gW22VVCySD0aU5LyI1Wl RLEycXhC6q2Lt7tNDbBbHW1K9gYJ8+xTBvABz9toRoPe9TX8QYUmb/gpxh6biamUxMrI 4Jn/i0BdUO6AFs40gIpSZb79f5QBwFSPTpHDo+1zNVcB/nFsiCNbyyKyJ6oJniJYDIBs N1aQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cSuGR1t+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bq19-20020a05620a469300b00770819cfa28si2055050qkb.656.2023.10.13.15.41.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cSuGR1t+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5A8E3856DC7 for ; Fri, 13 Oct 2023 22:41:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5A8E3856DC7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236917; bh=/Jev4dHfWGTZBaPM5+Vcm8mAYdnbFOU63YsXlC6lIHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cSuGR1t+fse3OCBCrBWqDbOvulycCKipUj++T+PLwkrcT2Br0R4yedRLwOB+zJRQ3 nGgcGtTSm1/yXpls5va4IgMKur/SjZk1X2MEC0mO4NDxwt0H/8qEqMv67AMQgG2SAv oGlWR/ULdTnq8hja7fqAsjllfFbDorQ6OPuuQo2w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 416E1385701E; Fri, 13 Oct 2023 22:41:07 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 416E1385701E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236871; cv=none; b=h1XxWffoQJaPsH97uq0M/qsMO++bxIbTNeJ+qmIubKg6wOoSksJ7TRQ2483l6CcWzl8jH83N1c7ZqcjZ9E6ljw2MIOL7fWOd5fBBzNeMc1+kLbeOrg4vSZqVGy7sZZen6hpN0pjSPmyh61UWhrC8AOP7Cymxq9gZQEmClOe8CRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236871; c=relaxed/simple; bh=8rMhG14aIhD9DTAEYVTpE3L+8lb4pjYaRAWF4qQPl14=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FFDseIWvyfA3RZ1yfB0pXPUBkqeLG6K2mad+WVDuQbkmCynNQQ4DA2XZ4qOdrnXtvlLF6+T08FR/VwyMG0uVUVTdeaC50xUB8uMlVtaHicHePYQidxKe8a9/4Z9CfknnqBrDWLmm8T++AOpZnAtn6Lpic+i3dLGPbwZclcK02xQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 416E1385701E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMQpLj003418; Fri, 13 Oct 2023 22:41:06 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05v37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:41:05 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMewDH000964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:40:58 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1F016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:40:57 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Patrick Palka Subject: [PATCH v19 02/40] c-family, c++: Look up built-in traits through gperf Date: Fri, 13 Oct 2023 15:37:16 -0700 Message-ID: <20231013223957.1634024-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bhjiIWLXe9UWM7Wdi5X7VOasMpF2mWka X-Proofpoint-ORIG-GUID: bhjiIWLXe9UWM7Wdi5X7VOasMpF2mWka X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779408747974559636 X-GMAIL-MSGID: 1779681899178114897 Since RID_MAX soon reaches 255 and all built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses gperf to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * Make-lang.in: Add targets to generate cp-trait.gperf and cp-trait.h. * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait identifier. * cp-tree.h (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (init_cp_traits): New function to set cik_trait for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_lexer_lookup_trait): New function to look up a built-in trait from a token by gperf. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. * cp-trait-head.in: New file. * cp-trait.gperf: New file. * cp-trait.h: New file. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 -- gcc/c-family/c-common.h | 5 - gcc/cp/Make-lang.in | 26 ++++ gcc/cp/cp-objcp-common.cc | 8 +- gcc/cp/cp-trait-head.in | 30 +++++ gcc/cp/cp-trait.gperf | 74 ++++++++++++ gcc/cp/cp-trait.h | 247 ++++++++++++++++++++++++++++++++++++++ gcc/cp/cp-tree.h | 14 ++- gcc/cp/lex.cc | 19 +++ gcc/cp/parser.cc | 132 ++++++++++++-------- 10 files changed, 492 insertions(+), 70 deletions(-) create mode 100644 gcc/cp/cp-trait-head.in create mode 100644 gcc/cp/cp-trait.gperf create mode 100644 gcc/cp/cp-trait.h diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..21fd333ef57 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,13 +508,6 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, - /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..051a442e0f4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 2727fb7f8cc..a67d1c3e9f3 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -34,6 +34,8 @@ # - the compiler proper (eg: cc1plus) # - define the names for selecting the language in LANGUAGES. +AWK = @AWK@ + # Actual names to use when installing a native compiler. CXX_INSTALL_NAME := $(shell echo c++|sed '$(program_transform_name)') GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)') @@ -186,6 +188,30 @@ endif # This is the file that depends on the generated header file. cp/name-lookup.o: $(srcdir)/cp/std-name-hint.h +# We always need the dependency on the .gperf file +# because it itself is generated. +ifeq ($(ENABLE_MAINTAINER_RULES), true) +$(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf +else +$(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf +endif + gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h + +# The cp-trait.gperf file itself is generated from +# cp-trait-head.in and cp-trait.def files. +$(srcdir)/cp/cp-trait.gperf: $(srcdir)/cp/cp-trait-head.in $(srcdir)/cp/cp-trait.def + cat $< > $@ + $(AWK) -F', *' '/^DEFTRAIT_/ { \ + type = (index($$1, "DEFTRAIT_TYPE") != 0 ? "true" : "false"); \ + gsub(/DEFTRAIT_(EXPR|TYPE) \(/, "", $$1); \ + gsub(/\)/, "", $$3); \ + print $$2", CPTK_" $$1", "$$3", "type; \ + }' $(srcdir)/cp/cp-trait.def >> $@ + +# This is the file that depends on the generated header file. +cp/parser.o: $(srcdir)/cp/cp-trait.h + components_in_prev = "bfd opcodes binutils fixincludes gas gcc gmp mpfr mpc isl gold intl ld libbacktrace libcpp libcody libdecnumber libiberty libiberty-linker-plugin libiconv zlib lto-plugin libctf libsframe" components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc libbacktrace libphobos zlib libgomp libatomic" diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..b1adacfec07 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -421,6 +421,10 @@ names_builtin_p (const char *name) } } + /* Check for built-in traits. */ + if (IDENTIFIER_TRAIT_P (id)) + return true; + /* Also detect common reserved C++ words that aren't strictly built-in functions. */ switch (C_RID_CODE (id)) @@ -434,10 +438,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-trait-head.in b/gcc/cp/cp-trait-head.in new file mode 100644 index 00000000000..9357eea1238 --- /dev/null +++ b/gcc/cp/cp-trait-head.in @@ -0,0 +1,30 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf new file mode 100644 index 00000000000..47e3c1af499 --- /dev/null +++ b/gcc/cp/cp-trait.gperf @@ -0,0 +1,74 @@ +%language=C++ +%define class-name cp_trait_lookup +%struct-type +%{ +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +%} +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +%% +"__is_same_as", CPTK_IS_SAME, 2, false +"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false +"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false +"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false +"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false +"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false +"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false +"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false +"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false +"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false +"__is_abstract", CPTK_IS_ABSTRACT, 1, false +"__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false +"__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_class", CPTK_IS_CLASS, 1, false +"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false +"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false +"__is_empty", CPTK_IS_EMPTY, 1, false +"__is_enum", CPTK_IS_ENUM, 1, false +"__is_final", CPTK_IS_FINAL, 1, false +"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false +"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false +"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false +"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false +"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false +"__is_pod", CPTK_IS_POD, 1, false +"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_same", CPTK_IS_SAME, 2, false +"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false +"__is_trivial", CPTK_IS_TRIVIAL, 1, false +"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false +"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false +"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_union", CPTK_IS_UNION, 1, false +"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false +"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false +"__remove_cv", CPTK_REMOVE_CV, 1, true +"__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true +"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true +"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true +"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false +"__bases", CPTK_BASES, 1, true +"__direct_bases", CPTK_DIRECT_BASES, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h new file mode 100644 index 00000000000..97ba8492d15 --- /dev/null +++ b/gcc/cp/cp-trait.h @@ -0,0 +1,247 @@ +/* C++ code produced by gperf version 3.1 */ +/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 4 "../../gcc/cp/cp-trait.gperf" + +/* Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ +#line 23 "../../gcc/cp/cp-trait.gperf" +struct cp_trait { + const char *name; + enum cp_trait_kind kind; + short arity; + bool type; +}; +/* maximum key range = 79, duplicates = 0 */ + +class cp_trait_lookup +{ +private: + static inline unsigned int hash (const char *str, size_t len); +public: + static const struct cp_trait *find (const char *str, size_t len); +}; + +inline unsigned int +cp_trait_lookup::hash (const char *str, size_t len) +{ + static const unsigned char asso_values[] = + { + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, + 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, + 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, + 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, + 86, 86, 86, 86, 86, 86 + }; + unsigned int hval = len; + + switch (hval) + { + default: + hval += asso_values[static_cast(str[7])]; + /*FALLTHROUGH*/ + case 7: + break; + } + return hval; +} + +const struct cp_trait * +cp_trait_lookup::find (const char *str, size_t len) +{ + enum + { + TOTAL_KEYWORDS = 45, + MIN_WORD_LENGTH = 7, + MAX_WORD_LENGTH = 37, + MIN_HASH_VALUE = 7, + MAX_HASH_VALUE = 85 + }; + + static const struct cp_trait wordlist[] = + { +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__bases", CPTK_BASES, 1, true}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + }; + + static const signed char lookup[] = + { + -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, + 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, + 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, + -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, + 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44 + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + unsigned int key = hash (str, len); + + if (key <= MAX_HASH_VALUE) + { + int index = lookup[key]; + + if (index >= 0) + { + const char *s = wordlist[index].name; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &wordlist[index]; + } + } + } + return 0; +} diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6e34952da99..62e134886fb 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1226,7 +1226,7 @@ enum cp_identifier_kind { cik_simple_op = 4, /* Non-assignment operator name. */ cik_assign_op = 5, /* An assignment operator name. */ cik_conv_op = 6, /* Conversion operator name. */ - cik_reserved_for_udlit = 7, /* Not yet in use */ + cik_trait = 7, /* Built-in trait name. */ cik_max }; @@ -1271,9 +1271,9 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is for any operator name (including - conversions). Value 4, 5, 6 or 7. */ + conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE)) + (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ @@ -1286,12 +1286,18 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion - operator. Value 7. */ + operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ & (!IDENTIFIER_KIND_BIT_0 (NODE))) +/* True if this identifier is the name of a built-in trait. */ +#define IDENTIFIER_TRAIT_P(NODE) \ + (IDENTIFIER_KIND_BIT_0 (NODE) \ + && IDENTIFIER_KIND_BIT_1 (NODE) \ + && IDENTIFIER_KIND_BIT_2 (NODE)) + /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ (IDENTIFIER_OVL_OP_P (NODE) \ diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..f6e1f6a4075 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" static int interface_strcmp (const char *); +static void init_cp_traits (void); static void init_cp_pragma (void); static tree parse_strconst_pragma (const char *, int); @@ -283,6 +284,23 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + id = get_identifier (NAME); \ + set_identifier_kind (id, cik_trait); +#include "cp/cp-trait.def" +#undef DEFTRAIT + + /* An alias for __is_same. */ + id = get_identifier ("__is_same_as"); + set_identifier_kind (id, cik_trait); +} + static void init_cp_pragma (void) { @@ -324,6 +342,7 @@ cxx_init (void) input_location = BUILTINS_LOCATION; init_reswords (); + init_cp_traits (); init_tree (); init_cp_semantics (); init_operators (); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f3abae716fe..39952893ffa 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -49,6 +49,7 @@ along with GCC; see the file COPYING3. If not see #include "contracts.h" #include "bitmap.h" #include "builtins.h" +#include "cp-trait.h" /* The lexer. */ @@ -246,6 +247,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1167,12 +1174,6 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_CONSTEVAL: return true; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - return true; - default: if (keyword >= RID_FIRST_INT_N && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS @@ -1182,6 +1183,51 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } +/* Look ups the corresponding built-in trait if a given token is + a built-in trait. Otherwise, returns nullptr. */ + +static const cp_trait * +cp_lexer_lookup_trait (const cp_token *token) +{ + tree id = token->u.value; + + if (token->type == CPP_NAME + && TREE_CODE (id) == IDENTIFIER_NODE + && IDENTIFIER_TRAIT_P (id)) + { + const char *id_str = IDENTIFIER_POINTER (id); + const int id_len = IDENTIFIER_LENGTH (id); + return cp_trait_lookup::find (id_str, id_len); + } + return nullptr; +} + +/* Similarly, but only if the token is an expression-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_expr (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && !trait->type) + return trait; + + return nullptr; +} + +/* Similarly, but only if the token is a type-yielding + built-in trait. */ + +static const cp_trait * +cp_lexer_lookup_trait_type (const cp_token *token) +{ + const cp_trait *trait = cp_lexer_lookup_trait (token); + if (trait && trait->type) + return trait; + + return nullptr; +} + /* Return true if the next token is a keyword for a decl-specifier. */ static bool @@ -1190,6 +1236,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); + if (cp_lexer_lookup_trait_type (token)) + return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -2854,7 +2902,7 @@ static void cp_parser_late_parsing_default_args static tree cp_parser_sizeof_operand (cp_parser *, enum rid); static cp_expr cp_parser_trait - (cp_parser *, enum rid); + (cp_parser *, const cp_trait *); static bool cp_parser_declares_only_class_p (cp_parser *); static void cp_parser_set_storage_class @@ -6021,12 +6069,6 @@ cp_parser_primary_expression (cp_parser *parser, case RID_OFFSETOF: return cp_parser_builtin_offsetof (parser); -#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_EXPR - return cp_parser_trait (parser, token->keyword); - // C++ concepts case RID_REQUIRES: return cp_parser_requires_expression (parser); @@ -6065,6 +6107,12 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: + { + const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + if (trait) + return cp_parser_trait (parser, trait); + } + /* FALLTHRU */ case CPP_SCOPE: case CPP_TEMPLATE_ID: case CPP_NESTED_NAME_SPECIFIER: @@ -11033,28 +11081,11 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Parse a builtin trait expression or type. */ static cp_expr -cp_parser_trait (cp_parser* parser, enum rid keyword) +cp_parser_trait (cp_parser* parser, const cp_trait* trait) { - cp_trait_kind kind; tree type1, type2 = NULL_TREE; - bool binary = false; - bool variadic = false; - bool type = false; - - switch (keyword) - { -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: \ - kind = CPTK_##CODE; \ - binary = (ARITY == 2); \ - variadic = (ARITY == -1); \ - type = (TCC == tcc_type); \ - break; -#include "cp-trait.def" -#undef DEFTRAIT - default: - gcc_unreachable (); - } + const bool binary = (trait->arity == 2); + const bool variadic = (trait->arity == -1); /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -11063,12 +11094,12 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) cp_lexer_consume_token (parser->lexer); matching_parens parens; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) cp_parser_require (parser, CPP_LESS, RT_LESS); else parens.require_open (parser); - if (kind == CPTK_IS_DEDUCIBLE) + if (trait->kind == CPTK_IS_DEDUCIBLE) { const cp_token* token = cp_lexer_peek_token (parser->lexer); type1 = cp_parser_id_expression (parser, @@ -11079,7 +11110,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /*optional_p=*/false); type1 = cp_parser_lookup_name_simple (parser, type1, token->location); } - else if (kind == CPTK_TYPE_PACK_ELEMENT) + else if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* __type_pack_element takes an expression as its first argument and uses template-id syntax instead of function call syntax (for consistency with Clang). We special case these properties of __type_pack_element @@ -11094,7 +11125,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) if (type1 == error_mark_node) return error_mark_node; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) { cp_parser_require (parser, CPP_COMMA, RT_COMMA); tree trailing = cp_parser_enclosed_template_argument_list (parser); @@ -11144,7 +11175,7 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) } location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location; - if (kind == CPTK_TYPE_PACK_ELEMENT) + if (trait->kind == CPTK_TYPE_PACK_ELEMENT) /* cp_parser_enclosed_template_argument_list above already took care of parsing the closing '>'. */; else @@ -11158,17 +11189,17 @@ cp_parser_trait (cp_parser* parser, enum rid keyword) /* Complete the trait expression, which may mean either processing the trait expr now or saving it for template instantiation. */ - switch (kind) + switch (trait->kind) { case CPTK_BASES: return cp_expr (finish_bases (type1, false), trait_loc); case CPTK_DIRECT_BASES: return cp_expr (finish_bases (type1, true), trait_loc); default: - if (type) - return finish_trait_type (kind, type1, type2, tf_warning_or_error); + if (trait->type) + return finish_trait_type (trait->kind, type1, type2, tf_warning_or_error); else - return finish_trait_expr (trait_loc, kind, type1, type2); + return finish_trait_expr (trait_loc, trait->kind, type1, type2); } } @@ -20081,20 +20112,21 @@ cp_parser_simple_type_specifier (cp_parser* parser, return type; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - type = cp_parser_trait (parser, token->keyword); + default: + break; + } + + /* If token is a type-yielding built-in traits, parse it. */ + const cp_trait* trait = cp_lexer_lookup_trait_type (token); + if (trait) + { + type = cp_parser_trait (parser, trait); if (decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, /*type_definition_p=*/false); return type; - - default: - break; } /* If token is an already-parsed decltype not followed by ::, From patchwork Fri Oct 13 22:37:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152794 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2191719vqb; Fri, 13 Oct 2023 15:42:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxTXay+JuSywsrlrufxhfERtkfCDB1MI0daT0Jv8fhk6dMGCn0+2TO6a9AKRBVYFagU5y+ X-Received: by 2002:ac8:7dd3:0:b0:418:1289:87a7 with SMTP id c19-20020ac87dd3000000b00418128987a7mr38158398qte.56.1697236977799; Fri, 13 Oct 2023 15:42:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697236977; cv=pass; d=google.com; s=arc-20160816; b=VLRoPSELFAy+ZVbXELxpERdggsPnwub3IU6DsdOn/MEVSqT4JHy+52xQAZIziym2H4 EI975qM/wP3u56orKdIDszLF9yaVAmpncFhehXeJOxXoCDj8hAEDqCZjblhX3kcAGhHC cN+tD3btQ3xOrdjpoSrWYvH520pMVMsSN4wYtFjjxqyTfnEfkYpI6PssgoRHHF4uS1qQ k3ZDTDnctuGGyu9oj1Gx+UkHoQDbHJ5QqfIDYdorIGjtZmEUpXuqZkQCOSMHPfdt6MIi 8nevNQqL6dN/bsk1MCj4Djl3vla329+DeMPnl+lgh+9nyV+ROHyuqn5itgvAVV0fY4Vd 5n3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=QVChz69Gyt60mbU9bGpz82rR2gXDD0jcc7ySui8Wybg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=OJPwVyN+YUkUVB2woafQRG06uEW9qnDWHjM5qzA55Ws0wdZo/MnMrXNxywyxkkqVUT 9+0DjwmK5Y0wvCTztKvccUClKW86rZpaQrTG2rUe/rHxnah4/QvN/GsmpjJKyjoToo6v H35s9+klS9Yb4x1Y6jePoEzSkwbGZob+j/ApysTo50wKIYlxV4cseFmEcy2dZdtxljzy pPJLg/KwOhh8ucd3Xk0sNk/DSC3126EBp2k+u+Ck+8lStp8AanCIebEroREwg4NXoHNZ XK23Yup4eOn888TrgsORIVWUuW4jiZMvkrz9bGaT9+yBrRYKl2SzZOvKS4Or2V7T6OFx 4EJA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mw6rd+dB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d3-20020ac85ac3000000b00403cecf35bfsi1960393qtd.297.2023.10.13.15.42.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mw6rd+dB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 819483857725 for ; Fri, 13 Oct 2023 22:42:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 819483857725 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697236977; bh=QVChz69Gyt60mbU9bGpz82rR2gXDD0jcc7ySui8Wybg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mw6rd+dBqzTsB7u5v+2LCYH9RYpNrIZwJyD7TAevSDqO/QheQ9hrNz8CzrLhD8iF/ I2AmafKbYbQzpqLyVpJm4w2bU1yOz27VO5aArrMebjJQNQFnTHPFJbTBkYhFKoQ14n wTN94zTs67Jo7nqGif9qJ2FDm16Tr9aj8qd7tQL4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 16A813857033; Fri, 13 Oct 2023 22:41:39 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16A813857033 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236900; cv=none; b=eqDis7QAVjfvaEBON7+iKbe2x02M9XpoDmJFJ8cQZWVdfWvpJUd7iLOmAYVjQxsdsCQO41v3+YXMyYTiBYq0NYui2vKo2gfFQNQUbb5qrjx1nKb9EvhaWHCT5ixDwvAIY16mpMP80cwA3TvrX+HP6IZMpElhbLdR0A2hgxsy3rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236900; c=relaxed/simple; bh=2JyjEv3NKZpiwAUHDLDUZlXV/snu6Qd2uC3fAj1M/GQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uuQSAKtQXmLNqIQ0HS7q9Cq1Wq0yQZxT+LeWMN+6YxIULgb31I0qymm7Y8j60wi6IJj0Idpfbg96JpKR3QDGeWsNCvxWilfue5couT5aaDccZiVMkV5gEypBBpbqqTwlMK36ky8GudTcl0yYbVKJeRp3plRfSgvwJ7nPq+oo5DQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16A813857033 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMX5Q4030783; Fri, 13 Oct 2023 22:41:38 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tjr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:41:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMfOs8001159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:41:24 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1G016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:41:24 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 03/40] c++: Accept the use of built-in trait identifiers Date: Fri, 13 Oct 2023 15:37:17 -0700 Message-ID: <20231013223957.1634024-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: W-RuDFrCOM4egB9w5acXla-3_02YK_Ds X-Proofpoint-ORIG-GUID: W-RuDFrCOM4egB9w5acXla-3_02YK_Ds X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=991 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779681961607250764 X-GMAIL-MSGID: 1779681961607250764 This patch accepts the use of built-in trait identifiers when they are actually not used as traits. Specifically, we check if the subsequent token is '(' for ordinary built-in traits or is '<' only for the special __type_pack_element built-in trait. If those identifiers are used differently, the parser treats them as normal identifiers. This allows us to accept code like: struct __is_pointer {};. gcc/cp/ChangeLog: * parser.cc (cp_lexer_lookup_trait): Rename to ... (cp_lexer_peek_trait): ... this. Handle a subsequent token for the corresponding built-in trait. (cp_lexer_lookup_trait_expr): Rename to ... (cp_lexer_peek_trait_expr): ... this. (cp_lexer_lookup_trait_type): Rename to ... (cp_lexer_peek_trait_type): ... this. (cp_lexer_next_token_is_decl_specifier_keyword): Call cp_lexer_peek_trait_type. (cp_parser_simple_type_specifier): Likewise. (cp_parser_primary_expression): Call cp_lexer_peek_trait_expr. Signed-off-by: Ken Matsui --- gcc/cp/parser.cc | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 39952893ffa..59015eac596 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -247,12 +247,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *lexer, const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1183,21 +1183,33 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } -/* Look ups the corresponding built-in trait if a given token is +/* Peeks the corresponding built-in trait if a given token is a built-in trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) { - tree id = token->u.value; + tree id = token1->u.value; - if (token->type == CPP_NAME + if (token1->type == CPP_NAME && TREE_CODE (id) == IDENTIFIER_NODE && IDENTIFIER_TRAIT_P (id)) { const char *id_str = IDENTIFIER_POINTER (id); const int id_len = IDENTIFIER_LENGTH (id); - return cp_trait_lookup::find (id_str, id_len); + const cp_trait *trait = cp_trait_lookup::find (id_str, id_len); + + /* Check if the subsequent token is a `<' token to + __type_pack_element or is a `(' token to everything else. */ + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); + if (trait->kind == CPTK_TYPE_PACK_ELEMENT + && token2->type != CPP_LESS) + return nullptr; + if (trait->kind != CPTK_TYPE_PACK_ELEMENT + && token2->type != CPP_OPEN_PAREN) + return nullptr; + + return trait; } return nullptr; } @@ -1206,9 +1218,9 @@ cp_lexer_lookup_trait (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_expr (const cp_token *token) +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && !trait->type) return trait; @@ -1219,9 +1231,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_type (const cp_token *token) +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && trait->type) return trait; @@ -1236,7 +1248,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); - if (cp_lexer_lookup_trait_type (token)) + if (cp_lexer_peek_trait_type (lexer, token)) return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6108,7 +6120,7 @@ cp_parser_primary_expression (cp_parser *parser, keyword. */ case CPP_NAME: { - const cp_trait* trait = cp_lexer_lookup_trait_expr (token); + const cp_trait* trait = cp_lexer_peek_trait_expr (parser->lexer, token); if (trait) return cp_parser_trait (parser, trait); } @@ -20117,7 +20129,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, } /* If token is a type-yielding built-in traits, parse it. */ - const cp_trait* trait = cp_lexer_lookup_trait_type (token); + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Fri Oct 13 22:37:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194567vqb; Fri, 13 Oct 2023 15:51:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFCPvMxDJ/7XCwpOXEG8bUOhF3pleE/vdrQVnUEpH6KOJ0AaSgs9PNSxa+T/LdVQkdcLUK X-Received: by 2002:a0c:b44c:0:b0:66d:188b:482c with SMTP id e12-20020a0cb44c000000b0066d188b482cmr1920624qvf.25.1697237507222; Fri, 13 Oct 2023 15:51:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237507; cv=pass; d=google.com; s=arc-20160816; b=BbOMTXor1PZ7aVIFxXV3IAXb58RDWjlnToiL4thTHAehMq3MLdHNkICv9AyQOTFeP4 d4+g/nUOiUOplPc0pwSlJPE6uQI+Awm1dOyklzMUs1V6BNvo8Dqrwz+am1+xGPKL4Rfc ygfvlJHm+cuMEQnBEZvLehHsCYtuuzhm/kMw8fGQvcgjYl6NcX/GK3R3A8Urz6g2cW5N Lk8iwx9mvqTUvlHa/SyUk0GwdRCdeXZQTpUIIct6qyBS3Yq0kkghhuRBaVxq7FlJeAUp vd4EcLF8AlqT8kP+KNMq5VLhZdjzt/PO1joWGOPdSt1mJqKMW+HRbz9BJ29K4nobACah 8R1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=A+QpW2RW+MhQraNL0kHmj2hvnz/HJE31o+NReBlrjYg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=q3Asufv1+eZycLGJOJkEoXP1qNt1TUV8EMtGtjD7WskGuJXueyzEbberj4Q51tcbhM IJjKPEOPsi7cyA+gdRGsvIf3nJItfRmyz0x3O86XaR3burq0KMt7/78r8fGCBOfS2lBN SEbPOjBalFbIDuITTMwW8ZkYoaRZruufYeQPpKaSofftHK4sDE3j2Gh9IuLxiTU0SsJ5 VwL+9AlZM4oOYKaGVrCBs2b8QCRSEW1NVgMMj1TjSGimR/2fPONRDvqPI2AJ4gPFYRZQ t57pP0L/9vIbLuv3ecir7hFFeNJJUX2NcJXNJO1hiGd4tPC9tePox3VnbCjTWh5PA7DP +/iA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XGjsGwXF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id im15-20020a056214246f00b0064c92f86b15si2072086qvb.145.2023.10.13.15.51.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:51:47 -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=XGjsGwXF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25EFE3861885 for ; Fri, 13 Oct 2023 22:51:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25EFE3861885 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237491; 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=XGjsGwXFuVK0xyyQ5nsTQZZJ1e6QVxBqyZ0QYKETT6p6gPqsLSvlBEFZjPO50u6pO gWaGCK/WBcPM4QFLfpNX0FtU1kT2rTt+r2+x5iOzOmYNZ4atk7ZHJ1ItIE3ZUMR4Wj acHFIzyr8piTRgxdiQCvchUzMFx3vVACpLZErIq4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 033FC385B513; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 033FC385B513 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=KXwU3OLBQNqE83xP/h3H2btzYb2VfoBm3x7coTB3q6rzeM4uB2MbVdQSPNIvOOX4g3utC/E+CUvAM88dEQ8bwBuy7FxjXJpcRuByp3aI5C76/O5hM4MtkKmNH+MyxbCwAUt9OMpW3GlaKoy1oq7Ux3knBSj2KJrHASeyNmJlmGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=Y2kmhZlE5hdHH4cuuwyfH68h6RYqgjOE8+aB26KxFqA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CgYfMkUP6x0/NA84dzjYmuPAKx2RzRuFM9SJxPzPMTzUbsnItj4ibRYtAvS7J6/r0YjnEYvZv4nsewFHPMVcE7AicdQVBhN099qFSs+LJ4qi+K2VBBInWM5X+Dy/29a9sqnoqjJ04lCFnL8vPifAvAV4i3GkILDv9sLw2dBduT8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 033FC385B513 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMNtCp011242; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbgdj193-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1BK001570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1H016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 04/40] c++: Implement __is_const built-in trait Date: Fri, 13 Oct 2023 15:37:18 -0700 Message-ID: <20231013223957.1634024-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: MpH5JcfTs8Q-aIzi05NTpg1RK9AKGOV8 X-Proofpoint-ORIG-GUID: MpH5JcfTs8Q-aIzi05NTpg1RK9AKGOV8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 malwarescore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1779682516715288049 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * Make-lang.in: Update key positions for gperf, based on automatically computed values. * cp-trait.def: Define __is_const. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/Make-lang.in | 2 +- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 202 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_const.C | 19 +++ 8 files changed, 135 insertions(+), 100 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index a67d1c3e9f3..7479e7dc00b 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -195,7 +195,7 @@ $(srcdir)/cp/cp-trait.h: $(srcdir)/cp/cp-trait.gperf else $(srcdir)/cp/cp-trait.h: | $(srcdir)/cp/cp-trait.gperf endif - gperf -o -C -E -k '8' -D -N 'find' -L C++ \ + gperf -o -C -E -k '6,8' -D -N 'find' -L C++ \ $(srcdir)/cp/cp-trait.gperf --output-file $(srcdir)/cp/cp-trait.h # The cp-trait.gperf file itself is generated from diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 722fc334e6f..567dd35fe0a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47e3c1af499..47a5ec9ee6f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false +"__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false "__is_convertible", CPTK_IS_CONVERTIBLE, 2, false "__is_empty", CPTK_IS_EMPTY, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 97ba8492d15..c9005eee1ff 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -1,5 +1,5 @@ /* C++ code produced by gperf version 3.1 */ -/* Command-line: gperf -o -C -E -k 8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ +/* Command-line: gperf -o -C -E -k 6,8 -D -N find -L C++ --output-file ../../gcc/cp/cp-trait.h ../../gcc/cp/cp-trait.gperf */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 79, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 1, 86, 86, - 0, 35, 86, 0, 86, 0, 86, 86, 10, 10, - 50, 15, 55, 86, 30, 5, 15, 0, 86, 86, - 86, 20, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 86, 86, 86 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, + 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, + 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -104,6 +104,8 @@ cp_trait_lookup::hash (const char *str, size_t len) hval += asso_values[static_cast(str[7])]; /*FALLTHROUGH*/ case 7: + case 6: + hval += asso_values[static_cast(str[5])]; break; } return hval; @@ -114,116 +116,118 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 45, + TOTAL_KEYWORDS = 46, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 85 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" + {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, -1, - 6, 7, -1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, -1, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, 28, - 29, -1, -1, -1, 30, -1, 31, 32, 33, -1, -1, 34, 35, 36, - -1, -1, -1, -1, 37, -1, -1, -1, -1, 38, 39, -1, 40, -1, - 41, -1, 42, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, + 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, + 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, + -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, + 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, + -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 782aa515da0..23f1d1c249a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Fri Oct 13 22:37:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192447vqb; Fri, 13 Oct 2023 15:45:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWRitqxFJCjJ2Hs92orPpfup8JxNpi+VtWTLUaOppgoBYEpnqtjmkMs5uBiWZ2wWyvFVDy X-Received: by 2002:a05:622a:1a8a:b0:417:b06f:6103 with SMTP id s10-20020a05622a1a8a00b00417b06f6103mr1779925qtc.21.1697237128520; Fri, 13 Oct 2023 15:45:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237128; cv=pass; d=google.com; s=arc-20160816; b=J1hgJ+GMPcGaEdYf22P4osJKOJ68JWUCwQmRwHTTk1q/eCM6rtxXOso0Fw4LQtTGWV rM/ct9Yq96ZzFwPNhRuexdpi6ulg4bu1oHQVQavwpXOMtMDDMOuwcIjTNLEg2vYBVJ45 tiRnSPhCLyUMU6ZaZ4hag3m6xj8LpnqRGXlA3B8CXth3Pc2b2Ue1JvqBtr0wHjjmgHpk wstEA4xf0ooKWjnCjy8E3l+jrhvX9zlnTKO83akslSlbVW1iytxYwSPyLRxguLZD08Mo c3oktQ81rTQDGrMj1lgyPzxHdA3Odi/Q9hlYBY+IFay8TGMjEv6SoS1LS/WtGhz99YA5 gHBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=mley30bNpOolCO2SoMGg9Q+om6Q/CDiiBot2bhWz57I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wIuLpI5qBP4aSkpZLp8MO3EjCRr6qf9/SN9Uli4pjzYh/lp4dV7IXzo5zCO7VucsNU JkL80HNqasejSH/6To+V9Z6zm88MEhPXTSo32ivCd4vzwRCxifcCmKSr8BXHFojJ7QEJ eK+pDFoyfgiBSXTxoHkJ28Z0tmlwHh+HXDYDp4P+Y2iPE701gTWiFOqrIoaAggUwlwZu xvrRj2iMz3K2WVl2TKdF+egZk5SQnQKMeNU7iYae33GdUjOad4IKUYPzHvt+nfB856FM HJmxxdcLf7Sk/VKdJ5zZXbkhDodtAANkimn2gpdjN060EssCzTjcI+QLwJJydPz7JUYa OO5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qyNn+1J3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c13-20020ac87d8d000000b004195f30d7f3si1976775qtd.698.2023.10.13.15.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:45: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=qyNn+1J3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E8ED386182F for ; Fri, 13 Oct 2023 22:45:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E8ED386182F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237124; 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=qyNn+1J3eFerXI52uSruZkoJO9KtMgdgdss308kiVnJ6Su8mJ1KmFV/bQzHGVSs91 bRZ5GJyc7DeISChsNmqeXWzzzZ0wiFJUXJSODGhEyO012LHE4ptGeoMbXgI4QwKgDV 77bmK0vGbq8ZgnDUeXbKvsw5INpPPRBUZGTaZtWc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 29FA5385701C; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29FA5385701C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=DCQ2Pi1yRQ5FHME5aKnXWb7SmyCcYzYHf2wvGrgxBUFBj4XP5d7cLtRiLnxBp8DJYIuwOvMKlGjtZsMxptG/QkFhSZir1b1oMRzCffKfHl42TNI1dsDF05++Vx+bUXQDsuwCIERCul1b6Z7Z2JZeUXgHY4TArtW/sJVpB70Qp10= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=Ig95QKG3jMRJ2d5xxOfPZpdM9Fw/zdK52c0tgvu9+Dg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=h4XI/OAuCRFu9fIsu6m7t1+Dg/WBijx+UtKLBshV9RBz4aYkrpKDp7WNKkDJI7cXwv5CbYhFFtNJu+h8+LCPAt2tNSBRAX1ZJO+HRq9FeRExhQ6l3vB8c6FEVlaWbgIQIrY/P26Jp9ljVsaDj6bNwvs2EAvDGICPYcWKbOEW8cE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29FA5385701C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMaGag004536; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfg9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1B5001530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1I016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 05/40] libstdc++: Optimize is_const trait performance Date: Fri, 13 Oct 2023 15:37:19 -0700 Message-ID: <20231013223957.1634024-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: tt7kH07b2xU4V5UwjtQUf7XkU4N0dqga X-Proofpoint-ORIG-GUID: tt7kH07b2xU4V5UwjtQUf7XkU4N0dqga X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=716 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995283749276021 X-GMAIL-MSGID: 1779682119239132821 This patch optimizes the performance of the is_const trait by dispatching to the new __is_const built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __is_const built-in trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..686e38e47c3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,6 +784,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -791,6 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3218,10 +3225,17 @@ template inline constexpr bool is_compound_v = is_compound<_Tp>::value; template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif + template inline constexpr bool is_volatile_v = false; template From patchwork Fri Oct 13 22:37:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195644vqb; Fri, 13 Oct 2023 15:55:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH12/2eFil1lzxYV3q6pIvUxJhh2OPg1CzCCdPgT3NNv+roDdtUe35OdNT1CAHPA6CQfUWk X-Received: by 2002:a0d:cb48:0:b0:5a7:bde8:51d5 with SMTP id n69-20020a0dcb48000000b005a7bde851d5mr14097876ywd.32.1697237703050; Fri, 13 Oct 2023 15:55:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237703; cv=pass; d=google.com; s=arc-20160816; b=JMvQN0id0J2iGJEBxAJrCFA12p4fVpVWwdyIluaKiJVD9a35qK/1DaopJu5+rksL4Z dn34E9qYmcGVWgS9aKE92hwdjgy7UzVCehxvSDQe+Anvic72JRMcjoWZ9dKZru3UCy6N ltU+aU4XmXLHjNdl6eMDVsziWe2FBjpip8aF551plZaP0yRUwfZFcjnYuwy8EWVzQzlE h1g4lA6lXuyew/ZyhluW64GUipKiSKl3X3qTNUtryz6qXOQxZdgPwXAkmC+7ltlaJxFD 4gDeEo/5f7Co1aoosij7Vjn/qLcU5QVfbaP7/kNIreKmbewtsR3+dqD/kXbsp226h4fu BvHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=5mJSSLFen0u7IaQjhA1s1/3FXyGQA3+lBUInCyPeFK4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=s6ksJQUv9TtEq62A7nmAjuWR3RzSWQUlikQLu1jgKevYWqGlLXar5qZ7grex8/pMSw 9MxTPdToEhhuTgE4DJ+Cix5k0yeXjxqMOodrR0Of2j1S/Z/l3aMQ/HsmL76ANvT2rdvH crcUNmcime75Uyn7qxKqQBOcBtcFZ9rBwMNpv44v3dnOhCYRj8YgkEQyq8GvZeK0NcvF R2ZGtZ3DGzvyk2udXrM5TiqSKDJI0/PYWw+o/vodWEQoDZUccK0+19nGymJnAUeh7ooD XLF48GgwwUKhtD2ozRDrkZvlUBSZitkpE6lNRJh7ymxQXY9JjM20YIbboqPEBknpSiEk Ausg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gJ9dEoPZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id es20-20020a056214193400b0065af6e81f13si1923313qvb.121.2023.10.13.15.55.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gJ9dEoPZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 822EC385CC81 for ; Fri, 13 Oct 2023 22:55:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 822EC385CC81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237702; 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=gJ9dEoPZuVKuWu+qQynyQHFXX50h7dkCEFo96lIGepptwkwmSTg3/WauA8N3CTGri yIULx3FKLNfqcepYKmKszTHUReUdAyKGaqbWZ75lH/Zm1kGIBIa22ydIrfYMJz+dFj h2o3ullPjaO/8UACbzunFQYSiT1Er9UDcQ0YUOW4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id C4FDA385697F; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4FDA385697F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; cv=none; b=fSMXryriqRqnLTj2Qit0XgPjc0wYxOaVeJoVo53jMp3X7k9TKwF24hIl6pCZqfvYmzvZk/dO0i9mS/woGVZdoKbOUJaADzMm0YDhK308g9ddpablbILA2mqAttcmX4nmjEdq9Ll+2x1kZPBAFddRXJ6y26NuXk4ur6qZYf6lhvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; c=relaxed/simple; bh=IB28/p6AlpOolsW4jPzzQOV9D+fmGQGsZO62I2hPsCA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fJxq4k8bzqX2a1nbSrS08unJA3j47H34zlE+Q0fz9Cdj5JJrK4YIYRR9RPOUzstQ1RQIM7dQN7MGvu1010LMJhwczPAYyKaqRHOu4gL1MIevgxLtrq5wJlwuaiHt9jLU2rhyUDe5VPyx5KMNpFlmVodfQsUNk8WD4rLXnDJVKAw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4FDA385697F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMfdDU031258; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh18L001578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1J016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 06/40] c++: Implement __is_volatile built-in trait Date: Fri, 13 Oct 2023 15:37:20 -0700 Message-ID: <20231013223957.1634024-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 2VzzOeQfK2B_OBkXG-nKniF4xygA4uCf X-Proofpoint-GUID: 2VzzOeQfK2B_OBkXG-nKniF4xygA4uCf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=850 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996916785922643 X-GMAIL-MSGID: 1779682721564023116 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. * g++.dg/ext/is_volatile.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 38 +++++++++++++----------- gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_volatile.C | 19 ++++++++++++ 7 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 567dd35fe0a..f031e022541 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9e4e6d798a0..d786f47e60c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 47a5ec9ee6f..ea7abda6c75 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index c9005eee1ff..f462794d5db 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 96, 96, + 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 46, + TOTAL_KEYWORDS = 47, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,27 +125,29 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 70 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, @@ -159,9 +161,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -215,19 +217,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, -1, 10, -1, 11, 12, - 13, -1, 14, -1, 15, 16, -1, 17, -1, 18, 19, -1, 20, -1, - 21, -1, 22, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, - -1, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, -1, 39, -1, - 40, -1, -1, 41, -1, 42, -1, -1, -1, -1, 43, -1, -1, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, -1, 45 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, + 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, + 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, + -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 23f1d1c249a..73178540fbd 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Fri Oct 13 22:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192888vqb; Fri, 13 Oct 2023 15:46:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxTnBk47sD73EImpRm6pXIY+h5VDKgq41iJ90TRmjaIbMrdL+XChShhkNgVmulFrtwFGYI X-Received: by 2002:a05:6214:d42:b0:66d:113e:5374 with SMTP id 2-20020a0562140d4200b0066d113e5374mr10829561qvr.25.1697237209773; Fri, 13 Oct 2023 15:46:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237209; cv=pass; d=google.com; s=arc-20160816; b=IQsg57A2vmaRJ+d/7Nb0CGsryCg6ryqit2Xj/vJ2DQm3rZNNSOTst7Gyb0HTTuhFn0 xFLfWSQOh4fnUFn7z4N54bwGH6RS1X7+k9biLL6zmTQLEscInyQgHh+Q/6DglHB8MbQH IifWXolUyfFevNHYtUI6zJskatq1qumvxIsujrvtNGIQEGkItPKgNqTuupp8YWqV6OXu kY+PmKAm1aw528WPj3IeYxIi5C1DudoU9t49+ndT09Jd3aOtG4c0wTMHLbUL8MnzJn/1 Urbp1ZIE+f0G1Q5hacgIu+bqaPlIICEqp/971ejdlo40h0ayeDaI5lvV8wDN3c+X+7/s 8n+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=jTvM8K5VP5nF2Q2x/3Xbn+YFgDUeR1oVEf9nVRR4fTg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=o/V3a2LJ/5KG2gt2QGbrW4Jg8lnhb3WrPwTjoIvyna7sxYMSpNEHxOQm5SW01EtlVw /cIdm7YZjLNVhcKYKiRKRGihsJPrRssZodTuA55tCtjJfGJINqXIXOokEoWaYStMNPka FbOACSAqcOVygo/xgikZNT2wlPstEjySJTWTx2imWn8MqAcQguCs5H2Mj6Rxjwx7xa6W 1d9bl9wX5bSMsa8g+i/MULcfFJRWZJc1H+HanuPnX8+vD7yCqckcLlun8sQQRLhgdcJM 5AIkdjpowHEeYuyd8///lcfRfNRHKuMNOe76svDy4HBjZDIZZKWKJDaKWJhoHwfHUdcw Y7fw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LWl7sp1m; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ef7-20020a05620a808700b00767b7c58ac4si1922205qkb.605.2023.10.13.15.46.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:46:49 -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=LWl7sp1m; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CD563856DF8 for ; Fri, 13 Oct 2023 22:46:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CD563856DF8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237204; 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=LWl7sp1mNloi6K8B96wSxXOwFpVU39ZVAePNBakQk2xruewaEmXFATd5ArDJgVDcz 8/PUi3j61vm0PJinuvqXz8M187mMZCzWRydPb6p4kSwp17j3HaODFAQaA/KAMUkwTm wYpG5nLgipOBRuI7yvxJfn+qwzj89RQnE5TTKVmw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 551DD3856DD5; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 551DD3856DD5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=Tdl2GGy/9Srs3b77Eu7pv5rxde9M8CTaiuGB/st0Z6sYYKQUesX6jakuIaoOuacsi+vQN88ezY1A5ktXZqNwR9xg0JQO2vMKoGoYInjJFLGwfG5YVm4Qhk4mxRGZc1ZP9Miwaa46QQWiL2dRI2vVgO3yvy2c7Q0hAKyNr+nTa6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=C0QfeWKCr4uUzOqn+4ufr8dEtmbXQAN/FqKqiHue+Tc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NpGVQdsa5IyzA8trOt2qghR2sLm98ZoRCUX5GlpuvyaOFJ5gJbmI+tfldg5fdu/28Rvp3KVgtt0XspckNFmoruHwX4ipCvF3OxEjEmvWGmXEiwY9CnK5gxM5yQWfPxRcbYkGvuH6UMilHMhR3+/JvPCDR2vNmYM/mJ7zFkF65Y0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 551DD3856DD5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMgiqh001139; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh15x001531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1K016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 07/40] libstdc++: Optimize is_volatile trait performance Date: Fri, 13 Oct 2023 15:37:21 -0700 Message-ID: <20231013223957.1634024-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7jyEK_DsyEkAqu-rfNDM48Ey4acM_JDS X-Proofpoint-GUID: 7jyEK_DsyEkAqu-rfNDM48Ey4acM_JDS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=762 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997095680917896 X-GMAIL-MSGID: 1779682204788459391 This patch optimizes the performance of the is_volatile trait by dispatching to the new __is_volatile built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_volatile): Use __is_volatile built-in trait. (is_volatile_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 686e38e47c3..c01f65df22b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -800,6 +800,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) + template + struct is_volatile + : public __bool_constant<__is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -807,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3236,10 +3243,15 @@ template inline constexpr bool is_const_v = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) +template + inline constexpr bool is_volatile_v = __is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Fri Oct 13 22:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192873vqb; Fri, 13 Oct 2023 15:46:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDfK/kvT4S08fC7WZEIa3Zztz8kz5wBmwdgODZ9+iBE+B0JkhDUpPa0hI7KgUQGsbnwOnN X-Received: by 2002:a0d:c886:0:b0:59f:9c08:8f12 with SMTP id k128-20020a0dc886000000b0059f9c088f12mr33955848ywd.38.1697237207632; Fri, 13 Oct 2023 15:46:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237207; cv=pass; d=google.com; s=arc-20160816; b=zqIsh6FtAxsyj8ofJ2VL18Iy6dvN5wvi38Qjs1w1sNBMDEJG/FW+QOd18WajV+oEzz g6Ipnbas5fitxoDXB8l3sUyzoT5N6fgPZjUG9XX1KEJNdEy0CFwRxCdZYeqt1FmeAMyN qU9zelsP1ReeslMYvEdb609Pe5iBlS2p+B6oXTihuFjjkGnDPqH1UAm3QthcQA9cYRAA osR/NJt3KejK1JNOfLxwMQJsDFy+QuMpMQ44NjZYd2pd7CaHY5OglWtRw4TGQF4qQTrt XtWudsbESjDABi0gv8IRjsH9Le2HW+qo1oHzRCnzseMbUozrSvo35I6hQFkjy7hJxF5p vR4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=aGgLT43MksFdT+cI8oi9mRH9zkZ6sRhQjmHrrWqj/uE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=v5Nvm8h1CDAZ7qXn5geqTSFgsnBYTVXFryeW8paLS2R9VuL6zEwQHIlYxayzNUTTl+ aE3/MDSeaJXlxi8W/oJsOcAomyaBn8PbCviGlUsDPe7+CqZDUk7TyrADnSzMWAE33+w8 NOYiOQ4/Il/o6exL6R0Vq/mvFhe81S4sSp0/NbFyarSm/+soC6chZUDYSEisX1fI1ULg xJy/tA3ekAkbvqST/OLHlQu8D5+r5iW+WXpaU7ODPhHm2a+abhd3soURa+2EmlcjrAS2 XNLIbQ6HPpXQPy4BR7IterSoojbz2ksaiSKbd2qYyDqmmeCnY+ggzXUxnIx8/h/kLjRl DZlA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ijwMprpz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id az13-20020a05620a170d00b0077429d89227si2006689qkb.375.2023.10.13.15.46.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:46: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=ijwMprpz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68F943854143 for ; Fri, 13 Oct 2023 22:46:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68F943854143 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237202; 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=ijwMprpzVe0RF/V8soilxNZIJ/rYqdkCn3MfznaLK3QPqvHbvYlR+5Jus9LNh745d SX5okG7j9QlljptBFcynV78VE8h31/MMht0JpI8WIiJqTBu5k6VXlaQY6pTMPUH7El G9ym84rFdPbGY8LXQ0jUT37zDJpjO+iiTUbGXyQE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 440CA3856DC7; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 440CA3856DC7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; cv=none; b=ZvJ2o4xfmuEmERZ8fGyfnM/ul2BXueQx22h3fDxqITNH+Js3J8QKzPH5QdNR6SPYMXh4E/gNCKjmK2kH6Kd9GiZpDvjuq72zUWQ/M3eHRhQnKJgWrhggnWdxsInt+FjZoO/84YrsZ3vKmIvzHAwcQiV+bQ9XzUfkRJPalie4/1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; c=relaxed/simple; bh=fprXPj47qmbdOKAPiDQTOc09TETOPKb/XjolEnUDEw4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ERp4wHkGXXtFZCYSIoIDcO5aS1HqXqa4eZkzk7jsPx1Pj7Hd9w6lrcgt/3JFrtEjgIZE1WaxfOWRoyVlohYTAK6P25LOf2B2rLaM/2ZtMQCS4zdP5YbmEpZn7agxhRcqkklVKKkAIOW311yCvRy8aBoEjSCOTKJmRvRMkZ/xv+I= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 440CA3856DC7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMceAr024615; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh195001532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1L016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 08/40] c++: Implement __is_array built-in trait Date: Fri, 13 Oct 2023 15:37:22 -0700 Message-ID: <20231013223957.1634024-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: I-_nUzHZQblR207uAHpxYqbPM8x5yeEP X-Proofpoint-GUID: I-_nUzHZQblR207uAHpxYqbPM8x5yeEP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=832 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1779682202608333145 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 148 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_array.C | 28 +++++ 7 files changed, 116 insertions(+), 72 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f031e022541..5e30a4a907a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARRAY: + inform (loc, " %qT is not an array", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index ea7abda6c75..fb162cac164 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false "__is_class", CPTK_IS_CLASS, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f462794d5db..526e63dec42 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 35, 10, 20, - 40, 0, 30, 15, 96, 0, 96, 96, 5, 15, - 30, 0, 5, 96, 10, 25, 5, 0, 5, 96, - 96, 5, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, + 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, + 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,108 +116,110 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 47, + TOTAL_KEYWORDS = 48, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 70 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -226,10 +228,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, -1, 37, 38, 39, -1, 40, -1, - 41, -1, -1, 42, -1, 43, -1, -1, -1, -1, 44, -1, -1, -1, - -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, -1, 46 + 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, + -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, + 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 47 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 73178540fbd..e1358afcb3f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Fri Oct 13 22:37:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195024vqb; Fri, 13 Oct 2023 15:53:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNqdyrWWR4pZQH4iUuU4YrbkiLag3ejuYCmSzzm3Wv6xA2pm9f2eJwaj/a5CZedS/k0F9P X-Received: by 2002:a05:622a:2c9:b0:417:9e55:617f with SMTP id a9-20020a05622a02c900b004179e55617fmr33648038qtx.62.1697237587268; Fri, 13 Oct 2023 15:53:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237587; cv=pass; d=google.com; s=arc-20160816; b=d/zNYSqNIaxNk04LCNVzKHQ9+WaCjvDaVrasjG21z7QhGCcRZObQj77pOfQV7+rPDB opX/CJkZJkO30wFVv4pLFgtErKuMgCK9VT445zWefSTuJZMmyx/hYM0kNkM2TI/k7kBM nVDUPILMvg4qS4Z/XpB73/+6dn1SycGfa602OFV7L2tP2cq9mDpmpUHeNCThuU/hzk1q aexjH5OWrIqsA3gdbRisGr2zg8xz4lNrGKewxBU2iD0O7Qikw2oIMJoMnVreOYBg1Sxd fFqYdzw7DzenmqIDzzaJVY+eITmbmLRFzN+GjmIjPZGqxJRqwEBruf0SMLmrCN5keju8 MH3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=+Ve3wTlV1WuBwACAa7t6wUegG+N4dAZL0ZMv2zH4a8Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=UzNTu+frXHQYdiiWdRRNDrdrpYg++8mlxRDq9OSzSV8TFp80/fZwdaVn3fWwsytr76 AnPFa6yc92stCfoZdz/QD7qLedgTn+EO0NM0A+GKUP7GFgCsqKEKrH3249syszwBM+53 GgT1uKZMoARU8EGz15CtIXFZvuHzJ09s0S1yOekAGFEftRQ0KNyFdTTkpe4q05E/ra95 r7wE8mfmNi5Wk0mqkLzI2pMqxWrXrUEwmt0dnupxzQueWjisuHJw5kbUt/r5oPxzYqFw wuAeJrWA+jJXWi6tLprnAEjCkSOflX6+rjo9OWr1NOn5DA7Po+IT8SpMiREIriDK9VoP XYNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mfqFleNQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e12-20020ac8598c000000b0041953bee755si1994359qte.441.2023.10.13.15.53.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:53:07 -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=mfqFleNQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C37F3853506 for ; Fri, 13 Oct 2023 22:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C37F3853506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237582; 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=mfqFleNQdis90/q79pTfNMp6vouwa7bn3Iuf55+Rln/eEfMqSK8k5pSSJmmr1KsY1 iqCvnMnFM4jfOWqZJGDG5jlpiWs+2zuBVtOhu3yk2FEAq1GA22Ij+9JICK/IRKVXB2 CF7MnSAY6qy/lsjiJySx5oRlA9gEHAcOp9+i6wdA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 36B87385B522; Fri, 13 Oct 2023 22:43:18 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36B87385B522 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=ASifs7kN8Ag4DjMUhEbDs4FYr5JzCXMGv1PWMVr94NTulsKAL6IBg04gjQLTP5NIcUH6vspeANAgm40f8GxTK9HJBNlWRDqcY0/0qPfmGaHJqXJ9AwEdcd39jBo5tYmohXCnj1HID5EHyv7Jwq6WBwEqL2kv02e026j5gvlSbhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=MOf+TxQspyRPPZlZdf9KhTx3QdQB9mHppfT5BFfsWxE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZUFH5WxtovsvN+QgIzXmY3RZA3p+HHaNZNcpsZC3Don5yKU+EqZ2HTyhR3vZ5Cl70cfmsngHLOc0fEYWTbh+YDdneH9L2Z66DjXbJQPiBjqjLko/UVyHi/qVbqglahqJyV+NVi+hikCKvF3BwjOsvbyCz/1tHReG+fHNpLpaw7k= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36B87385B522 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMgPUZ001997; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05vfh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh15c001583 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1M016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 09/40] libstdc++: Optimize is_array trait performance Date: Fri, 13 Oct 2023 15:37:23 -0700 Message-ID: <20231013223957.1634024-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: FVhzGe5XbcYQAy0URv_ztA-23L698MJd X-Proofpoint-ORIG-GUID: FVhzGe5XbcYQAy0URv_ztA-23L698MJd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=477 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997263374731491 X-GMAIL-MSGID: 1779682600246975067 This patch optimizes the performance of the is_array trait by dispatching to the new __is_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_array): Use __is_array built-in trait. (is_array_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index c01f65df22b..4e8165e5af5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -523,6 +523,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_array +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) + template + struct is_array + : public __bool_constant<__is_array(_Tp)> + { }; +#else template struct is_array : public false_type { }; @@ -534,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_array<_Tp[]> : public true_type { }; +#endif template struct __is_pointer_helper @@ -3183,12 +3190,17 @@ template template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) +template + inline constexpr bool is_array_v = __is_array(_Tp); +#else template inline constexpr bool is_array_v = false; template inline constexpr bool is_array_v<_Tp[]> = true; template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#endif template inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; From patchwork Fri Oct 13 22:37:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2196435vqb; Fri, 13 Oct 2023 15:57:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpfWXut9ZT9XojTvxmFf4BXYVKqv5e9HIv1Wp5wXq8V2YUtJjdYBCYPAlnfUbKxm2hus/k X-Received: by 2002:a05:690c:fcb:b0:5a7:fae6:1cc6 with SMTP id dg11-20020a05690c0fcb00b005a7fae61cc6mr7803194ywb.24.1697237857117; Fri, 13 Oct 2023 15:57:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237857; cv=pass; d=google.com; s=arc-20160816; b=pgtOpdQe4oNbp6NS58fKPI85WqmV80g4xrrF+CoK0THSEkyxoIG/Qi02VwUhCh14ii bJnXCwvuq9OIizy86GRfl9P9TKYYee91DNNF1VZGtNttbY4PjdUlM8h4SQI/SDzrrfqC fCuFYLvGwyT43rKRKR5sLOEuVwZds3emlablUpf1yN7YcFGU/DlDe6xEVdaI4CMnJSfk fWLqRBC/1oWIYNozsddkFa/bzR0Oqt42jTC4PS6H78wqd6cIyOTuMobqMusGtAEtSvhk 1JmSA58/KR+MeK2qp6MIpug5iiR+1udey2x07iKagwbknlvnM0gG4/qSe5P6AafY+9Qf QxwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=oNXBI4oZxhCwxCDJdXjGd2fmUW0BlAlh2yuf0fbhEbQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LEWm07Wv2eA0NRS8LC/a/OIOt/yK69CixguwOj6lJmU5agBFRjmpo8mDwR3hrpH69p h5yDKiAakiavTfYdUAdaaXTB4ySy5xGUU/P7X6o9MUD01/QtncV3O8rxd49x6JEcNQGB d8VNJIcgd158z52MHGX+vI0B6h5HF6PRJhxweglZfskn9gRPeyoCa9Xzt1YKPnOoqcJQ KgMLNk9nmmMmxJ6JZ0o8+lzpLvpYmUX1kbjZY+SI0a2JfbE1SedUGGMXXoReY8enFZVm Ttxk7pKTjZ6ryxQ3YTLtDYZFV6Nkm6GeeFnaaNk5lcFT3ocK3LDfiEC4oCurizh8Flgi R6GQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M8o99hGC; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id pz4-20020a05620a640400b007770bfd349fsi1928333qkn.603.2023.10.13.15.57.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:57:37 -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=M8o99hGC; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE01E3857702 for ; Fri, 13 Oct 2023 22:57:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE01E3857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237856; 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=M8o99hGCsioJadFsDTGbDyoVL6VY4Gn3epjhOKPECtWDCflk3enEUSelL10tPUS9N DA+jmen41wtlncI9JEjsspuk1xn88ZGniN++PN6pHjtmW2lRnoqTPEJq5uhpvIAQd0 eNnfCUQ7DIUTOIKqa56n5rQRgMTskPuKazIiDLGk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 14A4B38560B9; Fri, 13 Oct 2023 22:43:23 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14A4B38560B9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=O36E6f81M2SLIu4c7wr/q9de8yc8n1j6BjMS6to+yaQpLkFrawTqRdBvpjhQ1hLTugXXrvYVgWkQUj42sDU4oLB5Nuj3mDFOMxhuwJVlbt4SjY9KaTB4wgeNfag7u97sP5fDbztsxgpkDKfFtJqkHyx3j+VVRHZEu1mO60lXMjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=vyFkIM9zU5ChqtdiViJHgtZOBQL7xlNrBxml/awmanY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DPn4BhsBgLdYNrtrXh1mn0fRu5BodN/6JlDfXnWGioQ6l8A6rkES7GXUSaVL7SCjhF/MdNjSSl6w2tYvHzhspkkfbodosqXnTroHQU1YOiME/0eplS3Pj5wt6tDo9/gOPdcknwJWsf2ZtXgmLOWyQl2XX+3+amSy/jSej45mlTs= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14A4B38560B9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMhMv5016991; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8ttu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1lq003471 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1N016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 10/40] c++: Implement __is_unbounded_array built-in trait Date: Fri, 13 Oct 2023 15:37:24 -0700 Message-ID: <20231013223957.1634024-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ExR_fl6-CGV7XVF8GqGSBG9SSrtD0tQ_ X-Proofpoint-ORIG-GUID: ExR_fl6-CGV7XVF8GqGSBG9SSrtD0tQ_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=775 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997094718165190 X-GMAIL-MSGID: 1779682883199204382 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 42 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 ++++++++++++++++ 7 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5e30a4a907a..751ac61b25a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3796,6 +3796,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index fb162cac164..a894fc8c74c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -63,6 +63,7 @@ struct cp_trait { "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false "__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false +"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 526e63dec42..47060ffbbef 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 48, + TOTAL_KEYWORDS = 49, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,30 +125,32 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 59 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" @@ -161,9 +163,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -219,21 +221,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, -1, 12, 13, - 14, -1, 15, -1, 16, 17, -1, 18, -1, 19, 20, -1, 21, -1, - 22, -1, 23, 24, -1, 25, 26, 27, 28, -1, 29, -1, 30, 31, - -1, -1, 32, 33, 34, 35, -1, 36, 37, 38, 39, -1, 40, -1, - 41, -1, -1, -1, -1, 42, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 43, -1, -1, 44, -1, 45, -1, -1, -1, -1, 46, -1, -1, + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, + 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, + 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 47 + -1, -1, -1, 48 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e1358afcb3f..0a2699be476 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Fri Oct 13 22:37:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192788vqb; Fri, 13 Oct 2023 15:46:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWaeYRjEuhGp5ApUmo3ZV0JN/Z3FMrlDIh4W+RgXZnmeLEK8DUWAwzXYsqqcU+/n8TvOZK X-Received: by 2002:a05:620a:44c3:b0:775:8fab:8c6f with SMTP id y3-20020a05620a44c300b007758fab8c6fmr2084137qkp.29.1697237193446; Fri, 13 Oct 2023 15:46:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237193; cv=pass; d=google.com; s=arc-20160816; b=e34E1uj6vSnWP3kHu4WvsjPBO1xbYaULVJXQfJ+Q7L7nNHr2JHjbQKUyBBDGYLTuVF 4FzRP3WxykJ8uN40cRdeWorTBNL+nK3L/SnWutmIQsGcg8A0ZifFinXIqj5FlwPEbT5T YXFFmmzN/BCv3mhbMP0KCTLcYVGcCklDO/tf2h80JL1c0Tvt2eAtTm5b+3C13jwr8w6k 2LyzU8bzucCiDM4XDlqRJ41XVzK2KdVGDlhUQ+L+iXot7fnqML4Gxf9RvOh5+QtwmTdp Ld5vxf6KZ70KYv32AIhLJBsvFmKk10WV3PMMAQ6Cled+Av3elDNuNSSOAOIy5ZuTK5VP IFPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=TD5uPdlfDaOzJ+ENinfQBL4M0l8QGC6kbZ4keFw9egE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ayqtTphtx8NlTWbXVziH5o+DmYMeOrZV35uLorjJuDrdy3TmNhNeNdU1R5c7+6BwQ7 Wbfjqyo5h0Bxjp9kITqDCD5/TT/eqNv3vcvyhnfY8gkjeCDmlh2cl3CR63asEJWdKZRu eJzy7UFImFTe1ZUB/m+kVNIhgT7EgAZwt/epVNdLrVBtEH2tvvWOrqxQ3oHaLNRGs412 cFR0TS2KLnI4+37xgyekJB7ZOUhkQT07sKPvGCMyMlxJmmld4QVNAO7HM/ff0mHKyx0f nItGLXocxiyMzH0q69NhTX7fx24bOGd0+mW0uipDuQaP8CeGza3HB2n3batlYMKlY4cT vTXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Z/I/EhJm"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id rr21-20020a05620a679500b00773aef4cf9fsi1845718qkn.430.2023.10.13.15.46.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Z/I/EhJm"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC01938618BC for ; Fri, 13 Oct 2023 22:46:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC01938618BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237187; 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=Z/I/EhJmzQWHQ70iUGCtD/dy+otMb3pY6hRzWyDvtf432Zt+0TOVxncDSBKTxgTHF 0VXOmhm1l4wSTbveUsLTSnNx3pZqEhn1+FEaLs6YcQQBo4KrWh8tl1UfpAUkphmAt5 3+16qfDzWtxezpbXKsv+T/Y7tvHIUvnD1TPQPWMc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id D42103858025; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D42103858025 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=sjqlG5H/Aw/z5Li1LMqbNMh+2nF490Y9u2HHP1ReFunnzIaBpbJRIsE6mFSweiEGhEBg04C7xpjk0Lsp4LinhNAEPnLuxlmHHFWdMVrO0m9mLzNP8vfkrXLjoHxgA8Mg/SXlQGEBAR/4s3rpJsZnL7L+J2ALTZl6YJCmixukPFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=Cijkk+1KKS2ERennoIfTZ8dR0bWLbMoE2sdRxU4V8ZU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c8/yGnWRCNCyW2HCZghgsC9tWk8gi9VU7foB6q8b6xoj/8/jDZggMSRtWvdxi7LyUVvZxSTRJ8pimBYKFdlxReziDegnotU5sz3Ofw9KuhBtlxyv8Ed+xFj5FEyuBFnxftGymFvYLj3KRLgg0i280Lt5dxqTyQ5DAlkRO7TKD/8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D42103858025 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMdxxD029917; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0md-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1tN021531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1O016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 11/40] libstdc++: Optimize is_unbounded_array trait performance Date: Fri, 13 Oct 2023 15:37:25 -0700 Message-ID: <20231013223957.1634024-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 7z_7tWmsNxk05Ytsdbs01WL6tTKowEzV X-Proofpoint-GUID: 7z_7tWmsNxk05Ytsdbs01WL6tTKowEzV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=628 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996817880022434 X-GMAIL-MSGID: 1779682187404947462 This patch optimizes the performance of the is_unbounded_array trait by dispatching to the new __is_unbounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unbounded_array_v): Use __is_unbounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4e8165e5af5..cb3d9e238fa 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3541,11 +3541,16 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Fri Oct 13 22:37:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192976vqb; Fri, 13 Oct 2023 15:47:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmilyZIynmptvPsNcit0nSQ/eCVqnou//0It+JrPLazQ+8kskrnaVDwQa7740zEtMGoBcj X-Received: by 2002:a05:622a:c3:b0:419:af4b:c785 with SMTP id p3-20020a05622a00c300b00419af4bc785mr30246743qtw.41.1697237230083; Fri, 13 Oct 2023 15:47:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237230; cv=pass; d=google.com; s=arc-20160816; b=UP9u7JGXYAxVDsdev/3V0v2pb6VKFYNmhsi/mXlf5t77Apig1t0prhYVEJ3+Gi2QEB vK9Z9OBHY1smDTS+7z/Pl6o6nZ/mzVlfBsRAz3KR93upyZmhfIeEcpYh4303r3a6bZDw x+fGMA5D56KIQncSe4/+GxdfM+1Kxdq1JubKV0T+KvtDRDBv5eSkQIDolELwZXBhtpPB C2DwbfmxFcFZGvYf43SqEqG9QtV99h5iFZ8JjqgmNw+isvXnGupBmaiRAPR9/hf7VcNG i8YNI3cLs+VxUUDUSNMnzVzXmO8Yy0fakGuF+2YrCGNPy1F8erhZi7OTnN27CasNH/kd D20g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=5L2jYSvgfySeygsrAzTMQ891wCqdh/WFvwBHjxho0hA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PvMIEyd3ZHwbr9pWWPKX/MYD0Z0ZrjmaHKflWr6lf36FL3rBCFvib+l2fRFaUBkTdE WBIOPCNEtRPgtKtl16YNUvxwb9BXw01VS1cf7j3tlHMP+klOtS+AuriRdqkrx+oH05tD 7TcCc6jwFhYnBi84dtcUwbY53AsU+oB08GYo/Ht7RGg4gnwrnOONouaj83C83n6i4mvS aGHrAuP7uInszCeToNH+jqeV57TmeP2jUr+l+UY1rsKwOc3irwB1NSBbNSBf9MN6bF6D fK0ZAQEXO0Cbn7LKb+kZaG93/C9WwlPmPQ5X5XPPLpAC9a0d/YUykx5aMGRTnn8PNotv m9vg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dx8Fi0j6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b21-20020ac85bd5000000b004069466b1c0si1987430qtb.562.2023.10.13.15.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:47:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dx8Fi0j6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 446BA385CCAA for ; Fri, 13 Oct 2023 22:47:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 446BA385CCAA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237224; 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=Dx8Fi0j6jEXrYy4et7pUFB9XyvHLdQ3SCgzBnjd+NKsb642o3Shw/dQpzRO89L0wV 7/n+PNqHzUqC/9OnKyCZZMmhP/6zxQPBlEREFsrpT2mQhaet64SDurfcaq/KrVCpNA f6qz43c2m//J0LQBlo7hi7a+iLu3C6G6TxylGazE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 583F63856DE6; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 583F63856DE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=bByKcci0zrB6HB9nthmIe/6s+/Gcm7o6xobh3fLcXiAbU9zQ6FnJpur/xAm3ps7jcwfzCdEjfxluA6zyYM9KBXIpAoMKyiyM+KNRk6ekWbQVF7960ZSkAtkU5RaUxNGc9RcuOsoInIJokDKUyBfOzLKEuOCPu54xTqWStRme/IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=Q+HVP/m3j5zcZWnVVUZYa33+EcvTbYtL23oYcv3ef04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EgqIAdIwCN+DEJVyLyX5RJLdAyaVh5TU2x8TIeman5y/2pw9P34WZLev+Kcu7XB7AwQ+Ws3k7bQ8n2NURLvD5rfoW+5Y+sSAliLeCHS/7HQSzatTKXi2+NrR4yZPvk5cgid0y3aQROTKelVMH5Uk7XCub8RKLcWhtn2Teog6Kk4= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 583F63856DE6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMfHFe030971; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1As012731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1P016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 12/40] c++: Implement __is_bounded_array built-in trait Date: Fri, 13 Oct 2023 15:37:26 -0700 Message-ID: <20231013223957.1634024-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Mvht2kRUl70ESpM9_y3GQX_UV9BL7Mee X-Proofpoint-GUID: Mvht2kRUl70ESpM9_y3GQX_UV9BL7Mee X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=843 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1779682225399805917 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 86 +++++++++++---------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_bounded_array.C | 38 +++++++++ 7 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 751ac61b25a..d09252a56b6 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3723,6 +3723,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index a894fc8c74c..90fcdc01de6 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -42,6 +42,7 @@ struct cp_trait { "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false +"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false "__is_class", CPTK_IS_CLASS, 1, false "__is_const", CPTK_IS_CONST, 1, false "__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 47060ffbbef..f22a6e93618 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -80,7 +80,7 @@ cp_trait_lookup::hash (const char *str, size_t len) 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 5, 116, + 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 49, + TOTAL_KEYWORDS = 50, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,54 +125,56 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" +#line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -181,7 +183,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -191,27 +193,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, @@ -219,9 +221,9 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -230,12 +232,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, -1, 24, 25, -1, 26, 27, 28, 29, -1, 30, -1, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, -1, 41, -1, - 42, -1, -1, -1, -1, 43, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 44, -1, -1, 45, -1, 46, -1, -1, -1, -1, 47, -1, -1, + 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, + 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 48 + -1, -1, -1, 49 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0a2699be476..32880754020 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Fri Oct 13 22:37:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193645vqb; Fri, 13 Oct 2023 15:49:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZZWuOEb1ov+MWXM3cutDJ4Xs5btTfnNdKiUq9AmgPDGAOhOkvL1BZ6B5rfBro/SOmQ/Rk X-Received: by 2002:a81:ad5f:0:b0:5a7:ab31:f4e2 with SMTP id l31-20020a81ad5f000000b005a7ab31f4e2mr15359293ywk.13.1697237352544; Fri, 13 Oct 2023 15:49:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237352; cv=pass; d=google.com; s=arc-20160816; b=fQs/g78JoXxOyBxp32rvqfMR5mUlmBUgDhRJblJnAa+/LMRUtwUlHuIUYcdUPRURQ1 7wNlC2z1f7ww/kUX2/t/T37fPXx9IihFTWKptpQHyZoGUd8QcoCNPjWaIWV93LyQ7hyB DzdXChMXq55GUSzAI9oyOtxvE9A5Eq7Howxm1pYZolk9cibQxQFvr1Y2SlLbe6hL5S5g HiPBmukub29vInWNlD4drVwTLf96nrnAk5RlEmj2LNg2YHMzYG+CzGUY9KF2sC9eCpGF KgwFgBWb56Pb9dcG7H7pXfwfGxTxbSGuEJcHrrWxW6A+QJdhUmXu0yCWZ9Okc9kW3bvn MNAw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=rT+97LmUY51Goy/RS0sjhzzPDqddkmENQDgxhZx+FfQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HphZFS+G/+4SQhvPwul7kd5x0sU/VcYtJIqc4SRc6Mx2K1f2NosdZZWYQvME1jf7m0 tUhqcsM8UWmFkeSBPFEvV3n5HX31CfWVNOxjzP2xrn78OLPkw7uqSvQWnPledxvg1vm7 Lghj4SZiABUE3xW4crS/QjnZU9lAjFXBaHDvTV+bXN2hjOJ970vEAcZg7J2Zr1kTyyy4 WofygFplMgQRqhKSmQJBZozn90MzY4YOJjtKfC2RHysYOEP8uHKm16IhpHJupFau9n7i wiDBIhYSqKjqxkKvgo5McYjsJSYMOLB8pILRuH743gwGN+C0f49KCyQoAO0Y9IeQmdbq 76NQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XBC/iAMU"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bp19-20020a05620a459300b007757d446533si2054466qkb.282.2023.10.13.15.49.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:49:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XBC/iAMU"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F2E2385C6EF for ; Fri, 13 Oct 2023 22:48:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F2E2385C6EF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237339; 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=XBC/iAMUc6lDsBSNnaVG/+zC2EFrVjroUq/mDN0TKIiNIZq3qF0EtA0PJGXlsXrgV zXLwY9LDlRvmxixxUHdWPWYJDky2dpIT8ApU4WyI11wvzOb0uu6ccEvALi844b5/Ox inAyhWxJuDRPCQdTu0rgGWKVwZQcR5C7W1j7AlqY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 2BD103856965; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BD103856965 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=vq/y1601+LaJ5dhz/+6WmCznE3twVayycuiD4a6e3QR61AjyFBf18JPtQFhVnkpVbuO/Pe8fhSFCyyhn6v2oLFHHk2TdOY7P3Wn6p0wMsQ01vYzs3tejjfGOI9ODbLUpWNGJRdGSLV+mLxwFLD/gkovYhXzKVy4j/oFP58Y7Np0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=bh/DHfcrUuildpW5273OfXvIzy/3HS7X5XXA7BH7W8A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GH6czaHwsbTKCcI9brXumWpKb5t6XRXM9WIizKBTz8p3iwu6B+ICm9WkSoTchdZp3A7Q+wdiGZ0ZRH8rEsanJoxTuNx7YblkMMum7J4lbg94QO6ozSJujPM+hcHX3GJNymWUqv/IvjAo5QRbQPsh0pHwMn4Lr9JwXbIM/5dhnYY= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BD103856965 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXSNY029268; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh1YJ008020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1Q016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 13/40] libstdc++: Optimize is_bounded_array trait performance Date: Fri, 13 Oct 2023 15:37:27 -0700 Message-ID: <20231013223957.1634024-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: iwZDedicFaSSzKa-U7h0iDEUCsJNIZ1O X-Proofpoint-GUID: iwZDedicFaSSzKa-U7h0iDEUCsJNIZ1O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=620 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996999788880715 X-GMAIL-MSGID: 1779682354388342930 This patch optimizes the performance of the is_bounded_array trait by dispatching to the new __is_bounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_bounded_array_v): Use __is_bounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index cb3d9e238fa..d306073a797 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3532,11 +3532,16 @@ template /// True for a type that is an array of known bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array) + template + inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp); +# else template inline constexpr bool is_bounded_array_v = false; template inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true; +# endif /// True for a type that is an array of unknown bound. /// @ingroup variable_templates From patchwork Fri Oct 13 22:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195719vqb; Fri, 13 Oct 2023 15:55:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6dAMKgDx78Nc20xzDrWKhh/GmQ1s1SJTJRXcwMN3qjc/duO3VXa6UQxTCc5wpME9tV24x X-Received: by 2002:ac8:7f86:0:b0:418:111e:7910 with SMTP id z6-20020ac87f86000000b00418111e7910mr30246905qtj.43.1697237714207; Fri, 13 Oct 2023 15:55:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237714; cv=pass; d=google.com; s=arc-20160816; b=vRRlMQWOyw+Rlny8GlbT7seK98wNyNW8iJFZ9DYObWNALrE+A5K5hbTDLKzezOzA9G jMowVHNGavkbZ63hQYSt+HJVxKh+5/h887HM5HrHhunrrPmHGxQO6v99s/TI03qK9WX9 oB3f1nDfos2QEoca3dYRB83SeCj/9H8GhPkYdAPY8Q7xLefEMSikalDEQQPhzmc4e5Bw vynS+p5zudP2oVawBlHI9ecL//y+LbmGI6gGSX4T2L/JTvp23WSsirkoNXbwebsALzGA mXND939Mixq4dWY80gQUDDme2oRmtRawaERlAgqmDo3WQYmEzxx8obM/m6UlJQ3UAUIF Dk1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=GHfEbv14Vwy5Uuv+exJOCQGCztdAteLQQx0xnttls1g=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cxOh7Mq24bjVWwXXksXUbLHDFZjptI0A5Lsse1NEVjmA4Il/XGRayJyrgtHmQe7T+w cG+xwgXgU9TbdjjVaV8hFCeoJIGhWHKJUxL4JVPEkn59oYNQsTSzQmVMYaCpzmOuyqbx CZpT6n1TVFllvADn5QCdDbdCHFjyhrte8L3AKESUkAWM84jCU6JuTNSWPqGh3CBbxCpo oVV0KfbEZekRvFK4a3/HcpGTnTrE0/019KDQBXWKhaRCsodr9OE4wXQdXC5akqFaGfql 4NdQn1TgfOmPGeB06B/Noemh8NPza+DT5X9MLy2I+ahzUth85kTN7NrarH+tjYgaF2g0 XMpQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=N7+sb+jn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b16-20020a05622a021000b004196b9a23absi1962550qtx.145.2023.10.13.15.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:55: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=N7+sb+jn; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AED2A3857BA4 for ; Fri, 13 Oct 2023 22:55:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AED2A3857BA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237713; 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=N7+sb+jnC8cgifFCXsIHjmfydQ5gfHeCwSLu1GcNqzUOiXi2eppM+zXKnDVHgCgES d9XZpAg7ga+F5Ct0FU9YrTubDiMn3jy5vMZWpkC5AXlft1DojAa307cdEDUX9qTHFw mjlnVR3m2mjkQ6HzDy5HPzgK2IHT0LRspRsclm20= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 2E6D9385609B; Fri, 13 Oct 2023 22:43:21 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E6D9385609B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=bahp+jXBt78VR164bjU+fTnfNAwnzcb+X0Sa3L6xjCcy20nvdYI+gV4UXbwxZSDL13v1YKFvEO+h5Hwzt3LMcoekoZtReXg4sB4yP6EwOBsY3OS/7/+0oQ1BI1aACo6YsEh52qF3LNeq1/ppKZzYo/PYqSUHRyVxeDdfy0N/Dlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=wZ4cErfodga3j0e2Ef9CtgdrrubkZ3aLrFe+WfKn78U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CkNX0o52897/ycIM/sTK6DPE8wKwm9KaoqE4XuxsTbpX6sPcR9woyPx3aXs9lqrASELIc+j6/q3iWDwvLgS67D4ceXoC3/Zx0LBc+JWjXMwqWtsIJE34gpE6XQ60pMJzlI3PkLQ5ax2t2AYV+J9Yb7/aWzO6d6Bl8iXVJWeTAYo= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E6D9385609B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMhK41008504; Fri, 13 Oct 2023 22:43:20 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc7usj4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:20 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Qn008021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1R016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 14/40] c++: Implement __is_scoped_enum built-in trait Date: Fri, 13 Oct 2023 15:37:28 -0700 Message-ID: <20231013223957.1634024-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8aufoB2dQgTN5KBii8q-syxFGGhouSEi X-Proofpoint-GUID: 8aufoB2dQgTN5KBii8q-syxFGGhouSEi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=866 phishscore=0 priorityscore=1501 adultscore=0 malwarescore=0 clxscore=1034 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1779682733624254237 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 161 +++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scoped_enum.C | 67 +++++++++ 7 files changed, 160 insertions(+), 80 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scoped_enum.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d09252a56b6..1c0b2e0f178 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3781,6 +3781,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCOPED_ENUM: + inform (loc, " %qT is not a scoped enum", t1); + break; case CPTK_IS_STD_LAYOUT: inform (loc, " %qT is not an standard layout type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6d6dff7a4c3..e0e3fe1d23f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90fcdc01de6..f3fd82ba549 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -59,6 +59,7 @@ struct cp_trait { "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false "__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f22a6e93618..9c18165eb68 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 45, 5, 20, - 50, 0, 30, 5, 116, 0, 116, 116, 5, 10, - 30, 0, 5, 116, 10, 30, 5, 0, 25, 116, - 116, 5, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, + 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, + 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, + 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,56 +116,60 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 50, + TOTAL_KEYWORDS = 51, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -173,22 +177,18 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" @@ -197,47 +197,48 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" - {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 49 "../../gcc/cp/cp-trait.gperf" + {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, -1, 17, 18, -1, 19, -1, 20, 21, -1, 22, -1, - 23, 24, 25, 26, -1, 27, 28, 29, 30, -1, 31, -1, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, 39, 40, 41, -1, 42, -1, - 43, -1, -1, -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, -1, 48, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 49 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, + 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, + -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, + 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, + -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, + 50 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 32880754020..f56ab031d5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Fri Oct 13 22:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194056vqb; Fri, 13 Oct 2023 15:50:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiJ25WOfYy0u85087ZGXoRWqGxk4Am7IFMdAfA0+wZWrvdvqjB/nI7UAXyqQvq43j2EeeY X-Received: by 2002:a05:620a:44cb:b0:775:6dfb:874b with SMTP id y11-20020a05620a44cb00b007756dfb874bmr35935492qkp.51.1697237421867; Fri, 13 Oct 2023 15:50:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237421; cv=pass; d=google.com; s=arc-20160816; b=D7cHiCfmlDdwVlYF05wcrfvqMoOz8cNLPN4K6vRQYlzEaFYfdadfvBKfNezJYhMHCT q6IFf/cpOecEzjnsmnYo6oQdA3vTY5anFxOu78N+MGihpPE/knsuA/T9Svr3Y3pVTKY/ YFwpDtag7/FOMh+k2qsh1IrrZETikw2RMYE6e9/NFDaXbifGHGFfAtBub54pHlFhF3Gu +b6kFLDRTl0pBvYbdAMTwS5VHb+U6PoIhfgxm3m3xQSUctvVmPBK9K0++JCziCR0MLxf PKiIkc8fKMQS+8Qg4hPg3rk/NODthWmuOEwRmFVzCJWyPZ5OfAOaLJEwei4GjNWM0PT+ XOcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=eTYynmG1JFzS9StBjxf7V9+3uuIMHZbF5MXvNpbo7iY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jUDgXPIZx2TOXGqo31zssHNBNJz/JP2Y8jzCXxVGW6SfoDIUPJlFPJ14QzrJDBYr4O xP+8HsR/ukl/lT3YjqHA5f6+Qvywxa1suW/YQz23+SGzsyfqZ9OfhRa/0YV7dYiIj2dc 0EhILop661HFasbTh8EYdonRqfMUQxo6ZlRjCzY8dlvRGR6MTMPuUf0Ag1bt45GrPfxE yyth7GuoeNocYbsOpX4iqmfLsYiLIDZ1nupe52H6QsF00aye5thbcdxpzi1ImShB/jiC 2i2N4pEWiOzT/349Nuu81qplwn7wou6U/h5kyowpHmJP10TuIePiYE7Raa7EaTP5PxNq VZ7g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="SIXV9+g/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dx7-20020a05620a608700b0077568c879efsi1895908qkb.154.2023.10.13.15.50.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:50: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="SIXV9+g/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAB51385841B for ; Fri, 13 Oct 2023 22:50:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAB51385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237401; 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=SIXV9+g/zp8S0j9uhrHx0pBFWMAs3vrDq0WSljPTX0o59Vl8CkkLQFIJuF1KcYJKx CRJuszfhnMwZXYzzhnL9oGsT9Kknzb0VSfWqyBOwom3C5doVxCDUOUv5lx5EbtV20d FYWbeTpHZzoqsJ2lvYx9HachGbgS1VEiDhqaC94U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 67EB23856DFE; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 67EB23856DFE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; cv=none; b=Si2WBcjYxNNjL4ztYndwGu387+/XtvawbftNdUaYN+E/pWhU/Ssmxk/Dhsl9Gj75Ie6nLcxv28e1/0qYBZ1Bew2m+UzlJq971B1yGtAr45IDoku3jDsEWMCIIzQsH3f4rWCNpuRHVkK76bZPc3mWrErVlG/xHINWxbeETiKzpV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; c=relaxed/simple; bh=Nz7P73GKgdaoysk+y3xwS5zNXk6vIepk6igOSMNcwIA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bEAUOpV8lydxK3rqL1eSSbpEhIQ88m2bWr4wpaU3kX7K2aZsIU356TP8QYXLyD8N+eY48xZ062AMqmhrLQmZ+W7Clf772RnxOfAbWdfSWRDbc09edWgfTCIUCzLZ+gMhQtx2/qG9IZiC/tE0PN+IhHRVQhCV/esQVYAhya9bdCE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67EB23856DFE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMTicc021741; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15ex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2DP001548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1S016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 15/40] libstdc++: Optimize is_scoped_enum trait performance Date: Fri, 13 Oct 2023 15:37:29 -0700 Message-ID: <20231013223957.1634024-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 1xKiETtWJSXOxGMTeSttVWACAL8JO2hU X-Proofpoint-GUID: 1xKiETtWJSXOxGMTeSttVWACAL8JO2hU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=768 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776994899316432234 X-GMAIL-MSGID: 1779682426927458542 This patch optimizes the performance of the is_scoped_enum trait by dispatching to the new __is_scoped_enum built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_scoped_enum): Use __is_scoped_enum built-in trait. (is_scoped_enum_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index d306073a797..7fd29d8d9f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3633,6 +3633,12 @@ template /// True if the type is a scoped enumeration type. /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + struct is_scoped_enum + : bool_constant<__is_scoped_enum(_Tp)> + { }; +# else template struct is_scoped_enum : false_type @@ -3644,11 +3650,17 @@ template struct is_scoped_enum<_Tp> : bool_constant { }; +# endif /// @ingroup variable_templates /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp); +# else template inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value; +# endif #endif #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp From patchwork Fri Oct 13 22:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194269vqb; Fri, 13 Oct 2023 15:50:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjrmuMZ2WuvISXJysmerRwHqkJcjo7Ug0z5dUrIDa8PIsp0WyN9iMtivTBZrln9IL/K9Oo X-Received: by 2002:a5b:a8a:0:b0:d80:1604:f6e9 with SMTP id h10-20020a5b0a8a000000b00d801604f6e9mr26244513ybq.44.1697237452679; Fri, 13 Oct 2023 15:50:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237452; cv=pass; d=google.com; s=arc-20160816; b=jJJBwCY0JvVZNdChAVLoFWwKuSdZgczODvAWgV57lGIv5kRAjpmS7i9DMiOu6KiZL3 qeBfeSO45WIm2fCs6Iir83E2LB+GDhFnMh6XiWhU0xxYb8J3NNTlfuFNMvPzCnx8iOkO a52cUprd2GJddWCMeM91kZIIQbFp6IOzMe0R+hsoK0VFIFMVOgjxLwiKZGPeWG9uIhB5 9KoSEBxMXHccv6TWQIlxFU6cOFD63d4IZ/c2kHSVuLwzLlZsuCvA5jw6QxCekwlzD0Pp 0Iq4tVGAD/lku8nyI0NAVcyabFT/aDiLMq/q2p/5wfz7W1bWb7Ek6Zb9ZsWOmkSBX4dc E8Sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=NNA5LcyrTMWVzhvb/kOJAGK4+yp/NMHz9oDDEBNOqXI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=DDP8TxiQmCRRnTP/MKHhV1a+r7U1VLfV4W8HhI9UaX2ZN7uA8ghSubbotZn/NaBq3p ++DF3JKpdFaPLaDNgqM8UMxtqlElT+Huli2TOOSmuCP1mQ5mGh4LrYzd/Ag1/3xaW0cH l30qxw7lD+ld8sr9OHkQG8Hra10gRDINEETHK+rlPUXZBdNDk3TZsPO4diwjAaG2Tuwl NrspjoROdxTBm1lBdyyAPPDEh5ymUeCnH1dpXRHrlfKOSL634Wae0NRE0fB4KV1BRfxu Q2FIrw/z8yvwB9AGsDt99bpHFmP5+UFfb71bBAEMe2B8dfiqqytxiRzNTxyyN8obPNiK XSfw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YmTYxW6X; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id lb25-20020a056214319900b0064f4d7d85c4si2002286qvb.354.2023.10.13.15.50.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:50: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=YmTYxW6X; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 89FDF3865C1F for ; Fri, 13 Oct 2023 22:50:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89FDF3865C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237432; 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=YmTYxW6Xec9bpZyPWhA6lu692M+HFS1neTHaTc0llrygcw8I/ch7pLoOS1E01gMW0 81+WGmWc8aLNjLdG+C4aPOxCP2IUh/8caLltPRnO1JXEbN7+rM+qAnQrMS1TXtoR+E 00UooF4gSJ/JnH46H2TfI+Bn7qkJrgvsYq3Ws89E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id C7B58385B512; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C7B58385B512 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; cv=none; b=I1sMMuvh1gaaG+yg+YoDmfPpXtV5aFcJ9qldV4wrHb12R/kL4yF9cr0KNQED0EypT/P1K3pbYSJ7XxWQom+AIFy9+4iDvTg9ofdIhHNQy347ag+bP218Ihcso8DEiBICZShsVy8UE7HYDhRjdxZSBKYjEKYe5cedPsl30QLfTck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237011; c=relaxed/simple; bh=1JB3WSn5crkfytlv76hSa+eBAv+J5ca/oP08hFCfW/8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DajBrvoa34WNFtFNB/TaOLwk0CxQEsU3BT+LDhf6nltzbuqcfPDF8HW0EpHzTh/Ka7UdRTVZp7CcVFjDB1Pt1M//yv42m2NiK7D1rDWhUUOhRxY7BAD+u4VegMxfpF4tKgGgLhdl7nf1g7QOoS4GjXMRyLh5074tT4QluZo81PA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7B58385B512 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXhBC030698; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfga6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2jD001588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1T016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 16/40] c++: Implement __is_member_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:30 -0700 Message-ID: <20231013223957.1634024-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: f1jC9NT5UnOw2CBCsuwMDbBNLQXgt0Tj X-Proofpoint-ORIG-GUID: f1jC9NT5UnOw2CBCsuwMDbBNLQXgt0Tj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=832 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1779682458845480991 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 153 ++++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_member_pointer.C | 30 ++++ 7 files changed, 120 insertions(+), 75 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 1c0b2e0f178..f0d3f89464c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_POINTER: + inform (loc, " %qT is not a member pointer", t1); + break; case CPTK_IS_NOTHROW_ASSIGNABLE: inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index f3fd82ba549..3775b11283d 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 9c18165eb68..dfd60cec6e6 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 111, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 0, 5, 50, - 30, 0, 40, 15, 99, 0, 99, 99, 5, 10, - 30, 0, 5, 99, 10, 50, 5, 0, 35, 99, - 99, 5, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, + 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, + 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, + 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 118, 118, 118, 118, 118, 118 }; unsigned int hval = len; @@ -116,69 +116,67 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 51, + TOTAL_KEYWORDS = 52, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 117 }; static const struct cp_trait wordlist[] = { -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -187,58 +185,63 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false} + {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, 13, 14, 15, - 16, 17, 18, -1, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, -1, 29, -1, 30, -1, -1, 31, 32, 33, - -1, -1, 34, 35, 36, 37, -1, 38, -1, 39, 40, 41, -1, 42, - 43, -1, 44, -1, -1, 45, -1, -1, -1, -1, 46, -1, -1, -1, - -1, 47, -1, -1, -1, -1, 48, -1, -1, -1, -1, -1, 49, -1, - 50 + 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, + 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, + 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, + -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, + 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, + -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, + 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 51 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index f56ab031d5f..6c4880d8a33 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Fri Oct 13 22:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152807 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193174vqb; Fri, 13 Oct 2023 15:47:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE77iCJ1QVP74bGE5Lk3rtM2xUEQKOg8279L18xUvBBpFgRlGqksAHt/O6NxK2f0qammO/L X-Received: by 2002:a0c:aad1:0:b0:66d:2e59:4fca with SMTP id g17-20020a0caad1000000b0066d2e594fcamr2378030qvb.35.1697237265606; Fri, 13 Oct 2023 15:47:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237265; cv=pass; d=google.com; s=arc-20160816; b=pTcdUVCxJ+hPCsvo+sHSkwRg18gTFZtE0JRiXSJoXQ0lS83bnO9jwDE26IXRdoNozE VSNDPc0fbXDyWjBszm8sR5k2EjLIJ+3Hg6Yu2QzwCX2Ow9I5EUvSu3uStySlOf6IfsHo V5bEHVLF6+c9FrQKK2nR+DLrS+XxNAW9yk3ucSfYSuy0wCU+riMpPx/KvQLLE4bK55J4 3Q0+rn3zbrbJaf1vAZpH2oXUnAKPx2ZpvoGmTnXTEuYIXlDbaxbLlJ4vdWD1E8zbpTpz 9CcwfVJyGN1B3ewqv2RFlitpWvOafvGEvjboYJEJ0WxQsAKqn2xf3lt4gceTzdO1Aadu JfTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=PeJ2k/Wq7gdndA8HXsVxxiKd/y4nvV7Qg8DUS1uDF0Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CuDSEs7WoRwXZFCKBmJgKSzeZlHm6+ml0nAgjy6oIxEd345O0xNAFyea4ddC2LimI0 y4ITrR/tg/fgTUKD3Ta0cRaHngrKqKyMHKjkR1OomtemXeMjabUQMzuOUiHWu9YbINKk zzRHuCadKrsbSOB1FE2b05b/m6g7EqEIjGS58KUvluojN94/QZQGE1COSQ0weFYVv+fC ECNTTooPLV9gziwOUkK0JgZ1uMMQGytsOjUZxm9/Pm8n9kqGXgTUH+pASUUoWa4JUVYi 4KEZ3aMJLaD94hc0VuxkRD2R2z6730Rmvcie456z4KsDQ7PFeU9gtCMTv9h0wtJYMTP4 4gnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pX1HGAvH; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m8-20020a05620a290800b0076da7849687si2047184qkp.344.2023.10.13.15.47.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pX1HGAvH; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C20EF385CC80 for ; Fri, 13 Oct 2023 22:47:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C20EF385CC80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237258; 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=pX1HGAvHNBPU3J8JLaolInNXSPAPFYvKJKF7oXy8EOz5w3nOKSdsinGPR6/kdsog7 JtgyVuv4Cs6sm2JpXdNm24Ltd/C1rugKvKK0IvVQhzTHcluYcO5EC4ClpklQGG5vjW uN8anCOzpfmC3NCy/rHdw59oymo3FP2KYM7OGmqg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 5E5EC3856DF1; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E5EC3856DF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=REKJllSS7fOYSayRLtcxzD9R3onfdomLcWTssOCp442LpAxY3Uq0t6r5dlTgwByEG0/q4Wlyghx2Ta+HC/fcJHlzkFxl+soNegSHWpl+lBt8v6BWu3drNUAwrZGh9+2GFe+5JRUBGv2KmHn3q0yK8g830V0pK4wTwU4s6KEI7JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=UJgksNSlORUlZPpOVuq0Q6PZq76Ryp5/hjZPmLb21rk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=G6/27GBcFEsT7OZdrjt5qC/iV0JjVTUM+o/U87f2t3ntN58Un80SYsWC1t5q2BD3H0JYxjX2htunFo/MHr974QCiehBG1HMbFMaAWOiDzkvFiymWsYeKOU5HUNFuDjEegRJIK5237LLNdyoRe/TiqU9gVLqoOAcCJsGGjnj4AiI= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5EC3856DF1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMfHFf030971; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeqrtsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2BA003481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1U016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 17/40] libstdc++: Optimize is_member_pointer trait performance Date: Fri, 13 Oct 2023 15:37:31 -0700 Message-ID: <20231013223957.1634024-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: mFdC12rHVB74noYNf-PuF6_qmu-27ZY_ X-Proofpoint-GUID: mFdC12rHVB74noYNf-PuF6_qmu-27ZY_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=580 phishscore=0 mlxscore=0 clxscore=1034 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996307296308519 X-GMAIL-MSGID: 1779682263163246567 This patch optimizes the performance of the is_member_pointer trait by dispatching to the new __is_member_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_pointer): Use __is_member_pointer built-in trait. (is_member_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7fd29d8d9f2..d7f89cf7c06 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -716,6 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_compound : public __not_>::type { }; + /// is_member_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) + template + struct is_member_pointer + : public __bool_constant<__is_member_pointer(_Tp)> + { }; +#else /// @cond undocumented template struct __is_member_pointer_helper @@ -726,11 +733,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; /// @endcond - /// is_member_pointer template struct is_member_pointer : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif template struct is_same; @@ -3242,8 +3249,14 @@ template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template inline constexpr bool is_compound_v = is_compound<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) +template + inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp); +#else template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) template From patchwork Fri Oct 13 22:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193321vqb; Fri, 13 Oct 2023 15:48:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRTwj2VZb8t40wKCJbfTC7F4FBkXPPS76SPFItEqHzd4Gk8XE5oSkP7gN5P/9npjXkPV2D X-Received: by 2002:a05:620a:1913:b0:772:553d:a49e with SMTP id bj19-20020a05620a191300b00772553da49emr35496894qkb.18.1697237287378; Fri, 13 Oct 2023 15:48:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237287; cv=pass; d=google.com; s=arc-20160816; b=kb5AQr8oTVAywchjI4ykgOk2E1uXPnBHLtKoiFB96CsIPB85I/olddwOGJcPByFaMd LWInoUZIyQmZwsuTIU0zbC/BVv8p9zoWLY3Tz+cNWaWuqIAVj2pFueJ6kVA3aYQNU5xC r00FkxlA7Zn/4lsq8PWhDZvJ85Csj7t2cetPUzhqM4wxwSc6QF1dESx7Oy3HH4E64VGP cGSWi7uJQ2NgJfAn17pa2j0M49OGVCd0waRFwEURA6r1roqxgu4DCRB+KTl5bau4UjDc /JXCT7FgAqaY8i7E2+rA6OQN+4yhtPjrz7Eg/S4UnK6EHFGuOSzQUZq2yorU4nY+hJnu XZzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=3bNkJ+qefz3w0BXI7GF4h0ddBlYhCqJolSq6uux2RW0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=WzsbdpVVIDP6nyICVsfU4802gN2XZAK/uDremLFkGalRumCyfQzGmRwV6u1g1uUM8i QEcOzwNmk8k//Za5hp60KvE8PKBWBFYuZM0DwttKSvOOBaKAJiq6rGHroCVX11BCkW6f 7FgCcgfF5MOb5i6OhwsaN3gwPM0bdFNlRjNRJhtOuXWiowSq8A81/1H+a+T6TwtzypR7 0Kz6bv4LBReWmR22Bo4p4UYyPgUJVvKqdKnif671ntc0SjB70wG12qRNdE3TaGizeHdg r/Tdcje8Evu26MXjIJYzAr0fou4kpaSvPOyS+EGgy2D0o0QpjI3LjpGazYs3FmBi4N3Q qzAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KU4aQpVP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bk38-20020a05620a1a2600b00775ae264d8esi2067111qkb.293.2023.10.13.15.48.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:48:07 -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=KU4aQpVP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09ED5385B513 for ; Fri, 13 Oct 2023 22:48:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09ED5385B513 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237281; 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=KU4aQpVPuDXCZ/d488cZYN8PZhiA1lrQu/pccwwCuRyPcxSmaDtSwNso5c771Tb+D MWjmpXjZONBi4OxxFBHPhVPOVY1MVvyGJ24zAvW6RcPMpL6Swla/4ebFKKomYuKiNm P1KJa8HwVnhlWKxJ1EdXxzaEwC/D2IzG92bfDEuc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 616AD3856DF8; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 616AD3856DF8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=mzNGe/DJzJunZDXOPjKAUtCSahtCQOrxbNbmwt4/pehpgKcm6gNNY63I+9qbRsNiCDBONN2Z8UcW1ZJ/fwSiuHRrcteuKuNo1cuZJMOxgcokMFlQwwjANUEkr5git9VeoydOz87NR4sFX7SGO3pYrzqlahoWbWWIG/JwvLedEE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=DzUVpyOctR/NNW/yj3m9FlgZDpcOLFX/MSM4xIbD5xg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ng7JElLXOISljtGumJikla+o6XtgLSr5xjxiqFxYeFUHfrB/tDTEqNihA5vu1/FgTJnyFVyU24iwzRTtakZwaIbi5gLqKVyQTo/fXHogdPgweSVQt+ot/Qv+SaK5oZWlUEdDb8R/7lZPhxisQLN8Lrp9+wqxcjbQy+TxYKkdqKQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 616AD3856DF8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMdklR026434; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqe7n8c4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2XI003483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1V016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 18/40] c++: Implement __is_member_function_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:32 -0700 Message-ID: <20231013223957.1634024-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: BuGulSSrgRFmZVcR0LE1YYumEX5bgqI0 X-Proofpoint-ORIG-GUID: BuGulSSrgRFmZVcR0LE1YYumEX5bgqI0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=901 clxscore=1034 malwarescore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1779682285573215022 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 176 +++++++++--------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_function_pointer.C | 31 +++ 7 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f0d3f89464c..d0464dd4f6a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3756,6 +3756,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_FUNCTION_POINTER: + inform (loc, " %qT is not a member function pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 3775b11283d..b28efbab322 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -52,6 +52,7 @@ struct cp_trait { "__is_final", CPTK_IS_FINAL, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false +"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index dfd60cec6e6..d3d4bdf9799 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 111, duplicates = 0 */ +/* maximum key range = 89, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 20, 118, 0, 55, 50, - 40, 0, 40, 20, 118, 0, 118, 118, 5, 5, - 30, 0, 5, 118, 10, 50, 5, 0, 5, 118, - 118, 5, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, - 118, 118, 118, 118, 118, 118 + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, + 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, + 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, + 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96 }; unsigned int hval = len; @@ -116,132 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 52, + TOTAL_KEYWORDS = 53, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 117 + MAX_HASH_VALUE = 95 }; static const struct cp_trait wordlist[] = { -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 75 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 42 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 48 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false} +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, - 15, 16, 17, -1, 18, 19, 20, 21, -1, 22, 23, -1, 24, -1, - 25, -1, 26, 27, -1, -1, 28, -1, 29, -1, -1, 30, 31, 32, - -1, -1, 33, 34, 35, 36, -1, 37, 38, 39, 40, 41, -1, -1, - 42, -1, -1, 43, -1, 44, -1, -1, -1, -1, 45, -1, -1, -1, - -1, 46, -1, -1, -1, -1, 47, -1, -1, -1, -1, 48, 49, -1, - 50, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 51 + 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, + 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, + -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, + -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 6c4880d8a33..4d521f87bbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Fri Oct 13 22:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2196013vqb; Fri, 13 Oct 2023 15:56:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH0kuYj/N8PY0ZfnSn/pRQurPUT7bXKD7sljS94OQehc92i3AHqHrlUCtGJn2eI0Bg1ZFR X-Received: by 2002:a0c:f38c:0:b0:66d:1f6f:1645 with SMTP id i12-20020a0cf38c000000b0066d1f6f1645mr4232771qvk.27.1697237771443; Fri, 13 Oct 2023 15:56:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237771; cv=pass; d=google.com; s=arc-20160816; b=qn8PMe2mh7pFwBsrU5DPSudzFs6kZs3eMoXlNrq1vsAAOEns+RkWU13oF48Rjt09HG SOk5KWMUTCVShoH7FP38NUvhVHJum7RNuKjNaN0CNoAoK7e09Q+CEx8+e6/xSnHt7Eu0 IOyZG3Qo4cE3Jd78TYKqpYlxAyfOCVcG3rsZfykByfE9LxPtiKJ/jzX+oGAniOKmNvlQ JaiP6egdO18jsEbrQiTsgoUmRozNDHnxyjoG5+zKeOozAyO+kKY4rGlSasqt8FBy/Jwr cEaYO8GmDgA47ht+6IpY1bZ43LJwFeqjBpMI3RPKUuOJ1aok7lmP27EeIf1BogJh+bOo RWDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=ixwYONvJgNS3nm1g76jbi6vfkThyxr3CvvJiXmiywEk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=N8xpL0UY2GEpz1nvEowPmgEkHMrWcuG/97qpDb/xXud9UlV4cnymmGTLzSlUnqOUHg g17SR7nPPtnBGT/TDlIJI3Qeomz3M6Cbj7o0jQEah8T4cFP5+B6ZSAjwG047xltlD8oi AIVDpEas7dlIJGzeDj57cZPoBA7AC3WOCKtSxGR5ZKiEa8+DKtdz0lphSIHXFVrk7ijG O3kGaI/ieNTRDIaZjY3LR1cL0tE1fc8cHpgChWoRw2gSW+MI8RPAsMaDw1iS4srMJsO9 Hw54svv4J501ZxMCp2PzsR2iAAGX3fzrGzyhxXGgxnttDI+iJtaMLAa0Omi/oF4+NpL2 syKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b7nPxQrR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w8-20020a0cfc48000000b0064bbe315095si1928442qvp.68.2023.10.13.15.56.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b7nPxQrR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 718293856092 for ; Fri, 13 Oct 2023 22:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 718293856092 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237769; 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=b7nPxQrRCzrGE8Z/2V2ChuNZpja13yuxZe/G/RnoXHs9vIBuFXqpzz1d57N7oehRB UhOlyhndolyKSZST19VrkgKGljoABJkTww7N2vpnsWExjjWvjf0GvPlj7YinJR4K0t 4b7XC5WLtqmfGm2w1gNHL5Ey/K8TBNFBUfBDkv2s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 0B0F2385B531; Fri, 13 Oct 2023 22:43:23 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B0F2385B531 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=n9AjlQSvG1zM6MwlZZb7k6d6ozcI1SRV1uBcYmZ9mDUZzKwkTirFAtKSv6MWGxHRUuoVpgOHFGv3tJsXFxSFajAA2inyZGUCdNVnHnUhqC+iSEv8XRwuQkqKRbPEUn/+/KuIan9CjupLktOQoz6BQhd/pn354fplN7lRsg6XeoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=QuMkc1ehlJ5Wg8V4Rsxxo7gXiPPchTtHkDih2h1/T8E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nBX0kASE5OBYWEU1O+xElZUrwzj1KAOruNj05KTxQmL2tJ6bZsZAwmB3pFqCfom/UxUM27mBw6qfjwNoje+En9+14icX7v9GNvLvpeZ+9U5qZSm3bY5ua88mIhJZ27ZzgBbx9Hqi2cPv5zEB7QUxfsnvCKtV4FDH7EEzv29IJVA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B0F2385B531 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMaOI2005493; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2q5008029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1W016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 19/40] libstdc++: Optimize is_member_function_pointer trait performance Date: Fri, 13 Oct 2023 15:37:33 -0700 Message-ID: <20231013223957.1634024-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ppefL4jqnpTd19YgFLQrK3FwIU_05hfL X-Proofpoint-ORIG-GUID: ppefL4jqnpTd19YgFLQrK3FwIU_05hfL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=665 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995423218726551 X-GMAIL-MSGID: 1779682793461865262 This patch optimizes the performance of the is_member_function_pointer trait by dispatching to the new __is_member_function_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_function_pointer): Use __is_member_function_pointer built-in trait. (is_member_function_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index d7f89cf7c06..e1b10240dc2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -588,6 +588,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) + /// is_member_function_pointer + template + struct is_member_function_pointer + : public __bool_constant<__is_member_function_pointer(_Tp)> + { }; +#else template struct __is_member_function_pointer_helper : public false_type { }; @@ -601,6 +608,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_function_pointer : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// is_enum template @@ -3222,9 +3230,17 @@ template template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) +template + inline constexpr bool is_member_function_pointer_v = + __is_member_function_pointer(_Tp); +#else template inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; +#endif + template inline constexpr bool is_enum_v = __is_enum(_Tp); template From patchwork Fri Oct 13 22:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194556vqb; Fri, 13 Oct 2023 15:51:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkP/olJ9bqca9iHvBaQQ3c9Ats32xmGYCiRyQqDt1u5v6ROOJnwNXqB2yzJa9FQE3B9Jrs X-Received: by 2002:a05:622a:1053:b0:412:132d:3e62 with SMTP id f19-20020a05622a105300b00412132d3e62mr35051432qte.5.1697237505042; Fri, 13 Oct 2023 15:51:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237505; cv=pass; d=google.com; s=arc-20160816; b=qPZUrJVaJ8rQ+dElfIfiJOU71JHXmc9zk6Risx8F3vGXouCDWypKb/ALdtPNlDsca3 troe9Ojbej3g1VNt/Zump6SALD+AOLQzJloTwwHlMm/5Af7nEVEGIpAJm+E7CW/ZJGRD YdoezxiieRiBfeNQ0xDLFZyov2m55gKsOohn9wRKsSjEr5vS0pkFrlJdhANAaQXX6GFF L7sMgmEQ4ji1g7fV1/wwQCaNDa6p1VvU3bA4JrwN9dMtO3Y5c+73QeGAS/vJTihfKMzo gAuInb7+6wyGv8zeYhCIaxFH4WgdMiarfX8rcfJl5wUDee7PBHCQjrayjTsVqquSoUjU 6cag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=NfSBMZJXtDtpxCvY8bx+B8abLLlMoDMAByiaA61Vgwc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=DMAp5W9hw+Pwz5PVpDGz0DRI4YyzFxQp3x7HrxHNhac5HrvQaMl3PJNgSEToVx1Ziv vRELa6+WHddPjRLIEadt5+YjAbgLcDubx1RwXdb+DMRJdeQqRTz4bHAiY4iWIZFRmsr+ z2g+SI5ienQEd5PvePQQjtRr3mBkRFa+L/ldqA3K6MW75e5kU49YxCQLUplDSP2UJvVz XItPD7K1qilhdAPzXRhsJZkhvVswY8Ib5fV7jJwdviyWPfZqIcNdbxP8W2FuYM2YkL7F 1bfzRm2r7koA1wKNgMZV0MClXn497woLwNMwtlGhjEIPvmvsNaxmesXO5UR2wfyBTZ6S mnVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i2JNaZD1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 13-20020ac8570d000000b0041971a2b466si1864090qtw.715.2023.10.13.15.51.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i2JNaZD1; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E9E03850350 for ; Fri, 13 Oct 2023 22:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E9E03850350 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237488; 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=i2JNaZD1iVi+VaZbnuYqb+laKuhZB1PgEvSHZKcmkEiI9+XhPjgk4vffrPRQipx87 /sFnaREKJlsy8RaIzDQ/ODq3mQ/kDyLLktIrSyjr4+qVAEVMWhCGwLd0nClkRiwcO4 DP5UGuir+K4SnLZF57s6ryadxmIVW1rChfgdAvio= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 558A53856968; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 558A53856968 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=bf7rJ8Trlo2hv9Q+Kptdll2Ld90WGg2Tjbk3gQXLlVTd2KHehgq69THZCqJOCQKxtka5B3gU60i5mogBo6NFSbVQVFq5LP6bcJcMSMdFVyRhzbglyFa2O2XIG2GkPtXX06dwKC3A4u70M31KpPnsUkih31PbI2LtinxGuNqW87U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=17iXH4Kz9nRm/qvyK7TLTejC/fcRvg9+OrOovzXpYJE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JaVcfDCFU0tO/AYnlHCXoWXEuWASTmHBgNPK1ZpawXc53CPvnLZaWNgswaIjwtrPrsHYKXq2p7hzD/oH04647uRO+Mx3gHCFdxpjwGecr/GdIw+7eOmx6endWoghmt5mEPChg9/c/vMlRFkV2Uj5qWwsNyYRMxJJGgwlVmxuRTk= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 558A53856968 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMdxLw028167; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2SL008034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1X016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 20/40] c++: Implement __is_member_object_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:34 -0700 Message-ID: <20231013223957.1634024-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: NlJaf4rxOHYa7O-BcVORvz4oeMhtZz1s X-Proofpoint-GUID: NlJaf4rxOHYa7O-BcVORvz4oeMhtZz1s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1779682514494023332 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_object_pointer. * g++.dg/ext/is_member_object_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 62 ++++++++++--------- gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++ 7 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_object_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d0464dd4f6a..98b1f004a68 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3759,6 +3759,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_MEMBER_FUNCTION_POINTER: inform (loc, " %qT is not a member function pointer", t1); break; + case CPTK_IS_MEMBER_OBJECT_POINTER: + inform (loc, " %qT is not a member object pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 897b96630f2..11fd70b3964 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index b28efbab322..32199a1fe9a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -53,6 +53,7 @@ struct cp_trait { "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false +"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false "__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false "__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false "__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index d3d4bdf9799..799fe2b792f 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 53, + TOTAL_KEYWORDS = 54, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,57 +125,57 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 76 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,25 +185,25 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, @@ -211,12 +211,14 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" @@ -229,7 +231,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; @@ -240,8 +242,8 @@ cp_trait_lookup::find (const char *str, size_t len) 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, -1, -1, 46, -1, 47, -1, -1, -1, - -1, 48, 49, -1, 50, -1, 51, -1, -1, -1, -1, 52 + 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4d521f87bbb..9cbb434d4c2 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Fri Oct 13 22:37:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192828vqb; Fri, 13 Oct 2023 15:46:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJElea34iqi4rEENbtXDf8ElVASLB/ikHUdJKvyYM2P0vtGO5Vn3nNPpfeGn/B6kGTo9zA X-Received: by 2002:a0c:e04c:0:b0:66c:fcfc:9174 with SMTP id y12-20020a0ce04c000000b0066cfcfc9174mr11071587qvk.41.1697237199226; Fri, 13 Oct 2023 15:46:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237199; cv=pass; d=google.com; s=arc-20160816; b=qSbePvLZXLko02oNN+CondaWMR3x7zIXFAuuWA6gXAiddxQPZtt3Jj6DaS8T9ozxEA gL3wZtcnY1ecEfnzSTrCGlxYGmc1WL7Bz+0hOWos6u22+DUg3HOjzO7VKfw3G4e21BNo A/MVhfULqEXu6D1kuI1Kwnv2El2TlK96VUqULssDSHyRvKgHzPB4gex3Pl1Ts47No415 7UZn+RYEj50RczEoikRqMMqXchJ9P/n+vLcltXhbKme3ZHGlZG0kxho8S/l7pR0+9ze2 owXGkINhj0YfP+D4uv0V3w6f0o1KmHBg3qzCFBqFc7ZI0cPj1J5I4oudQr6Mpzr1O0lw hkyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=G0ET4lrvWno4IoFSJOT9pKXCJk7H8ixcfAHZNPjj53Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=oVbleqzgj3Ev9iZgs690lMC+OfW3k4OL6e8buzcyNr9z11AcOSxg3cDZKHsxoeYNi2 lTFzBKavk5Bv/C/BVIpJ1At/7Ymbem8XtUAebetWlao+LrHJ+AGk7UT1Sspufi7N3eXX 6DuqSI6aBq16yjKFhZNVUjwPvuPwoL0b6knDm7PZgWaZ5Uayos9yPZpmL7WwiuDw1wLT LhGY1gzhiubFslbmFplMRHnSuoN+10V6w0caVl1eChk1q9Pu3hWUcFtQbKgUJCB0K5tI 4OqLRRVoTR9z+CGwyBsEpTvG/TXIvfTl5wQH+nYc2pNLw3UcUVTsqGLi3q9PAQNz6wPm 5EIw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IvHSgszg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ks14-20020a056214310e00b0065af5e98ed5si2009428qvb.290.2023.10.13.15.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:46:39 -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=IvHSgszg; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3496F385C6F9 for ; Fri, 13 Oct 2023 22:46:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3496F385C6F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237193; 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=IvHSgszgm69rQKuhJGt5jl01F3BtNY6hwKMb9mneQkRgPr+YWahVI+iE25rZOznt/ mRAihEAF6B5kwk1OB13oTORjbIqfEdgLEmd5q3VosXhF4UsfjE6nS6eAOQiiZGlt6H VcVD0YsoizLIjB2nTERYwOB1xMfthaIREr+4XZr0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 3C1453856DC6; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C1453856DC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=TJ1D0Izk44j3CE9TSYlQ5RreR9FfJMtHxZgRqhILePwy/Gk8BPiSrrmGEHzKy+Q4P79aGus4qoymHRLIrjkp0LNexvRuDOgD0CksmMxqmCP6lEoIWCoJuI+AoFrFgsLG2SsRXBL08vIInDqOpry2kV1CnfhFrTjvZ36C8yYtiFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=0fPox7o95TE1z8HSfQmP62vuVnxXyv8pdeoAV2lJZWk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EjlrlyCo3CqzxWTNaRQmRqjCe1JUGd63w9v22Z0ExzobWf+h6RtGUwsWKcXgA3uBiGV2jd+TEj45E9xr2zUwAPVV7UGXNHdIfROGomnwmFKoJxihR9rip3eGxKlCllmI20VEHTLfAioASNZdESRYuABYOdzA0O2b4X9Vvp09MI4= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C1453856DC6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMYn2x019858; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2ao001560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1Y016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 21/40] libstdc++: Optimize is_member_object_pointer trait performance Date: Fri, 13 Oct 2023 15:37:35 -0700 Message-ID: <20231013223957.1634024-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: p8LRpHXi2ITTL8wPFvh5CDzW5Za4uvgF X-Proofpoint-GUID: p8LRpHXi2ITTL8wPFvh5CDzW5Za4uvgF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=596 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996522370919550 X-GMAIL-MSGID: 1779682193289779807 This patch optimizes the performance of the is_member_object_pointer trait by dispatching to the new __is_member_object_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_member_object_pointer): Use __is_member_object_pointer built-in trait. (is_member_object_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e1b10240dc2..792213ebfe8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -574,6 +574,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_rvalue_reference<_Tp&&> : public true_type { }; + /// is_member_object_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) + template + struct is_member_object_pointer + : public __bool_constant<__is_member_object_pointer(_Tp)> + { }; +#else template struct __is_member_object_pointer_helper : public false_type { }; @@ -582,11 +589,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_member_object_pointer_helper<_Tp _Cp::*> : public __not_>::type { }; - /// is_member_object_pointer + template struct is_member_object_pointer : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) /// is_member_function_pointer @@ -3227,9 +3235,16 @@ template inline constexpr bool is_rvalue_reference_v = false; template inline constexpr bool is_rvalue_reference_v<_Tp&&> = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) +template + inline constexpr bool is_member_object_pointer_v = + __is_member_object_pointer(_Tp); +#else template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) template From patchwork Fri Oct 13 22:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2196130vqb; Fri, 13 Oct 2023 15:56:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/J1bZfL7GTMY7R5mOJbhB+hjUw6qAvY/NpNFz0hiPZiZaJPNA2dhbQ79yYgUTAGUBNDAM X-Received: by 2002:a05:622a:1805:b0:410:842d:fc2f with SMTP id t5-20020a05622a180500b00410842dfc2fmr2053473qtc.7.1697237793726; Fri, 13 Oct 2023 15:56:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237793; cv=pass; d=google.com; s=arc-20160816; b=GW15J2s60R9GTyIhCV2VbooSzdEa58Zn/gw4Px+eaCfiyQVYca+aEX6WXrcutWxXHI +t1U9EQyX9bmvcRVlaVfXbevjTZVZVJ7/Jo3Oa+tVsYmxGcX18jootmMhe7f1WzUoRUq JMvUkp4MNYNWSmRMVmD6eyPTKDoKZPQ02olS9QK7QWEw3WHoLJIhtbSgZLQP0DJEQuMM 2upMA08Afn18INZC+BCybADIaaUTVPXlf0YkfVjJHmKJFmvugrqaxqutgltumh5Ckv/M HKH4BNDCHokvA5iis9qmDOKb24goSkV/eXAQvRFc+jYrhNH8psv6wCTak8hwSGkLdI0/ i9gg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=D5XC+sWyXNBrLWPVP1rjT6ABjNT2LfJ19/56u66CBRM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=zy0OOlJQg9YWy/vV1tVwvotj1upsi9w7a7ka9KaRiu1VYNnIPgWIw1yZ5laawnYVfH 77dURrDBmbpvo/W9eupKARdgFdFInJganG53qbPV9fH46VMSTdqFVkfp7xaMLWchsK9B m+fSv6sM4L9ZRKLm+sdZO9QFIVzddyKXe7hnohJ3Vv60nNcJqe6nXbuQ0HwnnPdCDjux VXcVDv2BpEnQbGv+pNYijHDo/P2Qzes3xzSVYc2GfFeMMB1abB3Lu01iEISa0/8rDoGl eHxlcA8WsylQg1CWI3zBWORMcljqrYffOR6oOlUMqU4/5FN9EBYDGZYL+3Goy6K4eaMf VO3g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=m4uXPFz4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u1-20020a05622a198100b004197d529cddsi1991305qtc.242.2023.10.13.15.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=m4uXPFz4; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 701393857352 for ; Fri, 13 Oct 2023 22:56:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 701393857352 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237793; 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=m4uXPFz4STXDVitHe/ur1SNC0F5BQNnxiP0vvGWg4NqblWpPZIxkoMnBFrKM9OS68 IhLDLAi6CeCjnvC6ow8I6Q6Wq13o3X4e4xHjBE8AquWuQ3DevoJr3XBq/tqA1TVwQZ ReK+z+jMWlQd+0MtIkyuoeVFl+S2LApEkLxAlBhk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 27802385B516; Fri, 13 Oct 2023 22:43:18 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27802385B516 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=lQ7c1XtWejsPHH4aWdp8RGK3Wvv0GqQ2xJcXb721Hu0glQ/i5l4HWgK/L7hmdD2lJ1r34nbwYBrgaOLoga0fpAOPAWcIjzsGYg9Wy9RGLLht8FG2Kff18CIGoUKw5JGbJrvg+/lZvwVVf9P5uwT5Kcm5z+avmq1vMZP1dXLViDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=72rISvwIVqIt7ZM3nxe5nJUSOIHMsd1e1LaJlDExQxI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rzugrf0moie7Xq4oI7oIMJvuvZtjx/VLzCfW6HHuP/q4HI35W+O8uLm/px5kC5yU8U/S9q+UU/Ele3NWMIlutZAUW6KLRyIweWX3gHqJFYfIXXR0U73yJFjfP5hVqRG9eNJaFyQv4Y3DhUFSBbXxsiGUGz31tfExzOf6EgqdYQY= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27802385B516 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMMQHV005607; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh24I001598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1Z016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 22/40] c++: Implement __is_reference built-in trait Date: Fri, 13 Oct 2023 15:37:36 -0700 Message-ID: <20231013223957.1634024-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FDWHMJ4G79SaznbLelILqiQSVMN6fJFb X-Proofpoint-GUID: FDWHMJ4G79SaznbLelILqiQSVMN6fJFb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=795 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1779682816452722884 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 113 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_reference.C | 34 +++++++ 7 files changed, 104 insertions(+), 55 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 98b1f004a68..5cdb59d174e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 11fd70b3964..e867d9c4c47 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 32199a1fe9a..5989b84727f 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false +"__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 799fe2b792f..f0b4f96d4a9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 89, duplicates = 0 */ +/* maximum key range = 94, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 20, 96, 40, 5, 40, - 40, 0, 25, 10, 96, 0, 96, 96, 5, 25, - 30, 0, 5, 96, 10, 15, 5, 0, 25, 96, - 96, 20, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96 + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, + 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, + 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, + 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, + 101, 101, 101, 101, 101, 101 }; unsigned int hval = len; @@ -116,58 +116,58 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 54, + TOTAL_KEYWORDS = 55, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 95 + MAX_HASH_VALUE = 100 }; static const struct cp_trait wordlist[] = { -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 77 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 78 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 63 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -175,7 +175,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, @@ -185,7 +185,7 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -207,15 +207,13 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, @@ -223,6 +221,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,8 +231,10 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 82 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false} }; static const signed char lookup[] = @@ -241,9 +243,10 @@ cp_trait_lookup::find (const char *str, size_t len) 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, 41, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, -1, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53 + -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, + 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + -1, -1, 54 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9cbb434d4c2..df720459458 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Fri Oct 13 22:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193108vqb; Fri, 13 Oct 2023 15:47:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExUU8lyaDq6rkQJNG6xtS5uhWdLnZUZeMErT7cBrMASiooKyeJb+hOWiUAOziBiDIpA6D0 X-Received: by 2002:ac8:5e4b:0:b0:418:1f6b:7ca3 with SMTP id i11-20020ac85e4b000000b004181f6b7ca3mr35891583qtx.23.1697237256059; Fri, 13 Oct 2023 15:47:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237256; cv=pass; d=google.com; s=arc-20160816; b=sdFIkYQk7NQ0kMskzUKDdTi+kQxcY9+mTBVGsNbp1hGkZNrbx10d0wazXSuu/WgGAR gb7bEz/6FuWykgaMLXqv6+PiAKF7Uy7yH3Eg3nN+syTRk/4I1KEhe3eI/3qwegvL32ML qSS9sEfDrVOY0389Wsy+jUiicYjlnSmgjt8/eekQYo4iFLoRzhtXljaSU3U+V+KaTzOf WmoyJoVM8xOpvzbBW1AdRSiyURbPUAggiOBf2o41yD2CnqNVmcneACfqx1sO/hqry+Eb fdueCgTGlMQRqP72BWmHrzxY+V1tP9YHwTo4xVCnNWW3C4qCaGiT/0LdkkCkId+IMvGV 9BVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=a3SDnv+ngUCB35eFko44fBFMw3GjBIvC/op0WNV0QaA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ZW6wu1dN2CvEGIhqodzdtQUXkyLqdziKbR+EV4Z8jFZdLkl7oL/7IaiEgNrVzb9amC tA4kZKPOdwEl2oV8UfHfVMJyBoClVP4XnGMsZzZtcmDJjguhdTvGat3tHk/1QwIKNJwD WVPTDaXETpXHXNeTzk1t0w6Z4uA77Q0QKDe0v1Y2zF2vYj8rX0Z/xSuZiMPWVT51oz/u W3DA1+o9K6uJah5QEopup7cAg6gvA6UeD6leak/FNRmN9AP27XZj9N9TTD3qzTvgRR5f 48PmMNEJjxpiQ+7lPhG6swW6j4UhJblQhzKcZsBoyxQtExG2FeIiAHJ/NdCbjKfS19lu /mHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="yivZ/dzO"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u19-20020a05622a011300b0041816d65a98si2011529qtw.421.2023.10.13.15.47.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:47: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="yivZ/dzO"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A0B0385C422 for ; Fri, 13 Oct 2023 22:47:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A0B0385C422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237250; 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=yivZ/dzOLd9rwPinpaT0wfLyJDYFruPj7+EivCGMer/u23wj0royps5jw3ZNTRGkE iITbvShmBwh7NhkkCh/MBdyx7jqxiXAxlKPOivNMahGeSTA1ggrmfsfe9oy8+b9Dhp O3I+e4p9w6CGgGBotcbNX2uxwS5IV2o0r0lvLJ7g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 6C6403856943; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C6403856943 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; cv=none; b=s6X6E0kf5AURbxIeuVeIWZH21ngp48R6DsVIONzS8k+s/7fswRDGXRaxmsIfCJp9Ezh1IqewKlIcQU2hqDA8kMvstOf5/EZqZBnTac2J0MkcsbY8D0q1kcy1CUs7kqKJWc9smYudAp88RTrazAzAadvadt4GSelsMTa2HPW719U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237000; c=relaxed/simple; bh=/ZpKzUC/+Cn+6c4i+PdtJvMDzWz2wSkg6dqToHkptIU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kglCAAYevoB69tAPBZ5cYV9nu9Q1GQOUijKGPOtnP306Hxa8myK7esEmV6dcrTTqZHru5DD+wyAXXUHhbKHkSo/OpmtX9Dz3B1/TESmBnkqZKGaCHleA5SiPX3Mdz/SxF0aC1cUKe8QUmmAmLZvKVNo6yEVT9Pc7SF2jZS+RENE= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C6403856943 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMd4Eu025980; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2UZ021601 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1a016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 23/40] libstdc++: Optimize is_reference trait performance Date: Fri, 13 Oct 2023 15:37:37 -0700 Message-ID: <20231013223957.1634024-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: kTdIoD7Agry36Il-9d3ghDZo_NkmffCc X-Proofpoint-GUID: kTdIoD7Agry36Il-9d3ghDZo_NkmffCc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=782 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997499735714658 X-GMAIL-MSGID: 1779682253139068141 This patch optimizes the performance of the is_reference trait by dispatching to the new __is_reference built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_reference): Use __is_reference built-in trait. (is_reference_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 792213ebfe8..36ad9814047 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,6 +682,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -696,6 +702,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template @@ -3264,12 +3271,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Fri Oct 13 22:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194006vqb; Fri, 13 Oct 2023 15:50:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuDgkpfN3N5bGDnX737HByuO8xtHwydqc0lm8/OBlQgKIEWhZR3agMTEw51y1rGklX8943 X-Received: by 2002:a25:6086:0:b0:d81:41b1:448c with SMTP id u128-20020a256086000000b00d8141b1448cmr25439081ybb.43.1697237415621; Fri, 13 Oct 2023 15:50:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237415; cv=pass; d=google.com; s=arc-20160816; b=oIqdThbKeCSUhhszzkfz8aVOMqHXPs+hcuwxXTePSA4gad8GTCRZvzS9IOe3wALV1v uVfiH9JYRqC07UyQPXNFRgcqS+EqoLrYGpc3FcQi01xJSUMnmE36SmvGYyeeEvdxNgp4 d5A+K5G+hSFZURKhkOaFRHQ1gNhVpundZukDjz8Zj+8KefdwMbO1mCDvpbL3Lb+d5ISP wxLdGiTNYwE8QJY5G6N4gFHI7iaFlvZ//uI02AkMxghXLvJmC+HMz935tYNJ2qHBqiPb 6+DMX8M7sLUCHRZKfrc+hbNVtxElYNTvKlJ6NQaIx1fAZWMgHCKCG4zP+sFjg1e/UhjF LkCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=oY7oZbhaUFAKx7uzKMOPK4vcrlUxmr2DvNiYyLWJc8Y=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=HwMrySe3R1vkK8xCUH/Ojj6cTTSTzZ/HjjlbUOLZl+bX9s9S4297CikTzSq2ufL2my MWPuAxMp7RV2iOxZgunTnfcTfS3kQ1T+fsBOyNeeSyViwW02U9dWZUQNQLn72z14WkdZ E3wW4RoP6GqswIpGKf7JuWm7udI8ykvmc0yI4+HzMwVyethEDL7+UwLCEbHbYOB0tG30 W2kVpTy3oCAmaRd519DmNvBbVh9b56XYPbbupsi6+DJSRN5XC8QP6XC8jmZtz1JxjuRS GQVN5+JmqRxtIfr0ESpqFyEJLfhhDVBMRDEMZ3iI1ScOaKGNbN/e+R2HKNpcfanPfSIW HA9Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=krx1PXry; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id eu18-20020ad44f52000000b0065af9ba7afcsi1905819qvb.92.2023.10.13.15.50.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:50: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=krx1PXry; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F343385E006 for ; Fri, 13 Oct 2023 22:49:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F343385E006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237395; 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=krx1PXryMGchgOB+I0ovoaEeC8G/CvY5RndYUFqFwJLnnsqgXUtwYxyP6lsF9IU7G J5iHRsfqgqlqNqddCs5vt69trJxsp9w+9a0LRRJBtzpL3lwGxJcMAc8h3k1qYhN9EK SN1Mu13gwlPtB4d5NulwFT6xGmqt+pyyUtNKv4/Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 5B5983856DEA; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5B5983856DEA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=ov8+r+2FfolT3Wf4X+CLTnF9pf+8wdW2o6E1oKYA0h4rEJo3T5JxdmZw5aUa4PivhdTtxhnpx1b9ZPdVOO4QC6tnTHsdQ0SLZIOn9xeSSipKY522xGcQ2rGN9A76Ee9WrFETmrLgx8Dw8TNfOCfYOFnlgyHvb000LTmPq31IeYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=8ltNAspFMVEShE4/X+456cDQXE0Fa0kNHV/uOBHUK94=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KhUrIY1s6KZ7dEDlg7AhK+xpWy0g/iJvMSFS1xRZPbYzzCF2TNMkNb5IUfgzQgZNdjNw7TWY5tjlp9eAAe4L+dnObfv28tXEYG/O1ry2eE5a90SrJKpc5X7OuKMtLuMg4TjfBObB9DougRjZwpnworv9i4ydocnVpV21LBJFGfs= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B5983856DEA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMZuc9017804; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqe7n8c47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2te003493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1b016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 24/40] c++: Implement __is_function built-in trait Date: Fri, 13 Oct 2023 15:37:38 -0700 Message-ID: <20231013223957.1634024-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: fQDJy8JkOWkwA_KVExD5tv1nYeqVWc_J X-Proofpoint-ORIG-GUID: fQDJy8JkOWkwA_KVExD5tv1nYeqVWc_J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=936 clxscore=1034 malwarescore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995319714743541 X-GMAIL-MSGID: 1779682420407492003 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 143 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_function.C | 58 +++++++++ 7 files changed, 143 insertions(+), 70 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5cdb59d174e..99a7e7247ce 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3750,6 +3750,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5989b84727f..771242a7f45 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -50,6 +50,7 @@ struct cp_trait { "__is_empty", CPTK_IS_EMPTY, 1, false "__is_enum", CPTK_IS_ENUM, 1, false "__is_final", CPTK_IS_FINAL, 1, false +"__is_function", CPTK_IS_FUNCTION, 1, false "__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false "__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false "__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index f0b4f96d4a9..b6db58e93c9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 94, duplicates = 0 */ +/* maximum key range = 109, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 20, 101, 40, 5, 40, - 40, 0, 60, 10, 101, 0, 101, 101, 5, 25, - 30, 0, 5, 101, 10, 15, 5, 0, 25, 101, - 101, 20, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101 + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, + 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, + 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, + 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116 }; unsigned int hval = len; @@ -116,113 +116,113 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 55, + TOTAL_KEYWORDS = 56, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 100 + MAX_HASH_VALUE = 115 }; static const struct cp_trait wordlist[] = { -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 78 "../../gcc/cp/cp-trait.gperf" + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 79 "../../gcc/cp/cp-trait.gperf" {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" +#line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, #line 49 "../../gcc/cp/cp-trait.gperf" @@ -231,10 +231,12 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false} + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = @@ -242,11 +244,12 @@ cp_trait_lookup::find (const char *str, size_t len) -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, 33, 34, 35, - -1, -1, 36, 37, 38, 39, -1, -1, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, -1, 47, -1, -1, -1, - 48, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - -1, -1, 54 + 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, + -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, + 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, + -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, + 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 55 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index df720459458..4b8e80f3e62 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Fri Oct 13 22:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192511vqb; Fri, 13 Oct 2023 15:45:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkWok0/5+MLFBXTCP/6yiIwAPYVWae6CPWL1gSXCOJGvUL4OnECTC1Pn5uz2Ik9fdZG+1Q X-Received: by 2002:a0c:aa5d:0:b0:66d:13c2:1c31 with SMTP id e29-20020a0caa5d000000b0066d13c21c31mr1985938qvb.24.1697237140312; Fri, 13 Oct 2023 15:45:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237140; cv=pass; d=google.com; s=arc-20160816; b=Xus+kadOvXAntnYCFw9ZaLCsfz9A9J6S5+wG1sqPvq6ZtqVvLxcohl5bXtPCel7W+U xWUG4zAyuAQn1cbvGbiv8pIDJ2H8EMd47oIq3C3vjIzYi+EGijbAl5x/mpl02atqYRmH AUgbcFNiWyki9dAZ8zWDz3jlU5OkhiwZ43w8SG3XQDQusEjqVHxmG1CRSGY39iWzqza5 VHURLGjTEmSuOAie8k6rdPqVPWtu3TdXSBbmRqfOYG/KAmlBcC5x7iaLf7xApWb/7UYR +r2YpRii2ECwLLi0309bsdSyUrjIe1d2j/6zLFqDgIa7tARUJocvU6G24HWhLl19+Yjs DJHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=iaWBS76ar32WQjo99XIMZUyy0dOBDYRpdSXRNfrU13A=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=FH4expQ6mozip7YKWSqUdPWFwSNR/aeHh5aqGl0xHCena/60/gj+MeZ68ztixxVBSW h/BGpbBn0JiWhtPdsC3TMU1C0J8ZXeYvjGsP12kk8mDbWcx7LILMFzz+I/UVFe97NlGb PIKfVTqa5+tNjlaYm/cHGsesMcaE0QyY99pQ/xdTcYtXqiFDjQF7TL1Sh7gtUqs26wnA sFKjISfs5ij1oPpoR94RIHTocoAT3A1guXq8Vjw1S90W/o3xZr5Xol6OiVgUjbvqGqck Mz3ddH6MV7If1BRX2TCF121VM3EnPb3jPMuIwuEpXXlhYlHg8cqxOkmOjrUM1g4erbwH 23EA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dy0OzrcQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id eb12-20020ad44e4c000000b0066d130cbb98si1919057qvb.19.2023.10.13.15.45.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:45: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=Dy0OzrcQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D7A33861861 for ; Fri, 13 Oct 2023 22:45:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D7A33861861 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237135; 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=Dy0OzrcQDpEwhnWXjOCqdfSql6eDrcB9Gqhpp4sD2j0Kqtj+BlzIkFyrQ9aHltgKs Gc5ZULfUw/b4l2YtSZSUrlzedd60oedTxB+Xq7NwBi90JaIQkiRhxC23zQRt1u75A3 wn0+wSfa7JL3miZOoV83dwFqz+la2d2C+Uqz45c0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 23D1E3857359; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 23D1E3857359 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=G+W4Z/71PUsd8HDoT/s2Vj/d8KV1/WD5jcj45061HpowSI3tmcEWV0yvLjOfRoWHRE6/Ff4vgStv6TOZIf+uuhydXDV7XYHomEgGuMsSaUrXr/Z8Bm82e/MWEM7HZFbpJ5Vzy20CDtIhgKQ5e8ViG46HHKHM7oFO+a73925Rv3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=c205PSleSo98VKF72O15l6crxQGKXbefxic2LHXRDwk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vIt4hy5+Wi0JpIucaA9ExPdAo0g1RKPQyaWsKq4RqHF8rlGLNRjJmVT5kfe2JEliMhV85K3i8X6X1S7KlmhBcJpf8BHpICovPltM9uZbTy6BwHecXrCrUhYn0XTCMiwGdUFP4bQNo6eY67u/BACXYMZfdr+kHU/xjIqx7fdL7XA= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23D1E3857359 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMYn2w019858; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tbx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2ek021602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1c016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 25/40] libstdc++: Optimize is_function trait performance Date: Fri, 13 Oct 2023 15:37:39 -0700 Message-ID: <20231013223957.1634024-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dcwnQJIGOAsrxb2UU4hFzN74C4Kmrx-C X-Proofpoint-GUID: dcwnQJIGOAsrxb2UU4hFzN74C4Kmrx-C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=583 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997392552534413 X-GMAIL-MSGID: 1779682131632581446 This patch optimizes the performance of the is_function trait by dispatching to the new __is_function built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..bd57488824b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3269,8 +3276,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template From patchwork Fri Oct 13 22:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152810 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193478vqb; Fri, 13 Oct 2023 15:48:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwn13Q6HZUgaDwEJyOiomCK9ksLAZYCuUDw24RSZoi2AraIaJwQlQf73DAt39kVrqjPiEn X-Received: by 2002:a05:622a:243:b0:415:2011:9890 with SMTP id c3-20020a05622a024300b0041520119890mr37130154qtx.40.1697237315088; Fri, 13 Oct 2023 15:48:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237315; cv=pass; d=google.com; s=arc-20160816; b=oVgSwQPWypFCf+v/tYa2JeVvnE3zog65c/VgsM9u51u6NuRSSHpGipjBDWm6YmlSGr 5cOkVgJjTIp2v0a7joKOADE37qGWVcG6bD9kiSMWm9HczQyCjm4QYUuV8g/A+93UQjp8 OaT63HYhPw6Z194SFs9Fh9j/bX5jeJZ+OZJAcoC+SBqhDpOwxUAPk53kFXTRB6FMpRDh nnH6USzdOvTLsfF6stq4rloiWBTNoL3VuWwPJj/7cZc0bXIFG2staDBCMskV/W+o/nrM p4SpJGY0sh4/fQRt/4T/0kMNV4/ZM4tErNB8OewYyNHyPHHoDGDo+KavjHQXHFi3dJA0 30jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=Q8cGYOOlgBr4ka3oidY/INwakk2lw0voEZaicAwcnN0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Atx6ZtQW0fumV654SK6o03//oDuI7+XSxuDKxdaT/p3+SOAvaeQy45TM9tGL3ccEMQ AMiqdqP2XFPwlK4x0Ij8VRQdmU6aG8pFsTtpjumClYPQ8uPeanERrpxRYiLkzaeZQS54 Leeq8kRw+zkW8i+Pt/DuRo7Z9vx81wUrlNeWRztLmZL2SB89qu3L77q9pp7cKT3Er/EK 7x4S92m6tJM4ndH4kbzRjXZELI1i1Zv7xKUxBjd+XVq5whnJ1n1mIL4/iNO5ejL05ArR 9QPfTRvSiGD1Ejjg7N74ZgIApY5QUV1AiSnUWl5jObtnqrVrMppJaO/7dXsKDLPUPoMt X6Jw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EinxbYUi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e22-20020ac85996000000b004195c79945asi2006879qte.560.2023.10.13.15.48.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EinxbYUi; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30B4C3857728 for ; Fri, 13 Oct 2023 22:48:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30B4C3857728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237306; 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=EinxbYUiEteOSlbPyE1zihYpXtDaTaCjkLZN6jPaOCX9o48OtXKlhz09aimfPty4v HAiptg94nvZXLGt3e57ciC9mO0FTUk2taabMV82MmYSLKc6/DKVTPkRrr1IbL1uTSq /OanahzR90MGr/O2CZNTphlrWOa08yy68zI5Y4Nk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 64A9B3856DFB; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 64A9B3856DFB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; cv=none; b=YMLB4WiWrk3CJCZJerFbiR//fM5MNPnrdTMsi/gageJUMnpO/X+1Nn6vpjhMwy6w0DaHCfckDdN1whba8KOnv3gR/0dP7acgR3+AR+c280zsx3aGOhMT4ArgLh9U2xUc+R1Bacw76OX7uyvoo5nXJMe2y2aare/ItbYtGLCE20U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237002; c=relaxed/simple; bh=zHRUm094zuZ3ZECOAp015pu8rl+10kg38IxbocgWKRo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Oh/aJCVm9OHsmrp0Afk6Fp3f6D0+PpcRD46R9EVp1HZW2vsdSF48MWkIm1t4xOIkGwPhOx7IGztG9e5eKjavz3ruUyuNCgu/o0dgUTtxZkTZJA0x/zAA7ko6e1C/lWjlwOPr+ZPMVqsOJ+kd/mlD4HOig1k3uI2lJ9iBgM44oK8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64A9B3856DFB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXZwh011654; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbp41w84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2BX012744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1d016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 26/40] libstdc++: Optimize is_object trait performance Date: Fri, 13 Oct 2023 15:37:40 -0700 Message-ID: <20231013223957.1634024-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Q3rCoOdy4TkVUC8P4GcCaiqXNMqE3NZG X-Proofpoint-GUID: Q3rCoOdy4TkVUC8P4GcCaiqXNMqE3NZG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=793 bulkscore=0 phishscore=0 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995944979792207 X-GMAIL-MSGID: 1779682315131684975 This patch optimizes the performance of the is_object trait by dispatching to the new __is_function and __is_reference built-in traits. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use __is_function and __is_reference built-in traits. (is_object_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index bd57488824b..674d398c075 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -725,11 +725,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ + && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_object + : public __bool_constant::value)> + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer; @@ -3305,8 +3314,17 @@ template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ + && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_object_v + = !(__is_function(_Tp) || __is_reference(_Tp) || is_void<_Tp>::value); +#else template inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template From patchwork Fri Oct 13 22:37:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194330vqb; Fri, 13 Oct 2023 15:51:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhkN7k2vl6IDQGrtxIQ4XZe3sHBQb76yRRXWuLBxQkdBmNiJyiRnxTWymbs2HdmBHQ8sdR X-Received: by 2002:a05:620a:4551:b0:776:f693:77bc with SMTP id u17-20020a05620a455100b00776f69377bcmr26852692qkp.72.1697237460324; Fri, 13 Oct 2023 15:51:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237460; cv=pass; d=google.com; s=arc-20160816; b=CTWX7VTVMOERo0+4LmjkrdMzMzkoGbdPxJUjvsXSjWuHnjxQqlGvYXN7J5fqZ3pC19 bH9nBZsSnsWwBEteLTAIKY0DN3KuTJZAHO7SLKnnTFRhQMtfl9QAe2yozMn21bh1LqHl R/rM6I4sRhtSdlkH8yXiHon6SHVBA5YiYdkX8NLWyKR979FpyQoZpYXa5zNUaAlIddgp SYYzDnBK0ophpllbWvNzS1jjD0YgzjhcAOaZnDZn9I7U9TZc51K3NuA/Hde3rwJH2AUy 8rMURGQsPwPi+asToDRsAPYjsERPyMYfF9Awjx81hc1sqWzXuKZvxFASvIj+6kw70ho+ A1Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=49ikNN5VAb/G4NpH7CAoShvEkZQc5oEVnya7sxItpIo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=BlGVp4Ky1ibiot8HNChmkUADgc3tRWUZUActlJQppb9AVyJPindQ0aXpicZPm9aDpS 4mFHklyiZX2aVnMlwakAqmY1aaBb+htX6DtdNOsYk5l9fRmazelTtakFk3sttkx4kMtY qXnqPhEaC5yxdSQ0VTwdKaFrewuL2vMIwv6nO0u0RCtdWiIFbd/e78VLIDRbHs/Tb+GW aFQ/ItY6Ur3z0wRu1jpl+TRNXDjboIu+wbfgRWO0dqQdqyGoVw1SgI/6fLOfWzg/Sr45 EYYleFekEcPUG0JJ01OtGUbn97Y6tZ/0RR3XLX8J3mRMf/a0ieWeg5ZXr/2wDEngHazd d0Ng== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rcGpqwRR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h9-20020a05620a400900b0076cdf0d3eefsi2035567qko.245.2023.10.13.15.51.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:51: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=rcGpqwRR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E54B03865493 for ; Fri, 13 Oct 2023 22:50:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E54B03865493 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237439; 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=rcGpqwRRdKEwDYAJ5GKSzkSkui6nHBA9+46QJZOOhBmXgVfDoX3NVrXEEoCjC7OQ1 CzVY2+95iybSY2YaAMZbjd5Q9tuyD7rLmSTBh9Pn/5L1drk3dinOUIdd+PYm+gW0Jk WbSfjuL+UX8rnJ0JoHM+epwnt042/l4Jo5FmcaE4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 0D1F73856962; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D1F73856962 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; cv=none; b=meFUNMYbOxSnL8oTp68s0dzZEN0vxgGy5s+0bvzDnIiW8vdgvWeFffyJZJGgvPnM71/kqkypA6IcDQH8+tGJ81dnj0u45PpKXMck6Nd77d1+OCmbhshY/MwQFVMw/ffX10obOzajbPFZgqiHjkvif219LmekEDib7+04XKUvdyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237007; c=relaxed/simple; bh=2r3iD77OE/JU9ChDDj7KX0mfbuBR5Uuh+aanU0JlCFs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=odf/QlC9wvx63f28sVX2SZ/iiMpxzJuW/CUhWlttglDg1OCVPAYQYw+e8mI2UlEROK0YL8JT6FSigjZhj5uYtXznquprlHbfLckJoHplEkGq/ULVtpMqhoLZCSwuqDsaxZIiRSt2L8wjiuzqKiQ2YeYzXV56FS65VpZU+OWxc/8= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D1F73856962 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMYVmn008921; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2AU008046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1e016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 27/40] c++: Implement __remove_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:41 -0700 Message-ID: <20231013223957.1634024-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: LDiHjk8iqCP1sSwUBod-xPVNe4xbCbEf X-Proofpoint-GUID: LDiHjk8iqCP1sSwUBod-xPVNe4xbCbEf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=587 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1779682467093860669 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 32 +++++++------- gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 6 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index fa79bc0c68c..2add97ae749 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -97,6 +97,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 771242a7f45..8fbd67788d5 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -77,6 +77,7 @@ struct cp_trait { "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false "__remove_cv", CPTK_REMOVE_CV, 1, true "__remove_cvref", CPTK_REMOVE_CVREF, 1, true +"__remove_pointer", CPTK_REMOVE_POINTER, 1, true "__remove_reference", CPTK_REMOVE_REFERENCE, 1, true "__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true "__underlying_type", CPTK_UNDERLYING_TYPE, 1, true diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index b6db58e93c9..ad2c2a2d250 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 56, + TOTAL_KEYWORDS = 57, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,7 +125,7 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, @@ -137,17 +137,19 @@ cp_trait_lookup::find (const char *str, size_t len) {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 69 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, @@ -235,21 +237,21 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, -1, 6, 7, 8, -1, -1, 9, 10, 11, 12, 13, 14, - 15, -1, 16, 17, 18, 19, -1, 20, -1, 21, 22, -1, 23, -1, - 24, 25, 26, 27, -1, 28, 29, 30, 31, -1, 32, -1, 33, 34, - -1, -1, 35, 36, 37, 38, -1, 39, 40, -1, -1, -1, 41, 42, - 43, -1, -1, -1, -1, 44, 45, -1, 46, 47, 48, -1, -1, -1, - -1, 49, 50, -1, 51, -1, 52, -1, -1, -1, -1, 53, -1, -1, - 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 55 + 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, + 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, + 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, + -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, + 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 56 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 4b8e80f3e62..168411f6700 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12488,6 +12488,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, type1 = TREE_TYPE (type1); return cv_unqualified (type1); + case CPTK_REMOVE_POINTER: + if (TYPE_PTR_P (type1)) + type1 = TREE_TYPE (type1); + return type1; + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4d3947572a4..bcab0599d1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -173,6 +173,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Fri Oct 13 22:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192059vqb; Fri, 13 Oct 2023 15:44:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSWon9B4p/XihI6RjlCojcatsyKBkz+vBe3iIQeYeNa2ofnwjqwdZRDCoPH+lA0wwECSA1 X-Received: by 2002:a05:620a:e0c:b0:76c:ea6c:59a3 with SMTP id y12-20020a05620a0e0c00b0076cea6c59a3mr24171730qkm.46.1697237050647; Fri, 13 Oct 2023 15:44:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237050; cv=pass; d=google.com; s=arc-20160816; b=SCGf7I7CZDuEQLxpFIRYNXWyW9wRYkl1L/CVIAG0j96xjo//OKfZKLDpaCO1dtJs2j 3H5ztmko2GqeumKpFhWo3RvR3m+1H60FoChBjyCQy/ilSzjLxEF6t4iIo7bn570ZdroP he80zd8gYSPSCePLVz2m614/mGRGeay35BLcHw+wTatkYYb7xWItvxDs9b9fDLNuojAf p7jhHvWjf/IFaYb849uOYin3spLfykwQuoBsu6WfeLUM9F10/pCbTOM3CFagk5ucrzoA gw+B8hrga+GYdlW+69KadULW5ouXAAP9UdUUY48wtLdZA4Lqzcf1ew+NVB3lPwwSRBa3 L/5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=f4PdqFin8j8p+uNqRVj8xt6YE09pyx26yFWZKrFmZZU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qpn00wvoL/IXdVpBIfn7D1Ns4C3UzhHmDLmwppSnAtruEhMvKx2BiP8fabvxn0KrDS nVxNVGDFEZa59b4Vjd4V5/035fxvTIUnOv3BiB1VKY0ltPXJLuio90dWAyxDzoppOiWJ a/ROFBP5n31aBxg3SMtDTvQtWH7cjUn0kYKX9u6ER5SacDmGBM2j/L6hMzb2zR043Us1 9xFW8y+nCXvbda3pJCDoRhyByhiz4milyAcdph5sD+Ke04JxhmrHuc7/4VefuKhxeL/E NNNnbxvM7MT5OA5FkWeAPvxyhU0K1VdNx6RF9jdnxSoDIV80npD9z1Yo4XuSGpHi8Gth 4g5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oZbJd4GM; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i6-20020a05620a0a0600b00773c039a37fsi1854948qka.163.2023.10.13.15.44.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:44: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=oZbJd4GM; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3835F38560AA for ; Fri, 13 Oct 2023 22:44:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3835F38560AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237050; 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=oZbJd4GM2phwKIss1KZz8AV80yfYfoY3J9RAB4naetnzgHOeThoj4nVECCT0GgsSI IVYe8Gw6FbKFs9a6mFDBjharRNQ6zNqyu1ycWj7Lt3n3QRl5oTmhwmrXkxtEC/6a5c L+5ui5T87YbzGofBFEoGLDYr4sdQRnfkAXzAptWo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 1D7233857725; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D7233857725 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236997; cv=none; b=fyT+bICMmIb1SFFKkaIYKdKiwAlKTyNZOTtQF4Jpqm45xL1C1D/fE0uEcdF7lhJrD04kmxFoeGYzLbGV81L1hk3y2GWJBwGT3e79M2NZG78dh0oCs8ltEPsc8T0wHVytGhKaqkxAEWM2b/1bCLp/3cisI9yf9N2p1yZL0pCBmNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236997; c=relaxed/simple; bh=vHI02GzVWW7SZ1SaoXTatpzigzV+rRMb+vomEf99kE4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=v2hYuJTjJQYaOuVztsv0AeRCgZy7tnT1mL99lPRbCz368zMoNBv9YL7au8G/pY+nwRfb9cM/eSkaKWv8akeKAROQksd9zfLGiEHPnROJWk5/9lxz6wuyW09fFRdefR5yLgh1odwS7ORggmXjTm6S4XZZoByvbzaKf3NFAFiBroU= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D7233857725 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMOew4028987; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Pj001569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1f016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 28/40] libstdc++: Optimize remove_pointer trait performance Date: Fri, 13 Oct 2023 15:37:42 -0700 Message-ID: <20231013223957.1634024-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lyBJYGM3_IKAI4DnVsoE-3_B_NsF2xwu X-Proofpoint-GUID: lyBJYGM3_IKAI4DnVsoE-3_B_NsF2xwu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=544 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997286578618893 X-GMAIL-MSGID: 1779682037526791613 This patch optimizes the performance of the remove_pointer trait by dispatching to the new remove_pointer built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (remove_pointer): Use __remove_pointer built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 674d398c075..9c56d15c0b7 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2105,6 +2105,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Pointer modifications. + /// remove_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__remove_pointer) + template + struct remove_pointer + { using type = __remove_pointer(_Tp); }; +#else template struct __remove_pointer_helper { using type = _Tp; }; @@ -2113,11 +2119,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __remove_pointer_helper<_Tp, _Up*> { using type = _Up; }; - /// remove_pointer template struct remove_pointer : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>> { }; +#endif template struct __add_pointer_helper From patchwork Fri Oct 13 22:37:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2196281vqb; Fri, 13 Oct 2023 15:57:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKwltgJqI5ECy9zJKJal7bkRP59IjtM89Klxc1/1iLmynVa6S9z0x34Bx8oFUwO7vaL2/r X-Received: by 2002:a25:403:0:b0:d9a:5908:a29 with SMTP id 3-20020a250403000000b00d9a59080a29mr11035054ybe.64.1697237826219; Fri, 13 Oct 2023 15:57:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237826; cv=pass; d=google.com; s=arc-20160816; b=JL02EtvC+3GLUw0aL9+2xJvv42yBKVsJkEiiLG2taIDAB9Yi4J0ChdFajMMruQcTMy sfuuhKLD7XVuIaxBPnN92paAfD5mWs/zplRMcrzRwKuLMI5iLH2EXRAu482+S5gditof sMR5QGwkND7xQW8m3XHwEiegk/um7jARkecaHTyaQo6I3DPkpKJwJZs+GdUQAeyoIuQ5 y8spCdoRPrb9Drj+xI1/0kfX8YJ/Wk+fUEJoNBoOjxoOOushkdviMD9gpA3T+MKHxJxb UO1tEigu/6fkTBNsjAsiDvmkCon0d0K7B2Av0maSYmbr4vrPJaJ+toex0PtG04B8fuuZ sZ/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=EVJ9kreNFo7nGznrJ7E7uGFZi9YprPq8mLOXjF0MpZ8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=dF6b8RKOd2VPIIrIASe6gU2J7H96JfbmGNuhNI0935KaIqBIKRTZGET/X3b9uZNt4c vKXu2cGPhX9nJXfwnVgEE3A25lKYzSH+OzcU6YmOIFlhJCrRMS/FZ2GthQ+WwBUZ6p4N Bffs+aeSTjPDxWc9ZeEJXs42Lm31oUwhO/PDPcQFk+fpGMPYMoAQ7VgDwm5nHrsH/Bcp tCXCznkqKS63KTwdZczlRi+MCyAj4qgDmu2PYOPt6mjmxsvC5mGsM2vvABEDN6V3kgyP 8LtrCKAn1GVEGNlJrpXLC3s4HGCflA3htZu9dMUY/O/Tg7uUYfhg0KGdtiJqjrvBSZKh h9Lg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LRoOTkqP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lb30-20020a056214319e00b0066ae8d61642si1945418qvb.435.2023.10.13.15.57.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:57:06 -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=LRoOTkqP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8B6E38582A1 for ; Fri, 13 Oct 2023 22:57:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8B6E38582A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237825; bh=EVJ9kreNFo7nGznrJ7E7uGFZi9YprPq8mLOXjF0MpZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LRoOTkqP0KTFDD+IPjg/hTZ/w5x3eVB6HZvBzR5eCkLZGxvEK4iZFrx8qnsmXyNsn Wv8XO1bkoBRLrxlPTPOOwvIKBMh0TxeAtKoVfGNduzDPoDqwYPO5ZBAjo27QDS+6Zr eo3rwmAwRQoxrE7SP8SE8DngJIXqwlwSOs8I80X0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 02697385624F; Fri, 13 Oct 2023 22:43:22 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02697385624F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237018; cv=none; b=cYjbvi1GSNT631ly+vi5bLFZbO2eM6vL4ceQgWMLh4hHcPdXTQ3fOiOMWrNIxKwDMiRrXSfH7iuBirQ7MbMJxnGcx8XZiTtno4vCmfvJDx6tJT5kn3grr9yRW4mfY0uXj7UzTS5ENnQXKJ96+l5XNtSqQUIC2Du6G7FAKOCDIY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237018; c=relaxed/simple; bh=JtzlHXI4pYeWX7a/62xfVB5JJROmVV/h5dLE82v9Y8Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mUqBLps14w1O7hW8pOylz/LElro3omcoBkr9Tyb1pS0cgYloSooU62eI1lD64yYv3H7jEKjwAqTlTqmSwex3aMh5CqDL0dkEEJ1g73Co+1wsBuAzCdz4wzyinBNnr+iGVmRDYUguvKDJf8HHytK6pQ98YG44MDQgfNla2T31D84= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02697385624F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMO6dC012574; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8tu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2cT001614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1g016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 29/40] c++: Implement __is_pointer built-in trait Date: Fri, 13 Oct 2023 15:37:43 -0700 Message-ID: <20231013223957.1634024-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: pe7iDUPfHWFD4PlsBmqlXXl_pZpvWXi3 X-Proofpoint-ORIG-GUID: pe7iDUPfHWFD4PlsBmqlXXl_pZpvWXi3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=786 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677497968726301 X-GMAIL-MSGID: 1779682850956816722 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 155 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++ 7 files changed, 141 insertions(+), 77 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 99a7e7247ce..c9d627fa782 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3787,6 +3787,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 2add97ae749..c60724e869e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 8fbd67788d5..5d40e04f91c 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -61,6 +61,7 @@ struct cp_trait { "__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false "__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false "__is_pod", CPTK_IS_POD, 1, false +"__is_pointer", CPTK_IS_POINTER, 1, false "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ad2c2a2d250..ab783b161c7 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 109, duplicates = 0 */ +/* maximum key range = 92, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 20, 116, 40, 5, 40, - 50, 0, 55, 10, 116, 0, 116, 116, 5, 25, - 30, 0, 5, 116, 10, 15, 5, 0, 25, 116, - 116, 20, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116 + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, + 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, + 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, + 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99 }; unsigned int hval = len; @@ -116,78 +116,78 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 57, + TOTAL_KEYWORDS = 58, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 115 + MAX_HASH_VALUE = 98 }; static const struct cp_trait wordlist[] = { -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 73 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" +#line 68 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, @@ -205,23 +205,27 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_array", CPTK_IS_ARRAY, 1, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 41 "../../gcc/cp/cp-trait.gperf" {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 43 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, @@ -236,22 +240,19 @@ cp_trait_lookup::find (const char *str, size_t len) #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, 5, 6, 7, 8, 9, -1, -1, 10, 11, 12, 13, 14, 15, - 16, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, -1, 24, -1, + 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, -1, -1, -1, 42, 43, - 44, -1, -1, -1, -1, 45, 46, -1, 47, 48, 49, -1, -1, -1, - -1, 50, 51, -1, 52, -1, 53, -1, -1, -1, -1, 54, -1, -1, - 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 56 + -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, + 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, + -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, + 57 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 168411f6700..83ed674b9d4 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12412,6 +12415,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index bcab0599d1a..efce04fd09d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); From patchwork Fri Oct 13 22:37:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194422vqb; Fri, 13 Oct 2023 15:51:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtNEtht7oIB/ODzfX+lLJYQ1lIgHT3GsqR7NvhOJXTYbHNNBB0l/8LDmFoG2VgspTIf8bP X-Received: by 2002:a05:6214:d0f:b0:66d:1174:3b46 with SMTP id 15-20020a0562140d0f00b0066d11743b46mr8664510qvh.50.1697237477500; Fri, 13 Oct 2023 15:51:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237477; cv=pass; d=google.com; s=arc-20160816; b=kB57L6fuedg5XiAYg2Z4I1lsvB+Za8d8XYNrZm419UdKhUkuifxZpFXk+Ekl+r0T4N iaFDQ2OKy+A0Peuoyp4OlRWqGNsEmLAtkZI5k6oiz05fLZvlg1JC7dfa604sux22uPH7 cIZ5htE9uxfjUtROkJ8mXUcwXsrMrtxR1moKTvg3nn7wc9unTzpWJNSVNvXOo4C+rC6k VFnjdFVUJqssVHpQvHlr5qQoSu2tK0Xi8BfZUi4KUjuCBeyMt8wovwCOLBqaMNI4CfDU lWDCmQ33FWzZXUlWLwd5eHBM9DdlMrYHS2iD9pAQaqZCsRFzJ8TFO5SLb9ZuSZxj5V1D qDCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=drDSkwF2b66LppQZo7mvO/N7JkJbD5f+nFqDwGJeobc=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=KnXQkz1uJy+IyXO3LXYWRqFLp7Q0ptl6DRQAtH/oqiSXUWTQozT7yuCxpsbWfbaqj3 QpbmXqmVMPSScrsGtMpdq4eNK5wrdJEfOAibRVHiLPOaEKXw9NdeE8qPdzPt6hyANQzg CjK+KHGvwQPnOtRhBQa44z7CpYhUdBmZNZFYbR55BR5Iu83dN5Dy8B1VBd8ooR6XBXzz iBWxC0B4ceIIg761jCCnHSwCLxjP9aXpqB0vF3Sk55JcAGeZp4unQl04WZdiOZpYKgdC V3wRPoqL5HHowD8Cgg9YIjkTRgGWCpfzI9I3fR5+rUiqJH/jnVSGjrwXM0j4uihdXHgG KR2w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lGLCazzf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f8-20020a0cf7c8000000b00658a46f799dsi1928846qvo.293.2023.10.13.15.51.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:51: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=lGLCazzf; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 893AB3856092 for ; Fri, 13 Oct 2023 22:50:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 893AB3856092 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237458; bh=drDSkwF2b66LppQZo7mvO/N7JkJbD5f+nFqDwGJeobc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lGLCazzfR61gAdZFv+hSq7DGUWnGLtWbxeDsDE7sKJC4BsbwX/ZyEgwNYWv9pnNZU ZpHtyd+LTYaj0i7RWTpjWbR+a8X59JzZ4J/Qjb5JOoxzfXzTiL8UHqxz+usvun60Xa Dd57ctJJO3UxFcGgbuc2MP0xJ9tXDj1T9PxwXjqs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 92DC83856956; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92DC83856956 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; cv=none; b=YscOqHoCBZpuw/8Ii1b6wyXfgGWxA9rGFWYOort+leelO7lI4zlfU12Ef3fuaZTPtm8wND5LhM5DkZwkewCr6aySiwevN91NPHSQ9SwQHzX/hMEKsvE4ygInZAqqofTI4tdXoAyaSdSj4cpzRqG8GYgxaqiYqHZgxN5yBi125B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237004; c=relaxed/simple; bh=BfhYt/j2VRJjuMIYFbFyeiniSUdXiuS4K54TRYwyHXs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Wxoe7Evu7Tfl/+BEsmyt/n6cHURItTbsfNti0wuGTYH7zQNLZDWSurSrC20+CBXsXYe/QZdeAe2H07IhIc7at53F2si21e5gXGPCTKW1k6eM7FQMk/D4HbXCIcJAm1vDcHfPTePO/xL1aoQ64rI/NHTBgjZ8U1PPbM1klwKmeiI= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92DC83856956 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMdxA0011122; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tpuhpfg9v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2fW003502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1h016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v19 30/40] libstdc++: Optimize is_pointer trait performance Date: Fri, 13 Oct 2023 15:37:44 -0700 Message-ID: <20231013223957.1634024-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wsWAwSHK3l4JbU-GDRllQAT0S8V_YAXL X-Proofpoint-ORIG-GUID: wsWAwSHK3l4JbU-GDRllQAT0S8V_YAXL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 adultscore=0 malwarescore=0 spamscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=486 clxscore=1034 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997371839653001 X-GMAIL-MSGID: 1779682485376938368 This patch optimizes the performance of the is_pointer trait by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..cd5ce45951f 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_pointer : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_pointer { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9c56d15c0b7..3acd843f2f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3254,8 +3268,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template From patchwork Fri Oct 13 22:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2193297vqb; Fri, 13 Oct 2023 15:48:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGi32A94TjrBDex/Ys1jp+pXjCvb6Uq5R7JsyNcmGQg3WgEnLJ7fOJwL6AOLW5UgN3qk9dt X-Received: by 2002:a05:620a:394a:b0:774:17fe:5820 with SMTP id qs10-20020a05620a394a00b0077417fe5820mr2252766qkn.21.1697237283223; Fri, 13 Oct 2023 15:48:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237283; cv=pass; d=google.com; s=arc-20160816; b=UoeLssN/AK3nV0wBRoD9Bm7/d02+RFH7CGigXGrtsGO7Te3W8BGyWfmfoK03SxL0zV RJLr5kzeDms7/ZOxb7KxDNfLLQbq5hNN/KSorkzWKm+e2xCxJMZXkuJz/q7aRX3tGNlV NSAy1WwYrlD7w+D6U5fh66zAy6Gn3KS3gp34DXfAni9Ve2RbwTh8wrdIwYOy+rGzZSOL K2Xf0Rob7mBpQyX4ul+dQA8QBl+quRTmAZkODly+XUBXKI+cu8XWCqjl4kk7l0xcWBJx 2IGwI3cBHJI0w+zZHjv5BG/un2SwLjsj0u2y3aCp9+F9JtstBJDQXusHVcS2NI4RkBxf O9lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=zsCGf51BpLy+ZfS3NOkl9r5HeKT3mprpbJUZjo/kKH8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=KDSiiuKWRyEl/VJMaMPPvPjAWvc4KfckOOvJkyxNOdYgHKwxk93NLi+R3Qy+vmnGo2 bEDM+9rkj3lPAfOfNEL1XjQullBzzv8KlCOmFQjeb6YJe7LE2v1IAAF6qIzO3MkUNuV0 LltSLK/GFIYV/PfceM1qyR9PQpF2o+xxiOTs+VCBMNYluDAOhPLZDpJwYaKgIFLezCuy 4zpJEc4jwfOxVZw4/ZeXJJ30ZNGi2TkSjt7/O+1msfPOawlu1LC6dG2N6FN9uZmM3XdL Jz8Zh7u88VrVulILvmiKhkZFOrkpy5hIgWphPKb6TnWlpL1ElTgJDg4uhcD4JR5LuqWe SDOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=P8MvrDkw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j3-20020a05620a410300b00773d05a13f6si1996710qko.538.2023.10.13.15.48.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=P8MvrDkw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FDD938555AB for ; Fri, 13 Oct 2023 22:47:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FDD938555AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237277; bh=zsCGf51BpLy+ZfS3NOkl9r5HeKT3mprpbJUZjo/kKH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P8MvrDkwFleIm6hJIpjy2xCcE1H1S8kUbnhSM7emjnuUTN+OlH58RMLxWKuijibEW E46rvNK8lbG/ejjRsjS6qHFP2xKKqtri0m+MrRpDjqR+TccRc4vhHj0Cx9ldWUych0 RGgxIF6gkr3QZwqynEXnNaDwEho6zwTeAaZ4xFMY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 0CD02385771C; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0CD02385771C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=G3dBORcYKD92rcsqHC9l8YgwgcGN/8oaBeFeA8ObqT+WWvkudmPHVQ3H04jevdAX4arE/dugv4owdANdtxKlW+1L2WO7vb9EuFmRPamdkKpNYMguKmjQV3e9EH/gytqX5Ojl9hIRse5FnSfUQvA7IltZxqPOxqkoa84oeCYA3So= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=8YIFuUboBC8SvXVm1jt6NYeF2dY9CF8Y3S+k1xc+who=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=be/H2D7Jfnc3jKXR1mCBSe9fK94nKwcpnyLWja0w+8YfwgCxrJtJJ+NpyK5UfKEB9ibzOgssXpnj5uWI9v1f2hY9HPKkkNS3YuX4l6tG4Pq/PJ3SMVFZZXyoaKSUTovAV6985ZC1zdzUyeAhWtU5r/UMnE+G6Or7t+3anJOjov0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CD02385771C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMdvag028132; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2JY021613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1i016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 31/40] c++: Implement __is_arithmetic built-in trait Date: Fri, 13 Oct 2023 15:37:45 -0700 Message-ID: <20231013223957.1634024-32-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0QOZFQ7SBfeB4tqrVfQ-GIN_ldPCRr7t X-Proofpoint-GUID: 0QOZFQ7SBfeB4tqrVfQ-GIN_ldPCRr7t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=972 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677582756408093 X-GMAIL-MSGID: 1779682281464831559 This patch implements built-in trait for std::is_arithmetic. gcc/cp/ChangeLog: * cp-trait.def: Define __is_arithmetic. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. * g++.dg/ext/is_arithmetic.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 184 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_arithmetic.C | 33 ++++ 7 files changed, 138 insertions(+), 91 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c9d627fa782..3a7f968eae8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARITHMETIC: + inform (loc, " %qT is not an arithmetic type", t1); + break; case CPTK_IS_ARRAY: inform (loc, " %qT is not an array", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index c60724e869e..b2be7b7bbd7 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 5d40e04f91c..9050c36f105 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -39,6 +39,7 @@ struct cp_trait { "__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false "__is_abstract", CPTK_IS_ABSTRACT, 1, false "__is_aggregate", CPTK_IS_AGGREGATE, 1, false +"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false "__is_array", CPTK_IS_ARRAY, 1, false "__is_assignable", CPTK_IS_ASSIGNABLE, 2, false "__is_base_of", CPTK_IS_BASE_OF, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index ab783b161c7..31fd5075f2d 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 92, duplicates = 0 */ +/* maximum key range = 97, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 20, 99, 40, 45, 40, - 5, 0, 55, 10, 99, 0, 99, 99, 10, 25, - 30, 0, 10, 99, 10, 15, 5, 0, 20, 99, - 99, 10, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99 + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, + 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, + 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, + 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104 }; unsigned int hval = len; @@ -116,130 +116,132 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 58, + TOTAL_KEYWORDS = 59, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 98 + MAX_HASH_VALUE = 103 }; static const struct cp_trait wordlist[] = { -#line 86 "../../gcc/cp/cp-trait.gperf" +#line 87 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" +#line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 82 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 70 "../../gcc/cp/cp-trait.gperf" +#line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 82 "../../gcc/cp/cp-trait.gperf" +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 50 "../../gcc/cp/cp-trait.gperf" +#line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" +#line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" +#line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" +#line 69 "../../gcc/cp/cp-trait.gperf" {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" +#line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" +#line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" +#line 63 "../../gcc/cp/cp-trait.gperf" {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 34 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" +#line 58 "../../gcc/cp/cp-trait.gperf" + {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 57 "../../gcc/cp/cp-trait.gperf" + {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 42 "../../gcc/cp/cp-trait.gperf" + {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" +#line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 42 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" +#line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" +#line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 58 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, #line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 57 "../../gcc/cp/cp-trait.gperf" - {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" +#line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 49 "../../gcc/cp/cp-trait.gperf" +#line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" +#line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" +#line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, #line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" {"__is_function", CPTK_IS_FUNCTION, 1, false} }; @@ -247,12 +249,12 @@ cp_trait_lookup::find (const char *str, size_t len) { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, -1, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - -1, -1, 36, 37, 38, 39, -1, 40, 41, 42, -1, -1, 43, 44, - 45, -1, 46, -1, -1, 47, 48, -1, 49, 50, 51, -1, -1, -1, - -1, 52, 53, -1, 54, -1, 55, -1, -1, -1, -1, 56, -1, -1, - 57 + 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, + 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, + 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, + -1, -1, 57, -1, -1, 58 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 83ed674b9d4..deab0134509 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARITHMETIC: + return ARITHMETIC_TYPE_P (type1); + case CPTK_IS_ARRAY: return type_code1 == ARRAY_TYPE; @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARITHMETIC: case CPTK_IS_ARRAY: case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index efce04fd09d..4bc85f4babb 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_arithmetic) +# error "__has_builtin (__is_arithmetic) failed" +#endif #if !__has_builtin (__is_array) # error "__has_builtin (__is_array) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C new file mode 100644 index 00000000000..fd35831f646 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C @@ -0,0 +1,33 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_arithmetic, void, false); + +SA_TEST_CATEGORY(__is_arithmetic, char, true); +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); +SA_TEST_CATEGORY(__is_arithmetic, short, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); +SA_TEST_CATEGORY(__is_arithmetic, int, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); +SA_TEST_CATEGORY(__is_arithmetic, long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); +SA_TEST_CATEGORY(__is_arithmetic, long long, true); +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); +SA_TEST_CATEGORY(__is_arithmetic, float, true); +SA_TEST_CATEGORY(__is_arithmetic, double, true); +SA_TEST_CATEGORY(__is_arithmetic, long double, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); From patchwork Fri Oct 13 22:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195059vqb; Fri, 13 Oct 2023 15:53:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE6+fOssPZ4CT2FxPl6LrwpXOP6AwlXKjw8BJ6dZd2yF6SzvE3ilmNHP1UVzbugWTF/nyG X-Received: by 2002:a0c:f489:0:b0:668:e6f7:3d42 with SMTP id i9-20020a0cf489000000b00668e6f73d42mr2030879qvm.9.1697237593847; Fri, 13 Oct 2023 15:53:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237593; cv=pass; d=google.com; s=arc-20160816; b=N52TXRPEe6lOAEjj2K+MtE19zTb8m8PtWcm/pQumiqJLxKGa1SjVXrG+e1XTYS4P6l MkBItQmXNMfVJj5KXWIOCVj0gx61j3qbZ8Rb4kqJYNc07UrbqZ1mghUvuJtI0DYkFqOL ouo2Cw5R54wDmfaTr7Rb3idwKv79xHd+bzlaICfWV0mdJtzL6ySLIN6aQ4SS1j48l6SN s58yOC44CS6H6XyOashYUonyr3T+h2/py0FlqE3STVftzjYHZaZh+bOwAwinPIDOrOpD vdFgNDlH8/czlKWpu5oTe04TultPWo15OUlY8OnZ2OQPsG8SDPLH3Avoe6dFgxzYPOet pJ0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=1fhb3UCeN02Vpkdn4EKFUyJ55Q3UBgEbl435AnJkjqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PCUssHwnBCBgEcSe89UQ8Mk6vA1130GMz/O4Qndd2obxDa817zJ6zigC0PDXvb/qy4 hWZx+gI7D4bplLZNYJq3Sz4OKVY+xesLzPqc/KcBl6qbW0H23sJegZyh/zOvJC7hiHxP vjtfqi9kSpx7R/i2HNYf7ogVOEXo96Hw3vwvGs9PiF7g2haV8lq646rdgSmv+LWI1y7C eSx49urqkqVcxn7zXhzXxfIyV9S8cLiqYo7PTqeZVCFzCoYDIMEIvkR99hX09hGmjYRg 6/s/hSNiWwukrlrX0QTdFuf4EqutogZmy7b+mMEJLuSPe3Jfh3vXMzjX3ReBFCWNtGMC Ji/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hl6bOwLW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y18-20020ad45312000000b0065af751dbb1si1982520qvr.448.2023.10.13.15.53.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:53:13 -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=hl6bOwLW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C599385E823 for ; Fri, 13 Oct 2023 22:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C599385E823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237589; 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=hl6bOwLW1ulW3umnqWUGLmY3RICWQLann+9bC3NobZP9oardk9pwy5XlEcaawN7Z0 kAcAfl1xLnQrEdbYc5r91G+MUBKDbC0Berhcgc0s/c5n8P0HeWd9QDyqaERzOMsbdv ftQy0mVqeX/eJAiVWhxzAPQaV2+0yvh3BXaDIe0k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 5D9B33856969; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D9B33856969 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; cv=none; b=BCA81mMIIlYZGofu1yLg4fyKOjlI3zkm9k3KBGQ4sRUCiXssIkkCFqbti4exCX1nS9QnTY21K6PE2vJzJ2e8ao9lc88L7HMTWMogoDdTDqEpVCCZeRI52DRGRv+AXyXTFbhz3Aggi6W551lHinH9K5Z7V7xwrYGkGcP/bI8GGD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; c=relaxed/simple; bh=axxlZKKPGB8wuYsjw8SAimjjV9ZTlh7UjEpqEksZVtQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DpHkzDXP+UkBSgyzebq7vt2A/d7cAlZlwUqLn4mNlkhOoCSE1+EjYioBO3vWlQlqhbKAdQeaPdfNIl/BmwYi++pGW/HcUrmYIN83zoSYkcOAgF0gMDJ2XcU03yEGamTYCIoLnxpQUs7dWevw4lx5Rjn+kLDhMnlzzz9Qg1BVOPw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D9B33856969 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXSNZ029268; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqcru15f3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2xb008053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1j016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 32/40] libstdc++: Optimize is_arithmetic trait performance Date: Fri, 13 Oct 2023 15:37:46 -0700 Message-ID: <20231013223957.1634024-33-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: agyfHrdoMJYfNDSVe1ae_pHXIPe6STMe X-Proofpoint-GUID: agyfHrdoMJYfNDSVe1ae_pHXIPe6STMe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 bulkscore=0 clxscore=1034 mlxlogscore=666 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996488688417878 X-GMAIL-MSGID: 1779682607179997464 This patch optimizes the performance of the is_arithmetic trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_arithmetic): Use __is_arithmetic built-in trait. (is_arithmetic_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 3acd843f2f2..cc466e0f606 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -726,10 +726,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_arithmetic +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template + struct is_arithmetic + : public __bool_constant<__is_arithmetic(_Tp)> + { }; +#else template struct is_arithmetic : public __or_, is_floating_point<_Tp>>::type { }; +#endif /// is_fundamental template @@ -3344,8 +3351,14 @@ template inline constexpr bool is_reference_v<_Tp&&> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) +template + inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +#else template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; +#endif + template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; From patchwork Fri Oct 13 22:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194767vqb; Fri, 13 Oct 2023 15:52:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJzHDgMEweznNv86sCTO91FDp1iXTtwcfp34ZUsTJ7wrnzk/XZLfZW9hxn4AiVyaHLt//a X-Received: by 2002:a81:ac06:0:b0:5a7:ad67:2b67 with SMTP id k6-20020a81ac06000000b005a7ad672b67mr12315627ywh.5.1697237535981; Fri, 13 Oct 2023 15:52:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237535; cv=pass; d=google.com; s=arc-20160816; b=AYTZLouSoLFWzSGLRRK8hWjyhqtZT5WXehawMHv6jM1OH3k9T5Fq+zcJEUDlFl70Ey GM+byHQzj9T1sltdTY7bKOXyGOSSjTN0yYMRM8IAE8XoZbZqwWcDkvlF7rBp0a6Ev3+j /iFoAtvfojsTEPS4uKI67roxSZdtCqnihUfR2RolNWM5t/70vVejuR6CsSfv95XGWh6o H4lpg3KCir8PVAbqsKaZoBXL6nnYWISM/BoroEWy8p7cJaDncBW7qYU4RLv8/lGZLDQc aWEolJVBOPDukE50wXJBYwT0GV1HQVEBjGG2n54h7BUaI/oXSmXxz3N0EITXgmCESH8X gICw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=noKDFtKJFjfo7apPynoK1CS9k2hGzaYhkiB5OX56sE8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ZbbOyd0Maw1Hx1r36IIoubAibXYriigENxWFyuDObvSahfUV/h8HEX2IpMYcbp4tTs cZ8hoA+GxEzOU4wvJxziaMTmKG9XsGf5bhSme5Y7fwFbAmWoZlBRJU4Z+V8a62Wlf7hi b0/+yAYr14SjX/Qlhqr8FfR2KGaKL6etLscFpg3EL1nWceNYu3zroyNVcx6ate/Ith3p vXaqMapyBkCdTki176Y4VYExslY9KqDfhZ+SsNs06zLJMces/IRdkmuhKxvxTLW4620N WQkCT01V4y5Kgm8c/fKgGenDoLo0d7WFoV2TDkkKNEOLm3eNlercxS1+GQKSppO0Q0u8 5dnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qQsVbE87; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w11-20020a05620a444b00b00775bf2a8df6si2042723qkp.195.2023.10.13.15.52.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:52: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=qQsVbE87; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D380138555A0 for ; Fri, 13 Oct 2023 22:52:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D380138555A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237522; 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=qQsVbE87EC5tmiRAplONcHJtjmTi1FDXldfTi1QEbryAbqig5aA5BL1SMtoDf77WA 8qxQnjGfE1PO5bUBqfyMw1J1FhFeg/BU/a0M+jdMErrFrhY8Er3gCr/JHCrGt0/IIg ddQbTm7p0K1FUU+qL1HvfAQQZbbjvm9JccZZMgiU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 2927B3856964; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2927B3856964 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; cv=none; b=xmyvtAtxesi3HMcYErnAyGLs/xJtgn5VmkzaAjDkP/4yEsznssqlsIotOImwIIW0Kq2l2LIlNyVW/htwQBcxXrbpuENz0wYeTveB91ISYWu97qxDZJsX3SUJA+lKS2wwyII2D09acmyyg5o+eCycbXW9XfHXHb0JAZ5MX3wCLmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237005; c=relaxed/simple; bh=VMehu4HE7BzN624OVO4Fw+NnsTWTfYiByT3bQXMD4Js=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PvLWz1Tz2YhXD3zXI8VDwmpwRGSCUw+W7BBr+g4JW7pu7M87WGJ/J1i+zVPhfCjpYksEAD2pJeH2RHsa2QUn4MbO6CH/Lr9R21Wz5vfeJet+rj1gqwml0qpsdsQRkBx+336q3CdJPi8qLY8lPjEnDGHem8HKxih2Rd9fs4Kfy84= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2927B3856964 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMh0aO001171; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2e9008054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1k016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 33/40] libstdc++: Optimize is_fundamental trait performance Date: Fri, 13 Oct 2023 15:37:47 -0700 Message-ID: <20231013223957.1634024-34-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 4LF9fYgV63lwI7nvBLaRJGH0VeI2Rbhs X-Proofpoint-GUID: 4LF9fYgV63lwI7nvBLaRJGH0VeI2Rbhs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=656 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996476757191546 X-GMAIL-MSGID: 1779682546521735295 This patch optimizes the performance of the is_fundamental trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_fundamental_v): Use __is_arithmetic built-in trait. (is_fundamental): Likewise. Optimize the original implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index cc466e0f606..88171e1a672 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -739,11 +739,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_fundamental +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) + template + struct is_fundamental + : public __bool_constant<__is_arithmetic(_Tp) + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> + { }; +#else template struct is_fundamental - : public __or_, is_void<_Tp>, - is_null_pointer<_Tp>>::type + : public __bool_constant::value + || is_void<_Tp>::value + || is_null_pointer<_Tp>::value> { }; +#endif /// is_object #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ @@ -3354,13 +3364,15 @@ template #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_arithmetic) template inline constexpr bool is_arithmetic_v = __is_arithmetic(_Tp); +template + inline constexpr bool is_fundamental_v + = __is_arithmetic(_Tp) || is_void_v<_Tp> || is_null_pointer_v<_Tp>; #else template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; -#endif - template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) \ && _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) From patchwork Fri Oct 13 22:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195708vqb; Fri, 13 Oct 2023 15:55:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJgLBDzcIS/eqaU3RY4ldy2NAC/KZ6Dx1px8hAqLuK/QBuVLlA/wvzIVbgrcmXRXtVJRjP X-Received: by 2002:a05:622a:591:b0:418:b66:c1bf with SMTP id c17-20020a05622a059100b004180b66c1bfmr34272745qtb.46.1697237713218; Fri, 13 Oct 2023 15:55:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237713; cv=pass; d=google.com; s=arc-20160816; b=P/B862XSAXNu4kfgtVV4DiOqjlmH1FiVmyerkK6vEgug/vTOQZgF+W3ueYfg96r1zL X+byZkCKekJMQUOuvHUZW8a467S61QDOgTthw9itGU1d00t/xtm4ipBWfSCsDB6/qxrm i/alg+TaAh2a/nY/xSn6+gtEmjNIZXmCBS3guLW9aUqEJnRfgp2xul1QNFGhAmkQDLCL QVlOCbLZm6Q+aXbYfqZ3bX9RtRBn1FprtkPAlamb7DyZnuYoLuA3GXvsbhXnXVsvHjaQ s/gkZ58iMfupWpy/j9fjJFzKd7Ajyx6wcA12gaykgQc15BSpBe+RUuguGnQRBQfBYcJp RIQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=o1Nmja410XQ2AZC2k+g0bmtqEr2kmIa4YhBvVROe/As=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=b5mAmtovO1uCqQh+1pcDnhht/8bAgnyaYalbEqTIBF5ow7GPXpTVPdaU2rSVQk3L4D LffZYuI6IPT9xIq9m0xaZz6SHNAMH2JwJiFFGtt7qFC+eT8HgHrc7+blF4ZcjtgAEqvw C+PkuKLAVFiiWx7bv9M8gxTGPQeAaNEuUsJTi2tXX7UhGSlqrSpuEK1SxeTj9/4UKDsH BmpU4Xgt+ODVPCrx8JRiSfQO/1ZPEUanBtg6qheF6rvq4k79HuC1/O24C/pulcJEVn+P d/c43jJj5zjE8i1+EgIztODWOeo3CXEA0SWO7vUG0GUMLXR5F6E+hnXz4qtqLh7anxH6 l6EQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VnFpyi2d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u10-20020a05622a010a00b00403b3e135f6si1955246qtw.785.2023.10.13.15.55.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:55:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VnFpyi2d; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC861385CC84 for ; Fri, 13 Oct 2023 22:55:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC861385CC84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237712; 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=VnFpyi2d9WTI1jI9QQh/pWD7ZN0EmfF6zDOs7ynmX4k+PxgNr/+jEQBiXIBtVU9HF nXaCX7W+r2KB8eGSvv4gXETuCdnfTCoKQLk/nGiFSgXwBVTotbiudkhebGcwGkCWXq LTH04ggk4+Ws8EWbEYlIvun0qxGh/LVP/mylccZs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 8FA8F385C303; Fri, 13 Oct 2023 22:43:22 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8FA8F385C303 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; cv=none; b=Wkq7f+qyz1akgj2TgWgCUpqfZQGBF8kHEpzphr7hUz9/fJz6Ikh4n8jwX2lrPtdCtpRyb4ybjy4eEsSMFYrC7jE1wELi6BdnRgFt8S1zMo8LjrcPVudrjLxdxmrJzMPosAk/OmDmVy+ET+d+CWa6XdZnIGg97N4Qv2W0JOxWJuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237015; c=relaxed/simple; bh=oaOZvY943DFsKkUU3T+LqLGilkqxFzx+Qlt1BfE8jdQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uP3YO7njphLQtRgi9FsgXTBtRjC/C9a5HGZZr5x1SnhgRKkxnN4qaAJyg1CF2Wc20t/XF2REaqmgLcPbLIeROsbOX5ktuNj6B+mOas6F8II1qDbCCs04KbwKnbkiTC9ceJCTMJq6DA0LNibVk6FUyp4fxb5cIbc1jzWvDr4Hakw= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8FA8F385C303 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMhM4G016990; Fri, 13 Oct 2023 22:43:22 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdeu8ttv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:22 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Zs001570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:02 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1l016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 34/40] libstdc++: Optimize is_compound trait performance Date: Fri, 13 Oct 2023 15:37:48 -0700 Message-ID: <20231013223957.1634024-35-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: KSeuGorZXu6hUdK_zUx1ZltPzT5ebfxl X-Proofpoint-ORIG-GUID: KSeuGorZXu6hUdK_zUx1ZltPzT5ebfxl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 adultscore=0 bulkscore=0 mlxlogscore=475 impostorscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996293852351903 X-GMAIL-MSGID: 1779682732308961298 This patch optimizes the performance of the is_compound trait by dispatching to the new __is_arithmetic built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_compound): Do not use __not_. (is_compound_v): Use is_fundamental_v instead. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 88171e1a672..48d630a1478 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,7 +784,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_compound template struct is_compound - : public __not_>::type { }; + : public __bool_constant::value> { }; /// is_member_pointer #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) @@ -3387,7 +3387,7 @@ template template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template - inline constexpr bool is_compound_v = is_compound<_Tp>::value; + inline constexpr bool is_compound_v = !is_fundamental_v<_Tp>; #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) template From patchwork Fri Oct 13 22:37:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2194403vqb; Fri, 13 Oct 2023 15:51:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnBLx5zxjvgndnusoIaCL4GZEAEqTT5edFqVG2qYISORbXVbpLtE92tQwHorDVjjU17hvG X-Received: by 2002:ac8:7350:0:b0:419:50d0:cf5a with SMTP id q16-20020ac87350000000b0041950d0cf5amr25604310qtp.2.1697237473974; Fri, 13 Oct 2023 15:51:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237473; cv=pass; d=google.com; s=arc-20160816; b=GigHgkK/QR1/218BgnNxYJV2OreecBWr0RSKlfKmXJZ/sl29OZE8WW5CBluBFf1V7O NtWcxGCZndUkPvWRj3tlc7ato6fl8luvtXlfCkuhy6O5thD+91iMLDi4aImUFwrqgqi4 vlIchqX+UjkrxPkhyHnfHuTLpDp6umud7V+WJTx+7DeSsNUKT5UoLm5sxO5HLrDBdOtg 1rN7ybTP34Gvyr0p1bR2EZApNOBvn1IaW0RXO4Cksgl3QMSprz7AadtXkgrQ+6tML6xj YF9I4/+Xp0XfhDYSUDmlFCIpemA22tzzrG9OLo9E/xxdNTJktfR123mRqNmv/x91Q/Xc aFqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=+gt+TeTh//XMchDOfk1urud/c39h1cCrtRFun5vxgz0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qJMEljTwyr0ccUJCRy8FmAFW+y5NGCYXROh0GtphyEzf2c+kGTOWMYxj+UkmfL1/PN N1pCuS7Ttr5yxk6BgK1q3BFZcabG9DJmqzxoS0kL6SYom+vVGpBBwuV2HR2OsxfS8KE5 OUHavaGDoo4zNRPuWQDkjmQvUX/CblcgkaSi/KK+S3J65A0tn/KqkTd8Kx9RYsVqMiyY yU5IlUbZlAtjH/zSNuXqprv9AYMoAzeLzzvBfxv+AAXlkGTgrJidj9L53UoCmqars/KP H4e6xsj+WFVtDO2HxgC3kbwCJvABkls9n3l4ZOEvQb5Ej934A/xzaJQkGEW8/OE7Nm/q f+kg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UVqufkSF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a6-20020a05622a064600b00417cf21cf2esi1986961qtb.676.2023.10.13.15.51.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:51:13 -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=UVqufkSF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 548D138618CE for ; Fri, 13 Oct 2023 22:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 548D138618CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237455; 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=UVqufkSFFSU5MhHU5i4WQfqX/Mqzv3VDfEJBZGHOO4pMBniFkJw01J2PhrydRvHLG CNNJz5A24fkxfT8XzPLRgUaaT4DP/gxFYBPBtcNTpoOkdElOGMVBDWPlIJPgG3qCNf ExkWGMBN45kuLq/IyG/3HlKElttwZSTG7SHZat6Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 16367385B515; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16367385B515 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; cv=none; b=EJYDpvK0SA19q1WAjn+B1qWltS7FAJiQfedVBAo8lHzw9nJ6CdHlkCQLT1VVPEcaawqASqzPvxJu72/3YkISeO5Jc9wzYA9Q4gD/y+CDxKK90Ha5T2ScbrxyYcVK+sUBHRunbkqAVNvqS8LLmKQXfzve0nIoA4NCFMfUsSHHfKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237013; c=relaxed/simple; bh=Lgb7wPNnMiIQRjEmMRx6vIFR149IoCrg8hydCryUerg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OBKkb+yadoLGita8a+rczgCwnVL2SG9iCdFbvepeZVebqg+sjFENa7WGGwdzHL/AJQyy75tHN5MG+VQoG3Es5yRlgOjMyUzxPwbvXvZ70gSPU8joaV1qwuyjDERUC4ZN64b07pSwrff/1C1Y9MdKbfPJoT7qJPbjAVQdtVDBgK0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16367385B515 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMgwW6018439; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqbgdj195-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Lm001616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1m016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 35/40] c++: Implement __is_unsigned built-in trait Date: Fri, 13 Oct 2023 15:37:49 -0700 Message-ID: <20231013223957.1634024-36-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ynKdYZ3m-4IBb6pP7CFSnmSbV4QJTQHU X-Proofpoint-ORIG-GUID: ynKdYZ3m-4IBb6pP7CFSnmSbV4QJTQHU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 malwarescore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=739 lowpriorityscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996278564175547 X-GMAIL-MSGID: 1779682481713815871 This patch implements built-in trait for std::is_unsigned. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unsigned. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNSIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unsigned. * g++.dg/ext/is_unsigned.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 118 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_unsigned.C | 47 +++++++++ 7 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_unsigned.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 3a7f968eae8..c28dad702c3 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3829,6 +3829,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_UNSIGNED: + inform (loc, " %qT is not an unsigned type", t1); + break; case CPTK_IS_VOLATILE: inform (loc, " %qT is not a volatile type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b2be7b7bbd7..0603b4a230f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -94,6 +94,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_UNSIGNED, "__is_unsigned", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 9050c36f105..90d05bca5c1 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -74,6 +74,7 @@ struct cp_trait { "__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false "__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false "__is_union", CPTK_IS_UNION, 1, false +"__is_unsigned", CPTK_IS_UNSIGNED, 1, false "__is_volatile", CPTK_IS_VOLATILE, 1, false "__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false "__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 31fd5075f2d..75ab2b5edfa 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 97, duplicates = 0 */ +/* maximum key range = 129, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 20, 104, 45, 50, 40, - 5, 0, 55, 0, 104, 0, 104, 104, 10, 15, - 35, 0, 10, 104, 10, 15, 5, 0, 20, 104, - 104, 20, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, - 104, 104, 104, 104, 104, 104 + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, + 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, + 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, + 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136 }; unsigned int hval = len; @@ -116,46 +116,44 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 59, + TOTAL_KEYWORDS = 60, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 103 + MAX_HASH_VALUE = 135 }; static const struct cp_trait wordlist[] = { -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 83 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, #line 71 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 83 "../../gcc/cp/cp-trait.gperf" +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 86 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, #line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, #line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, @@ -165,11 +163,11 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, #line 66 "../../gcc/cp/cp-trait.gperf" {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" +#line 79 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, @@ -180,7 +178,7 @@ cp_trait_lookup::find (const char *str, size_t len) #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, #line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" @@ -207,6 +205,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" @@ -223,8 +223,8 @@ cp_trait_lookup::find (const char *str, size_t len) {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, #line 67 "../../gcc/cp/cp-trait.gperf" {"__is_reference", CPTK_IS_REFERENCE, 1, false}, #line 70 "../../gcc/cp/cp-trait.gperf" @@ -242,19 +242,23 @@ cp_trait_lookup::find (const char *str, size_t len) #line 53 "../../gcc/cp/cp-trait.gperf" {"__is_final", CPTK_IS_FINAL, 1, false}, #line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false} + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, - 4, -1, 5, 6, 7, 8, 9, -1, 10, 11, -1, 12, -1, 13, - 14, 15, 16, 17, 18, 19, -1, 20, 21, 22, 23, 24, 25, -1, - 26, 27, 28, 29, -1, 30, 31, 32, 33, -1, 34, -1, 35, 36, - 37, -1, 38, 39, 40, -1, -1, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, 49, -1, 50, 51, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, + 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, + 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, + 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, + 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, + 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58 + -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index deab0134509..14387821b85 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12250,6 +12250,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_UNSIGNED: + return TYPE_UNSIGNED (type1); + case CPTK_IS_VOLATILE: return CP_TYPE_VOLATILE_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: + case CPTK_IS_UNSIGNED: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4bc85f4babb..3d380f94b06 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -164,6 +164,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_unsigned) +# error "__has_builtin (__is_unsigned) failed" +#endif #if !__has_builtin (__is_volatile) # error "__has_builtin (__is_volatile) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unsigned.C b/gcc/testsuite/g++.dg/ext/is_unsigned.C new file mode 100644 index 00000000000..2bb45d209a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unsigned.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_unsigned, void, false); + +SA_TEST_CATEGORY(__is_unsigned, bool, (bool(-1) > bool(0))); +SA_TEST_CATEGORY(__is_unsigned, char, (char(-1) > char(0))); +SA_TEST_CATEGORY(__is_unsigned, signed char, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned char, true); +SA_TEST_CATEGORY(__is_unsigned, wchar_t, (wchar_t(-1) > wchar_t(0))); +SA_TEST_CATEGORY(__is_unsigned, short, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned short, true); +SA_TEST_CATEGORY(__is_unsigned, int, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned int, true); +SA_TEST_CATEGORY(__is_unsigned, long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long, true); +SA_TEST_CATEGORY(__is_unsigned, long long, false); +SA_TEST_CATEGORY(__is_unsigned, unsigned long long, true); + +SA_TEST_CATEGORY(__is_unsigned, float, false); +SA_TEST_CATEGORY(__is_unsigned, double, false); +SA_TEST_CATEGORY(__is_unsigned, long double, false); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_unsigned, unsigned __int128, true); +SA_TEST_CATEGORY(__is_unsigned, __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_unsigned, __float128, false); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_unsigned, ClassType, false); From patchwork Fri Oct 13 22:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152796 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192068vqb; Fri, 13 Oct 2023 15:44:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzSrDdtbYWzQ5VgFBCB1NQtWe7ISJRbxo9iFn5wDDN2Y7FRbZSI/VCIMo13lePhPsyw7Vk X-Received: by 2002:ac8:7d4d:0:b0:418:fe4:51e5 with SMTP id h13-20020ac87d4d000000b004180fe451e5mr33591753qtb.24.1697237052767; Fri, 13 Oct 2023 15:44:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237052; cv=pass; d=google.com; s=arc-20160816; b=VkpGo36vqu7wW+g1MOWlaScl6LQSOXltlF4Xxc4h5PAQgC4FM9EB9sk2ihXS+zn3pg QPqO4c810C3+HenkIv4yHr7Cl1wdNz3QY3XY3xoe0BUzMtANBl/RPD/CxM1Io3TIEd8R EabwPjgN7umsevkMhjZBfCjQic72Nvjv+N2/A+o/jsyFvSV9lzksYEmA9ABvVumI5OLw YYGP8TM4vRRzkW10gZiEbSbD0NsNjA9HnefufsLGjEh0HW4GbVIcFrSzPcwokFKk42nW junI/2hgzIwun0HuOM5UahkNAM+mhaDMmw68DE6iYw39lJBb1yXb2vYACDxWH3HkXfRk ClwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=CwlyvDPOmJ6OOvNpdnw7BaxPEtnzz0oDQ2vJDpQNy6k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PRkzZNFl6CbjPRmYf+XCw9axVRwMFyRapmd3d1ZT8zJKRws5hHa9zKs2Ypad2UT6OM qmrxO0t69/r/TaWL0aE1hVtBJFsdNkiqIDMAJw0APsjkOvGt+jdHO7SHeNMPafeoYwMP u4ghDB6MNb++i8AIFxRaTT+0Xg8wIw+UhzOpqc/IsNbm1yEkZyO5iSPJqYpSPGqTABIV nJXDN2VCcqlbEv0ZOGN5YvDJNkBfajG4dJh+JgycyVD2LT6zszH7Ul//lQ7DzFFQOpAU E0vjhGbUIf/1uQ1Rms8JevwkwV3WyQN/N+uDKyb1XmqKuwVuMfNZm+QqCdAIB6kaafFp DqVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j1EZ9zMd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f5-20020a05622a104500b00417b0de7881si1987885qte.527.2023.10.13.15.44.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j1EZ9zMd; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E171385CC86 for ; Fri, 13 Oct 2023 22:44:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E171385CC86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237052; 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=j1EZ9zMdbf9iI2XYbRBGBnRUvSGPOC4b4t3fPVorQIZq7SYcQFfb13yq863JA1OYL ZYkVuc9Rjq0rg0B1Q016r/Cyu8AGwP44H6q3RAgH/WAPrO0xB7zoMTEP6KPujltqZm s835llxLedm4CTmcWv8MtvwTrWwlUVrK1dVPPFj8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 082643857707; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 082643857707 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=dBcJ4w74Ru6b4grNZ/e6QHmlUItJqL6l0kGsvOABmibdCM9dXMarpV2VdgQCgjQ6F8VUIzRu/tfXdxW74wxCBXe/zLxfDz1ngaOkTBufKeKsqYx7yx4Io5jMpW7ewbw42daOnRAkeH5c6B1awwJNpblJvH1edGrSZlSO7D3mZ+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=OO6VSbfKobcguq/wZw63boKixhRizHhk1hfPeW9ER2I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LI5ZoqnPWpabXmG//js6xsGZvjKMTU3RgxxTLcaG20gOmy7gc5xBLv2hhQObaZstfcdxer0eWtxs05LU0mbyj4h+0b/NXcaXDbqNUF2NyKEYQlWDkv6SvueO2HyGZBrWMRNaESXuVmr6uzyVhaZC8sQPfXn8oTuxoSONF6tGoh0= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 082643857707 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMZOWX011530; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqb8ma0mg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh2Z8012759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1n016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 36/40] libstdc++: Optimize is_unsigned trait performance Date: Fri, 13 Oct 2023 15:37:50 -0700 Message-ID: <20231013223957.1634024-37-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: o4VyTW-wXhb2XZMHgJHQio2wJbR1XoVa X-Proofpoint-GUID: o4VyTW-wXhb2XZMHgJHQio2wJbR1XoVa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 suspectscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=750 impostorscore=0 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995061376064333 X-GMAIL-MSGID: 1779682039737410647 This patch optimizes the performance of the is_unsigned trait by dispatching to the new __is_unsigned built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unsigned): Use __is_unsigned built-in trait. (is_unsigned_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 48d630a1478..f7d3815f332 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1001,10 +1001,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_unsigned +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) + template + struct is_unsigned + : public __bool_constant<__is_unsigned(_Tp)> + { }; +#else template struct is_unsigned : public __and_, __not_>>::type { }; +#endif /// @cond undocumented template @@ -3440,8 +3447,14 @@ template template inline constexpr bool is_signed_v = is_signed<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) +template + inline constexpr bool is_unsigned_v = __is_unsigned(_Tp); +#else template inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; +#endif template inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); From patchwork Fri Oct 13 22:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195389vqb; Fri, 13 Oct 2023 15:54:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcMWkY4xe2HL5suvtdV0+crjevTnxRAJNF/AwNL7q26Yk66JLT8L4YKGd417m65p2/oC83 X-Received: by 2002:a05:622a:15ca:b0:418:4e7:b82c with SMTP id d10-20020a05622a15ca00b0041804e7b82cmr33363435qty.57.1697237646611; Fri, 13 Oct 2023 15:54:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237646; cv=pass; d=google.com; s=arc-20160816; b=GHwc4tuxArWXtoboFSL1zlGR2P3QuMEOsdIbHkezS0mIvtXbcnBF9YbHnOute5Gqdr G6aKibuts36iGAexP+f/312f0uYomlXcpht5ZaTS+6Zhvg4ZDtB9j71+Ui7I25FTSVyT CIND9XFPoh8CPvkPF+FguWHlec2kCUG8YMVYnw8HwNtiOUa1uobCScI2qH2hfi7ckvRE zDOmkBhPynQHeCU2KYFzidhAo1RBA9iatabUaKZTYB80Na+2uxwQmnFrFY2ZkGs5C8NA 3Zri/PdPsKZtG+rYb0cS80kKv5O0zyKZKjQQxMQk7/A5H6/DFaSpc3xdF/VUHbK409YW +Y3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=VFV1FjvPw5MG2C0PVVDdB7G4ONd1IAwh+EchNoWGrqg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Sig1NEtgj72fltl1fJ3pVLQGJepGlZhjQWe7yvTM7mW9r8mKPw2jGBlKj1AZEoi6ZD v+yeZdBNPBOjjwb8PCHW7jgkL8N3o7vhf8QMI17Y/ayxCd3fE0VoZ67rWG1Zk17qI9sj CSK+h936KFmboHwiEoF30UsMmrFJwoajWq/Io0h/V89YIMn/TAusl0t91a01j2pKUY0u hARe5O/4aznzCzdirJLEFTdcLDBjZZK4gub/eBkHWFPvnlwMAx8XKrGN8ymyjvpiPWlW 4EvVlr2sjd74AXAAjZrG0n2jWEgtczeyrLliRoGn4M4n9wX5zOlgqAsrzgjwjVyHlZAS R2Mg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fgb6mCFT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n6-20020a05622a040600b00417ce695031si1982764qtx.258.2023.10.13.15.54.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:54:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fgb6mCFT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1147E3857718 for ; Fri, 13 Oct 2023 22:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1147E3857718 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237646; bh=VFV1FjvPw5MG2C0PVVDdB7G4ONd1IAwh+EchNoWGrqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fgb6mCFTl2ShySZujOe55CTBkJ9/cwmJqOTf5UQYY2ytgswmXJSd+802DXO8zATPg C0UzVr+K8P/6WGumLyEC/v/MWS2azK93WB4KA/OesVc1nONHK39Yiyvs6Wp0gsahU6 uowXvRap7rFW6C0st0MrfF4YJq1DkALzmm6WwgW4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id 52CC0385734F; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52CC0385734F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.165.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237009; cv=none; b=i7YPItLpwRLbjSAZgdUGY9bjXd05Aleb2Nmo0hrHSZClndizxPD+swvQM6LDTxdxOTkyzZ6GwD+G0oRWCKze6jA1isSPbxY25F3e8y6SxUaNHnnfK/fxpERYRIeUlocAldnXxFsDLH6XqhXBG4asXKDMNUFGsksRAI9pwgl3Zps= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237009; c=relaxed/simple; bh=kq1u3jMRGoU3/Ev+UFDFUiHgq/Ix7yUbsxOmOQHFY6o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cP78mUnI9FYxd6A0ZF/ft/taUP2JPCYxKi6ZjObrQkIIv/6CmU2GqO9e4oQbzMrjwQWrmDHW1IatHgTOZIm49ZXACVevzVxiE1CG4Vvps6bsOtzvY/xrwkjOYJDyZW301LiLyCIOOEag1pMOnqFtCAFWiApuqigWdydN6sz2c5c= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52CC0385734F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMapkk025263; Fri, 13 Oct 2023 22:43:16 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tq3k05vfe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh311008057 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1o016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:02 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 37/40] c++: Implement __is_signed built-in trait Date: Fri, 13 Oct 2023 15:37:51 -0700 Message-ID: <20231013223957.1634024-38-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bBvh0JBbLgtV4RCU0AnH2KPD3FUoNpEb X-Proofpoint-ORIG-GUID: bBvh0JBbLgtV4RCU0AnH2KPD3FUoNpEb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 adultscore=0 clxscore=1034 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130198 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_35_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677879825354017 X-GMAIL-MSGID: 1779682662476772514 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 211 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_signed.C | 47 +++++ 7 files changed, 165 insertions(+), 105 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c28dad702c3..b161c9b2c9e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SIGNED: + inform (loc, " %qT is not a signed type", t1); + break; case CPTK_IS_SCOPED_ENUM: inform (loc, " %qT is not a scoped enum", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0603b4a230f..b0faa4c8937 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index 90d05bca5c1..de0ba162e7a 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false "__is_trivial", CPTK_IS_TRIVIAL, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 75ab2b5edfa..6d1078de2fe 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -54,7 +54,7 @@ struct cp_trait { short arity; bool type; }; -/* maximum key range = 129, duplicates = 0 */ +/* maximum key range = 119, duplicates = 0 */ class cp_trait_lookup { @@ -69,32 +69,32 @@ cp_trait_lookup::hash (const char *str, size_t len) { static const unsigned char asso_values[] = { - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 20, 136, 45, 35, 40, - 60, 0, 55, 0, 136, 0, 136, 136, 10, 15, - 35, 0, 10, 136, 10, 15, 5, 15, 0, 136, - 136, 20, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136 + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, + 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, + 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, + 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 126 }; unsigned int hval = len; @@ -116,149 +116,150 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 60, + TOTAL_KEYWORDS = 61, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, - MAX_HASH_VALUE = 135 + MAX_HASH_VALUE = 125 }; static const struct cp_trait wordlist[] = { -#line 88 "../../gcc/cp/cp-trait.gperf" +#line 89 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 81 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 83 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 84 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 71 "../../gcc/cp/cp-trait.gperf" +#line 72 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 84 "../../gcc/cp/cp-trait.gperf" +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, #line 51 "../../gcc/cp/cp-trait.gperf" {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 70 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 65 "../../gcc/cp/cp-trait.gperf" {"__is_pointer", CPTK_IS_POINTER, 1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 68 "../../gcc/cp/cp-trait.gperf" + {"__is_same", CPTK_IS_SAME, 2, false}, #line 52 "../../gcc/cp/cp-trait.gperf" {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" +#line 77 "../../gcc/cp/cp-trait.gperf" {"__is_union", CPTK_IS_UNION, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 30 "../../gcc/cp/cp-trait.gperf" + {"__is_same_as", CPTK_IS_SAME, 2, false}, +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, #line 69 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 56 "../../gcc/cp/cp-trait.gperf" - {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, -#line 73 "../../gcc/cp/cp-trait.gperf" + {"__is_signed", CPTK_IS_SIGNED, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" +#line 80 "../../gcc/cp/cp-trait.gperf" {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 33 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 68 "../../gcc/cp/cp-trait.gperf" - {"__is_same", CPTK_IS_SAME, 2, false}, +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, #line 31 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 30 "../../gcc/cp/cp-trait.gperf" - {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 39 "../../gcc/cp/cp-trait.gperf" {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, #line 32 "../../gcc/cp/cp-trait.gperf" {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, -#line 36 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, -#line 55 "../../gcc/cp/cp-trait.gperf" - {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, -#line 37 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, -#line 35 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 56 "../../gcc/cp/cp-trait.gperf" + {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, +#line 40 "../../gcc/cp/cp-trait.gperf" + {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 44 "../../gcc/cp/cp-trait.gperf" + {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, #line 45 "../../gcc/cp/cp-trait.gperf" {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, #line 60 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, #line 62 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, #line 61 "../../gcc/cp/cp-trait.gperf" {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, +#line 55 "../../gcc/cp/cp-trait.gperf" + {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 36 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 64 "../../gcc/cp/cp-trait.gperf" + {"__is_pod", CPTK_IS_POD, 1, false}, +#line 37 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, +#line 35 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, #line 46 "../../gcc/cp/cp-trait.gperf" {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 40 "../../gcc/cp/cp-trait.gperf" - {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, -#line 44 "../../gcc/cp/cp-trait.gperf" - {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 64 "../../gcc/cp/cp-trait.gperf" - {"__is_pod", CPTK_IS_POD, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, #line 38 "../../gcc/cp/cp-trait.gperf" {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, +#line 47 "../../gcc/cp/cp-trait.gperf" + {"__is_class", CPTK_IS_CLASS, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 47 "../../gcc/cp/cp-trait.gperf" - {"__is_class", CPTK_IS_CLASS, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" +#line 88 "../../gcc/cp/cp-trait.gperf" {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} }; static const signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, -1, 8, 9, 10, 11, -1, 12, - 13, 14, 15, 16, 17, 18, -1, 19, 20, 21, 22, 23, 24, -1, - 25, 26, 27, 28, -1, 29, 30, 31, 32, -1, 33, -1, 34, 35, - 36, -1, 37, 38, 39, -1, 40, 41, 42, 43, 44, -1, 45, -1, - 46, -1, -1, 47, -1, 48, -1, -1, 49, 50, 51, -1, -1, -1, - -1, 52, -1, -1, -1, -1, 53, 54, -1, 55, -1, 56, -1, -1, - -1, -1, 57, -1, -1, 58, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 + 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, + 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, + -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, + -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, + -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, + -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 14387821b85..5e6b2ca37ac 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + case CPTK_IS_SCOPED_ENUM: return SCOPED_ENUM_P (type1); @@ -12425,6 +12428,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 3d380f94b06..aaf7254df4b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_signed) +# error "__has_builtin (__is_signed) failed" +#endif #if !__has_builtin (__is_scoped_enum) # error "__has_builtin (__is_scoped_enum) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); From patchwork Fri Oct 13 22:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192243vqb; Fri, 13 Oct 2023 15:44:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnzKIcOCmKJJ9X7C7yZ2/QlvBMed1+VWFrQuz5PdSrwh1rfypL1T/3ODT5NRXUMmNXGeAI X-Received: by 2002:a67:c510:0:b0:457:670b:1810 with SMTP id e16-20020a67c510000000b00457670b1810mr17420090vsk.31.1697237095622; Fri, 13 Oct 2023 15:44:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237095; cv=pass; d=google.com; s=arc-20160816; b=cXKTfnemMhZYx+lrlshzM28rK8BNGrKxWmG+3JP+2+cfFvos2fGxiCqRwtcSUW2/K0 2AwE9aCSWKzGjg/UZXrvYm605EdB1zvxyu6mY96LdU3eyrGQI+wV8ovbMsNehaITKOVr 9TVvKhT8PL67oM/Uz5KvrHjZRKHjhhFICwOScNtwvrm1IeHDkqQie+9bdYjY55vV/2gC CEzqskQbOzgqwLqwS9JW0BC00BdJEe60PlrWuf0BeAGkiKbEc/pqbx02K3QqsBBCbtJG CsOfSPRpmGNH6RUJHjQDHZpkasIAZ9dMIXiu/kJ/pOhDyipZHUsRGC0gXA4njA9tRAO2 aVKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=cQfm2Z2CbE9/tDAPdRh2GGqLZxuO7lj7PQBaV9C0Mb0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=NYnfHJkeH98FjZt4A9rNIw3tdsczhY4OMu079Fmpd8mAq+RgSnMqDVmc6ogwCCF5SF ucoVPlQvvZRcLtMW2dGE2q1DzINzeBQ+yTVIudcuW5d9fi/lWL30Y7CB9iMByHBOkqs0 X4BlVAi7Gpl5/wQ32krqAXWZMug9mRS0ZQuXqAXgeh5aR+M807rHH/y4DeaG4c2UxXHf IPUlVm61kuZ2JIbphA1JMCjfX9mfs+ze8Kmr5Jjjc3AskY6OOCoPKqxgEfA901zLQhjp A1/iWGJV1JbdpSmk4t/hHR6DCUMsP+jDnxfXamVPSMqTIOAaNMAMmsQHDgNF81fK8fLS cgpQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WpxOaq4p; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a24-20020a0ca998000000b0066d1e71e518si1927294qvb.480.2023.10.13.15.44.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:44:55 -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=WpxOaq4p; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3A75385CC8F for ; Fri, 13 Oct 2023 22:44:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3A75385CC8F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237094; 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=WpxOaq4plFbYqyZYaCMLAGiIGVV4jy3ohlAMy63y0aXryYU3otxfWEGNPF6d/idQa Sl0mRIJIU3Sb3yDccIwkbYr5vCkXyv0rm6/dOU1T1Vyzqg8kNIziimnaFQSeVniocO bgAvMTD7rEZ0lHUvEjVgnWkKDJ5mRJiy7J5/oPmQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id B856E3858439; Fri, 13 Oct 2023 22:43:15 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B856E3858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; cv=none; b=DOqVqT0stR3V6AR+XTACeSjLzbK3Pre1p0YWkkuRCk23O9Diup58V4jgLTshooyMpTbvVLCBDFXs0cF76+utgt1Uih5pO5hUhw6V1aPz5z4B1XIu7SQRhFWsUt2123D14JOrtFcRkS/XcTMEVBT2nBs0PiDkRAm7kpf2/7QS+IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697236998; c=relaxed/simple; bh=fm6aTmzL/u+DvSJqIIKZX3rAVzVD2tqarjJM/UYhTyo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GIzmFNWeZklON7nEmG3TjoCl+iiwhuHOgpIczDRAXAZGysf3ap4FDao+xUXsyjNEzyXQ/ZnDPA7Ib4o3vSdp5vmbr+xPJxFcSZF4TIBrNCEmcp0VGoAfRTR5B/2OdJh+sitzAfqyWtOYgsltatrYd+uJufPwpvi8Or5qRExPmXQ= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B856E3858439 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMXSpH014551; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh3kW021625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1p016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 38/40] libstdc++: Optimize is_signed trait performance Date: Fri, 13 Oct 2023 15:37:52 -0700 Message-ID: <20231013223957.1634024-39-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: i2t82heX8u9BemQANbz4FSvbadS3gbco X-Proofpoint-GUID: i2t82heX8u9BemQANbz4FSvbadS3gbco X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=732 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995527999111836 X-GMAIL-MSGID: 1779682084760928689 This patch optimizes the performance of the is_signed trait by dispatching to the new __is_signed built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_signed): Use __is_signed built-in trait. (is_signed_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index f7d3815f332..7e93923f44b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -982,6 +982,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __bool_constant<__is_abstract(_Tp)> { }; + /// is_signed +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) + template + struct is_signed + : public __bool_constant<__is_signed(_Tp)> + { }; +#else /// @cond undocumented template::value> @@ -994,11 +1001,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// @endcond - /// is_signed template struct is_signed : public __is_signed_helper<_Tp>::type { }; +#endif /// is_unsigned #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) @@ -3445,8 +3452,13 @@ template template inline constexpr bool is_final_v = __is_final(_Tp); +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_signed) +template + inline constexpr bool is_signed_v = __is_signed(_Tp); +#else template inline constexpr bool is_signed_v = is_signed<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unsigned) template From patchwork Fri Oct 13 22:37:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2192367vqb; Fri, 13 Oct 2023 15:45:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcEhioMK+WTasbb7Z0FFxB1lcFQvdrM2bJdx5faoCHikcMzBUpFWoWd6Sl3eGZelgypjBS X-Received: by 2002:a0d:e6d1:0:b0:5a7:c6c0:916f with SMTP id p200-20020a0de6d1000000b005a7c6c0916fmr13663805ywe.24.1697237114903; Fri, 13 Oct 2023 15:45:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237114; cv=pass; d=google.com; s=arc-20160816; b=bKAKijH/0MxfXu2PBG1szUr7qAChvGH74FHzNJZAVX4Ye1y7DzNR/7xoJQC5VZS28t /FXurwd2kUcWbbes1E5XJ2LdKPIvmTUBdtp2o+4vM1msqgAjAfcbwAeRzzojZ9voV7FC /EGoxKwaF7HLwjJvDb55tUXB4Y8qOuMytXtXWGISwyB180OA3wBmD5JMN0QxxpVdrLif 8s41mAROJ3cRuwa2UV8wWHHSWlptl247rcvKIU3jJHx2bEaWaPXqmlFLnx5v8LeM2Qrq N36yDEawYtEFv6peNkviu4BeXv11byh8QnQrhVAei4GNLz0i9NAM3B5n3HUnsTYmYLzA bimg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=EU6QwlroNYbuozq9y4oD1NN+xP2fyRjkyDiKNsypsB8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qQf8XLMHB/s8PCd2o5Bqv1e2WZ5XhKMG7yGnMjkIa1yuRKPIX7iRL6leuTWeTHvf9u 7qloOtC0Bcq3cpHlu5dvpkpoHBxVyREiMg90YsVHoNyWr6c8awQhhFomsI0V8H9ErlDC Rxodw8QfaFjdSLJLbxP8Z9jMCRlj8I4HWY82+qpIhclnV8bjZfBAOPA2/S9SSEEtNUTy 1uSV0GR+lgM6URa4/Xdt/qBXoGZBZ7/QqcuB+JXNri+OaEeKPhJqCVRj7OHBo6riW/5q C90t3B8YstBFGNOTsOC4oY7ydJI2gcQaK9vp4/JHUd6cX86q9cDV9rGEwvLQkFk71r4W tRsA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ui9b7Bje; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ks14-20020a056214310e00b0066d03c645a7si1995495qvb.221.2023.10.13.15.45.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:45: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=Ui9b7Bje; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D58B385E019 for ; Fri, 13 Oct 2023 22:45:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D58B385E019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237111; bh=EU6QwlroNYbuozq9y4oD1NN+xP2fyRjkyDiKNsypsB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Ui9b7BjeInu2meEcEBBFFbpkd0OlTvHYRpIpfmrNHSqp0Qu9Nw7ISWxMU+Pr8q7ct pQVXIbOkS3nvgaWUjP08sIBEoHZb3vY55SvVMhZcOnQi/kZY8fVJkthwIfBCfZd12X IQzU0xL7BKsSycvJmDKvX3jvi9mvuiIRwsqFnJE8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 355A3385703F; Fri, 13 Oct 2023 22:43:16 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 355A3385703F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; cv=none; b=bEmhJ7FaMtuBV4okeKjmAJATX9OQP5LZYu0bHG0T+Gr5ac6NZz80IvdtYSPMwCiQEkopfv6xMxJqyFEr63DemhLsXUv6rZpU2sOQwOTW7I9btWURdZU1q2mGjQQVlwomGXWi8JS0MR4N9/uKCv4M9k/YKDwlL+Sev2/fwmq9EdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237001; c=relaxed/simple; bh=RDSBV+PCBbsB8fHtDmG3mZJHO58uwQaWOfg/TlDTAgo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=IFiZgOFCv7gWaDovn9H8dFJBN4/Wzmnpttk3YUnVDhCFJkON7OK6MGdT8x4x/3lpx6xLvicmZoG9ogsTK1NkXmlTfI4oRuWEuYl3fZYucBtgkOPJoguospgoFDulBpQQSH10HGMKT0ElBbvuju5sD3q2fFltLoH7z3Qo+rQCgek= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 355A3385703F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMh0aM001171; Fri, 13 Oct 2023 22:43:15 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqc209mqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:15 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh3sT003504 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1q016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 39/40] c++: Implement __is_scalar built-in trait Date: Fri, 13 Oct 2023 15:37:53 -0700 Message-ID: <20231013223957.1634024-40-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: oGFzPsYERIl3lEF4TVBvgr-Sg3imCMoC X-Proofpoint-GUID: oGFzPsYERIl3lEF4TVBvgr-Sg3imCMoC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=909 suspectscore=0 adultscore=0 clxscore=1034 mlxscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677930252305327 X-GMAIL-MSGID: 1779682105148526600 This patch implements built-in trait for std::is_scalar. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scalar. * cp-trait.gperf: Reflect cp-trait.def change. * cp-trait.h: Likewise. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCALAR. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scalar. * g++.dg/ext/is_scalar.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/cp-trait.gperf | 1 + gcc/cp/cp-trait.h | 186 ++++++++++++----------- gcc/cp/semantics.cc | 4 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scalar.C | 31 ++++ 7 files changed, 137 insertions(+), 92 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b161c9b2c9e..78f100d2745 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3802,6 +3802,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCALAR: + inform (loc, " %qT is not a scalar type", t1); + break; case CPTK_IS_SIGNED: inform (loc, " %qT is not a signed type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b0faa4c8937..08a2780c929 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -86,6 +86,7 @@ DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (IS_SIGNED, "__is_signed", 1) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/cp-trait.gperf b/gcc/cp/cp-trait.gperf index de0ba162e7a..ef51c713c58 100644 --- a/gcc/cp/cp-trait.gperf +++ b/gcc/cp/cp-trait.gperf @@ -66,6 +66,7 @@ struct cp_trait { "__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false "__is_reference", CPTK_IS_REFERENCE, 1, false "__is_same", CPTK_IS_SAME, 2, false +"__is_scalar", CPTK_IS_SCALAR, 1, false "__is_signed", CPTK_IS_SIGNED, 1, false "__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false "__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false diff --git a/gcc/cp/cp-trait.h b/gcc/cp/cp-trait.h index 6d1078de2fe..8c68af420f9 100644 --- a/gcc/cp/cp-trait.h +++ b/gcc/cp/cp-trait.h @@ -78,10 +78,10 @@ cp_trait_lookup::hash (const char *str, size_t len) 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 20, 126, 40, 45, 50, - 55, 0, 5, 15, 126, 0, 126, 126, 35, 10, - 35, 0, 10, 126, 30, 5, 5, 16, 30, 126, - 126, 10, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 126, 40, 126, 25, 21, 50, + 0, 0, 30, 10, 126, 0, 126, 126, 25, 5, + 50, 0, 61, 126, 10, 10, 5, 0, 15, 126, + 126, 5, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, @@ -116,7 +116,7 @@ cp_trait_lookup::find (const char *str, size_t len) { enum { - TOTAL_KEYWORDS = 61, + TOTAL_KEYWORDS = 62, MIN_WORD_LENGTH = 7, MAX_WORD_LENGTH = 37, MIN_HASH_VALUE = 7, @@ -125,141 +125,143 @@ cp_trait_lookup::find (const char *str, size_t len) static const struct cp_trait wordlist[] = { -#line 89 "../../gcc/cp/cp-trait.gperf" +#line 90 "../../gcc/cp/cp-trait.gperf" {"__bases", CPTK_BASES, 1, true}, -#line 82 "../../gcc/cp/cp-trait.gperf" - {"__remove_cv", CPTK_REMOVE_CV, 1, true}, +#line 52 "../../gcc/cp/cp-trait.gperf" + {"__is_enum", CPTK_IS_ENUM, 1, false}, +#line 78 "../../gcc/cp/cp-trait.gperf" + {"__is_union", CPTK_IS_UNION, 1, false}, #line 83 "../../gcc/cp/cp-trait.gperf" - {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, + {"__remove_cv", CPTK_REMOVE_CV, 1, true}, #line 84 "../../gcc/cp/cp-trait.gperf" + {"__remove_cvref", CPTK_REMOVE_CVREF, 1, true}, +#line 89 "../../gcc/cp/cp-trait.gperf" + {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false}, +#line 85 "../../gcc/cp/cp-trait.gperf" {"__remove_pointer", CPTK_REMOVE_POINTER, 1, true}, -#line 72 "../../gcc/cp/cp-trait.gperf" +#line 73 "../../gcc/cp/cp-trait.gperf" {"__is_trivial", CPTK_IS_TRIVIAL, 1, false}, -#line 85 "../../gcc/cp/cp-trait.gperf" +#line 86 "../../gcc/cp/cp-trait.gperf" {"__remove_reference", CPTK_REMOVE_REFERENCE, 1, true}, -#line 90 "../../gcc/cp/cp-trait.gperf" +#line 91 "../../gcc/cp/cp-trait.gperf" {"__direct_bases", CPTK_DIRECT_BASES, 1, true}, -#line 51 "../../gcc/cp/cp-trait.gperf" - {"__is_empty", CPTK_IS_EMPTY, 1, false}, -#line 70 "../../gcc/cp/cp-trait.gperf" - {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, -#line 65 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer", CPTK_IS_POINTER, 1, false}, +#line 79 "../../gcc/cp/cp-trait.gperf" + {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, #line 68 "../../gcc/cp/cp-trait.gperf" {"__is_same", CPTK_IS_SAME, 2, false}, -#line 52 "../../gcc/cp/cp-trait.gperf" - {"__is_enum", CPTK_IS_ENUM, 1, false}, -#line 77 "../../gcc/cp/cp-trait.gperf" - {"__is_union", CPTK_IS_UNION, 1, false}, +#line 71 "../../gcc/cp/cp-trait.gperf" + {"__is_scoped_enum", CPTK_IS_SCOPED_ENUM, 1, false}, #line 30 "../../gcc/cp/cp-trait.gperf" {"__is_same_as", CPTK_IS_SAME, 2, false}, -#line 75 "../../gcc/cp/cp-trait.gperf" +#line 76 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_copyable", CPTK_IS_TRIVIALLY_COPYABLE, 1, false}, -#line 86 "../../gcc/cp/cp-trait.gperf" - {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, -#line 73 "../../gcc/cp/cp-trait.gperf" +#line 59 "../../gcc/cp/cp-trait.gperf" + {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, +#line 74 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_assignable", CPTK_IS_TRIVIALLY_ASSIGNABLE, 2, false}, -#line 69 "../../gcc/cp/cp-trait.gperf" +#line 70 "../../gcc/cp/cp-trait.gperf" {"__is_signed", CPTK_IS_SIGNED, 1, false}, -#line 74 "../../gcc/cp/cp-trait.gperf" +#line 75 "../../gcc/cp/cp-trait.gperf" {"__is_trivially_constructible", CPTK_IS_TRIVIALLY_CONSTRUCTIBLE, -1, false}, -#line 78 "../../gcc/cp/cp-trait.gperf" - {"__is_unsigned", CPTK_IS_UNSIGNED, 1, false}, -#line 81 "../../gcc/cp/cp-trait.gperf" +#line 82 "../../gcc/cp/cp-trait.gperf" {"__reference_converts_from_temporary", CPTK_REF_CONVERTS_FROM_TEMPORARY, 2, false}, -#line 80 "../../gcc/cp/cp-trait.gperf" - {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, -#line 33 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, -#line 59 "../../gcc/cp/cp-trait.gperf" - {"__is_member_pointer", CPTK_IS_MEMBER_POINTER, 1, false}, -#line 31 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, -#line 39 "../../gcc/cp/cp-trait.gperf" - {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, -#line 32 "../../gcc/cp/cp-trait.gperf" - {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 58 "../../gcc/cp/cp-trait.gperf" {"__is_member_object_pointer", CPTK_IS_MEMBER_OBJECT_POINTER, 1, false}, -#line 63 "../../gcc/cp/cp-trait.gperf" - {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 81 "../../gcc/cp/cp-trait.gperf" + {"__reference_constructs_from_temporary", CPTK_REF_CONSTRUCTS_FROM_TEMPORARY, 2, false}, #line 57 "../../gcc/cp/cp-trait.gperf" {"__is_member_function_pointer", CPTK_IS_MEMBER_FUNCTION_POINTER, 1, false}, -#line 67 "../../gcc/cp/cp-trait.gperf" - {"__is_reference", CPTK_IS_REFERENCE, 1, false}, -#line 53 "../../gcc/cp/cp-trait.gperf" - {"__is_final", CPTK_IS_FINAL, 1, false}, -#line 87 "../../gcc/cp/cp-trait.gperf" - {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, -#line 54 "../../gcc/cp/cp-trait.gperf" - {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 46 "../../gcc/cp/cp-trait.gperf" + {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, #line 42 "../../gcc/cp/cp-trait.gperf" {"__is_arithmetic", CPTK_IS_ARITHMETIC, 1, false}, +#line 77 "../../gcc/cp/cp-trait.gperf" + {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, +#line 88 "../../gcc/cp/cp-trait.gperf" + {"__underlying_type", CPTK_UNDERLYING_TYPE, 1, true}, +#line 45 "../../gcc/cp/cp-trait.gperf" + {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, +#line 43 "../../gcc/cp/cp-trait.gperf" + {"__is_array", CPTK_IS_ARRAY, 1, false}, +#line 69 "../../gcc/cp/cp-trait.gperf" + {"__is_scalar", CPTK_IS_SCALAR, 1, false}, #line 56 "../../gcc/cp/cp-trait.gperf" {"__is_literal_type", CPTK_IS_LITERAL_TYPE, 1, false}, #line 40 "../../gcc/cp/cp-trait.gperf" {"__is_abstract", CPTK_IS_ABSTRACT, 1, false}, +#line 41 "../../gcc/cp/cp-trait.gperf" + {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, #line 44 "../../gcc/cp/cp-trait.gperf" {"__is_assignable", CPTK_IS_ASSIGNABLE, 2, false}, -#line 66 "../../gcc/cp/cp-trait.gperf" - {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, -#line 45 "../../gcc/cp/cp-trait.gperf" - {"__is_base_of", CPTK_IS_BASE_OF, 2, false}, -#line 60 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, -#line 62 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, -#line 71 "../../gcc/cp/cp-trait.gperf" - {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, -#line 61 "../../gcc/cp/cp-trait.gperf" - {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 55 "../../gcc/cp/cp-trait.gperf" {"__is_layout_compatible", CPTK_IS_LAYOUT_COMPATIBLE, 2, false}, +#line 80 "../../gcc/cp/cp-trait.gperf" + {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, +#line 67 "../../gcc/cp/cp-trait.gperf" + {"__is_reference", CPTK_IS_REFERENCE, 1, false}, +#line 72 "../../gcc/cp/cp-trait.gperf" + {"__is_standard_layout", CPTK_IS_STD_LAYOUT, 1, false}, +#line 33 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_copy", CPTK_HAS_NOTHROW_COPY, 1, false}, +#line 31 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_assign", CPTK_HAS_NOTHROW_ASSIGN, 1, false}, +#line 39 "../../gcc/cp/cp-trait.gperf" + {"__has_virtual_destructor", CPTK_HAS_VIRTUAL_DESTRUCTOR, 1, false}, +#line 32 "../../gcc/cp/cp-trait.gperf" + {"__has_nothrow_constructor", CPTK_HAS_NOTHROW_CONSTRUCTOR, 1, false}, #line 36 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_copy", CPTK_HAS_TRIVIAL_COPY, 1, false}, -#line 41 "../../gcc/cp/cp-trait.gperf" - {"__is_aggregate", CPTK_IS_AGGREGATE, 1, false}, -#line 34 "../../gcc/cp/cp-trait.gperf" - {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, #line 64 "../../gcc/cp/cp-trait.gperf" {"__is_pod", CPTK_IS_POD, 1, false}, +#line 34 "../../gcc/cp/cp-trait.gperf" + {"__has_trivial_assign", CPTK_HAS_TRIVIAL_ASSIGN, 1, false}, +#line 51 "../../gcc/cp/cp-trait.gperf" + {"__is_empty", CPTK_IS_EMPTY, 1, false}, +#line 65 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer", CPTK_IS_POINTER, 1, false}, #line 37 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_destructor", CPTK_HAS_TRIVIAL_DESTRUCTOR, 1, false}, #line 35 "../../gcc/cp/cp-trait.gperf" {"__has_trivial_constructor", CPTK_HAS_TRIVIAL_CONSTRUCTOR, 1, false}, -#line 79 "../../gcc/cp/cp-trait.gperf" - {"__is_volatile", CPTK_IS_VOLATILE, 1, false}, -#line 46 "../../gcc/cp/cp-trait.gperf" - {"__is_bounded_array", CPTK_IS_BOUNDED_ARRAY, 1, false}, -#line 43 "../../gcc/cp/cp-trait.gperf" - {"__is_array", CPTK_IS_ARRAY, 1, false}, -#line 76 "../../gcc/cp/cp-trait.gperf" - {"__is_unbounded_array", CPTK_IS_UNBOUNDED_ARRAY, 1, false}, -#line 38 "../../gcc/cp/cp-trait.gperf" - {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false}, -#line 48 "../../gcc/cp/cp-trait.gperf" - {"__is_const", CPTK_IS_CONST, 1, false}, +#line 60 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_assignable", CPTK_IS_NOTHROW_ASSIGNABLE, 2, false}, +#line 62 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_convertible", CPTK_IS_NOTHROW_CONVERTIBLE, 2, false}, +#line 87 "../../gcc/cp/cp-trait.gperf" + {"__type_pack_element", CPTK_TYPE_PACK_ELEMENT, -1, true}, +#line 61 "../../gcc/cp/cp-trait.gperf" + {"__is_nothrow_constructible", CPTK_IS_NOTHROW_CONSTRUCTIBLE, -1, false}, #line 47 "../../gcc/cp/cp-trait.gperf" {"__is_class", CPTK_IS_CLASS, 1, false}, +#line 53 "../../gcc/cp/cp-trait.gperf" + {"__is_final", CPTK_IS_FINAL, 1, false}, +#line 54 "../../gcc/cp/cp-trait.gperf" + {"__is_function", CPTK_IS_FUNCTION, 1, false}, +#line 63 "../../gcc/cp/cp-trait.gperf" + {"__is_pointer_interconvertible_base_of", CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF, 2, false}, +#line 66 "../../gcc/cp/cp-trait.gperf" + {"__is_polymorphic", CPTK_IS_POLYMORPHIC, 1, false}, +#line 48 "../../gcc/cp/cp-trait.gperf" + {"__is_const", CPTK_IS_CONST, 1, false}, #line 50 "../../gcc/cp/cp-trait.gperf" {"__is_convertible", CPTK_IS_CONVERTIBLE, 2, false}, #line 49 "../../gcc/cp/cp-trait.gperf" {"__is_constructible", CPTK_IS_CONSTRUCTIBLE, -1, false}, -#line 88 "../../gcc/cp/cp-trait.gperf" - {"__is_deducible ", CPTK_IS_DEDUCIBLE, 2, false} +#line 38 "../../gcc/cp/cp-trait.gperf" + {"__has_unique_object_representations", CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS, 1, false} }; static const signed char lookup[] = { - -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, 1, -1, -1, - 2, -1, 3, 4, 5, 6, 7, 8, 9, -1, 10, 11, 12, 13, - 14, 15, 16, 17, -1, 18, 19, 20, -1, 21, 22, 23, 24, -1, - -1, -1, 25, 26, 27, 28, 29, 30, 31, -1, 32, 33, -1, 34, - -1, 35, 36, -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, -1, -1, 48, 49, 50, -1, -1, 51, 52, 53, 54, -1, -1, - -1, -1, -1, -1, -1, -1, 55, -1, -1, -1, -1, 56, -1, -1, - -1, -1, 57, 58, -1, 59, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 + -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, -1, -1, + 4, 5, 6, 7, 8, 9, -1, -1, -1, 10, 11, -1, 12, 13, + 14, 15, 16, 17, -1, 18, -1, 19, 20, 21, 22, 23, 24, 25, + 26, 27, -1, 28, 29, 30, 31, 32, 33, -1, 34, 35, 36, 37, + -1, -1, 38, -1, 39, -1, -1, -1, 40, 41, -1, -1, 42, 43, + 44, 45, -1, 46, 47, 48, -1, -1, 49, 50, 51, 52, -1, -1, + -1, 53, -1, -1, -1, -1, 54, -1, -1, 55, -1, -1, -1, -1, + 56, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, 58, -1, + -1, -1, -1, -1, 59, -1, 60, -1, -1, -1, -1, -1, -1, 61 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5e6b2ca37ac..be345f9aa47 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12226,6 +12226,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_SIGNED: return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; @@ -12428,6 +12431,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: + case CPTK_IS_SCALAR: case CPTK_IS_SIGNED: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index aaf7254df4b..f4f6fed6876 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -140,6 +140,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif #if !__has_builtin (__is_signed) # error "__has_builtin (__is_signed) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..457fddc52fc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include // std::nullptr_t +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// volatile return type would cause a warning. +#define SA_FN_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_scalar, int, true); +SA_TEST_CATEGORY(__is_scalar, float, true); +SA_TEST_CATEGORY(__is_scalar, EnumType, true); +SA_TEST_CATEGORY(__is_scalar, int*, true); +SA_FN_TEST_CATEGORY(__is_scalar, int(*)(int), true); +SA_TEST_CATEGORY(__is_scalar, int (ClassType::*), true); +SA_FN_TEST_CATEGORY(__is_scalar, int (ClassType::*) (int), true); +SA_TEST_CATEGORY(__is_scalar, std::nullptr_t, true); + +// Sanity check. +SA_TEST_CATEGORY(__is_scalar, ClassType, false); From patchwork Fri Oct 13 22:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 152848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2195208vqb; Fri, 13 Oct 2023 15:53:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQxkB4Prqo/ciuNy+C4joyGOp7VoHqGsgfAfS9BQxwnylIia9m2MJgTwmUM1BiL02Uf27u X-Received: by 2002:ac8:5bc1:0:b0:417:9c63:a7ac with SMTP id b1-20020ac85bc1000000b004179c63a7acmr30855854qtb.68.1697237615439; Fri, 13 Oct 2023 15:53:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697237615; cv=pass; d=google.com; s=arc-20160816; b=BnsXBgwjlAC3hX+uuBPrvGYEcXHXstvKyRY2vxMskKsn7aMzlayOkAV1OVYYPi5+aV SeckiwSUGdV9qQf+XX3clHD1jjkvqX7RfnYKY8GHfy0Ll2YdVStrfNEKyI42gX4W49QO 3HRYjHlpsMGCMNUb1uJarbF6Sk8XYIMf4N6HGJccTRzvqK8mTP71hFcV0fR2e6a2AW5X uvv/YCHqytPunbFhq/4yA4O8ymX+dGhaFTu4a3iV1fpnvkWeismNB9NaBAKQbXX3A4wB newfC4JgdewNJ4NNm2hZDygYEQkn8Qt2WlS6/2jS6QlqW8sUE/4wKg5vZO0TxulGLfIP 257A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:arc-filter:delivered-to:dkim-signature :dkim-filter; bh=wgA0JB2W7H093Rs+2xKll9G1wCc1Kjb079SkDPcw4Tc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=XwtFQHGC+9u6VspPWwhHLgWcjc0luZn8sUqim10LamV8Oilzrdghkb2Lgjx2Qc5xE6 O7qI2HibrL+JEESVb+0LXkPvx1KgtAnQom3xmGRLfSQ7/VzlTQaBeT4Sd+4tPHeBL3zd WYnVnnmiLG/16kEr8FB3n9DYS2sdxLHTvqFjrLHqlxc1cLrNNm5UvrcqqMxQLh4HX0oK k0TdjuRZ6noIOBHxbyk3aAcD3+Byy9OwE/3RR0ztA9YjhHV3nwwW8N8KoivSB+WbsS9X FaDXluDry2h/UzZdGaFNYYIQ54o3pEQooUle9afM/hT+KS3RSReYY0o2j6rWAl7uQ9Mr GTjw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OYhhM5uB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w12-20020ac857cc000000b00419a4b7aa59si1874249qta.481.2023.10.13.15.53.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 15:53:35 -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=OYhhM5uB; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 015123856956 for ; Fri, 13 Oct 2023 22:53:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 015123856956 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697237614; 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=OYhhM5uBS6wagWYznPER55dPj+7znsJ3ksvYX4mpJOsCH0p/P2YtIhkGJ4A8wE9qf L71M0g9mK4zSvdH94IZ/zNMmCyymHdDqVglrW5HtDMcxb71VfKJneNEhJjDmZf8z4C aI41tFEi8Wk4KI4Bgjd11rORo6thq9O14pmsqYS8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id B39F83856975; Fri, 13 Oct 2023 22:43:17 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B39F83856975 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.177.146 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; cv=none; b=oVclhfOxC5ND6bWklLL3g0TM2CjuZ1SpdVVbo5/azVxYj9I4VL/hmX+zwoCUDS6xUyEZDf4C7gevVAnQQc9JGPQsDstfExpGMBcHxSAf/h70b0OnuG/MktYuvf8A8NcEoJ8bGBEXW2r0w4OZ3kFdDqNuDVm1wf4VLF89OKYEqGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697237008; c=relaxed/simple; bh=yZDHLGphd8jxjnk42PZPq1zND4PhrwWhUcJ7anaWSLE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LDFZ0t7y/HgFSUKbpgh9d7UHeLoHhymB6T1/bSD/O+vOa9jrRhLFd8FhgN4xN03okdoS0USWYHD9U2362EjWh+m3KUbZvADhsicg04DRaZBHlCIT2mT7gf8Cwivkv/L/rZjmQr4iC4kANRjLum3fafFWIOjK74Tgi7oVmp9HpsM= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B39F83856975 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DMgb9m003205; Fri, 13 Oct 2023 22:43:17 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tqdep0tce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 22:43:17 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39DMh38D001617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:43:03 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39DMdx1r016619 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Oct 2023 15:43:03 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v19 40/40] libstdc++: Optimize is_scalar trait performance Date: Fri, 13 Oct 2023 15:37:54 -0700 Message-ID: <20231013223957.1634024-41-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> References: <20231013211206.1215663-1-kmatsui@gcc.gnu.org> <20231013223957.1634024-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 0c1_DTiq1cewC3nRqHC_9mwJFqpECQft X-Proofpoint-GUID: 0c1_DTiq1cewC3nRqHC_9mwJFqpECQft X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_12,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1034 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=551 mlxscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130197 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997480812710190 X-GMAIL-MSGID: 1779682629496828815 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>;