From patchwork Thu Dec 7 05:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174924 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4572376vqy; Wed, 6 Dec 2023 21:38:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFU7gfDme0bLsnewZCyAo5MZBrxv/QKjpLhN4aTubtl5fjpUR5ELdaaJ7ZVJABOVdNf91/Y X-Received: by 2002:ac8:5782:0:b0:425:4043:1d9e with SMTP id v2-20020ac85782000000b0042540431d9emr2259378qta.113.1701927513701; Wed, 06 Dec 2023 21:38:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927513; cv=pass; d=google.com; s=arc-20160816; b=I2mGwZrGq7yie+TuvnIW1v37kWFOveybAvJ5sGj/DZeKmGHvUbgM/Co8A7BnxlTvV6 KqJuYCr24rfNCi9Q36EipYNm07ss70EcGYBWVFUDYas4iZoBaTJbNbxmvQZKpreCDQJg 0TfxFajjww8S07IOdeBhJvmQMHvuvgCLh36g9O8RftLjbl0GTXYgdlu7PrU/MV/VGDyo z6qpj0z0MNr++fFi0MjqWlFZWOOLjyczdB2tGZ3tXwu6zCKDFaRqI0WMC7SFodmCcoAD zE2w5cZGvnQZW+z8E7y8KqVt0/z6PSOqKlC9HiXJZWROL/5aQ44GwMD4L2bVzJyMd3F7 MwpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Fc6My0CJ3TYmMveJ5thRQb28SNtPtkQPOIwa5IgZ510=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=nfd4kPrW7u6O4i93H1mfLFj5Yr2ZqZxXFT80MQM9gUTjGTJoGfwwCaj5Ybij+RKowW RA6PTqNTquZabvxXBcKzXIl/kTuQIxUMYdw9m2Smm3zys16pqXc5D9eeBes78KuoRRkt YeC6IMtWXm+Q53va2l3SpLv24DTHMLDA5boYQV8LPjMUmpfnOrCve4XcZMuux5UXy6dq GUIQdSWYFdAwabxs+xKrpcMJIOvI1GD35JViGCRsTbi6H449K9fxq1IwensAWBZd1pCD tp1qjkZfaEakbGSgmkkYVjFrljY4/B8dheGwo5C7eMy+YEXhoXTb9PfZzzNfS5V/vfjf QSNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=InbLVlg3; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x22-20020ac87ed6000000b00425199e7e10si642056qtj.19.2023.12.06.21.38.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:38:33 -0800 (PST) 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=InbLVlg3; 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 6D1353857C4D for ; Thu, 7 Dec 2023 05:38:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D1353857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927513; bh=Fc6My0CJ3TYmMveJ5thRQb28SNtPtkQPOIwa5IgZ510=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=InbLVlg37LC3YXhTLHoM6/HGZ4diO8TjepYUDY9ybtReYX2XTIYrGk1SHKBdxOf+5 NUyCPHDwPC6aPz6Ml2egdQRQM+AvrsvbL9NkrlN4qRVyvXm9cLAdBo1DfP8GU7lyXz ZKf2M5gfJcJTPFmVVxozc1p62Q/1nO8fXhRCCRQg= 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 4E70938582A5; Thu, 7 Dec 2023 05:37:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E70938582A5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E70938582A5 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=1701927469; cv=none; b=s+D72SgCIvi/NQa73kFj+lDUfOBIdCJUDGF6GYgZOC+d1NT/4OazTLgGc8Vq+AYMz+aJt/06EaMIbDaelVrnbLmp7tzbrDHVMmr8TGlUKA6r6ADOyOJReQ7sTBkjiKSxSScTJf6M98xBLyZc8d+fPKmtaidhbsigqJyvgfta19g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927469; c=relaxed/simple; bh=KkNnnSK1znGUuaWMNlqJw6TGMFV0YjyY2ZYSetKy2Ic=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=F5Ve7fF2QheBSvY328MTGyYil9v1JkQMyoKdrClOXdqmyB17B03twiCd3mRMiO+oa+RWlLXzkedh0lON9XbJX7ylB3KCjuhRdE469jmIagCtTiiUwq2GLY9qKQgbiHnLMjcwGwii+w/Y5K4RC/nZnGIXoSC/wC2MMtXKsYvlYV0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75ZQ99012248; Thu, 7 Dec 2023 05:37:47 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu0y1u4h6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:37:46 +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 3B75bIoe004847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:37:18 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ2020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:37:18 -0800 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 v26 01/23] c++: Sort built-in traits alphabetically Date: Wed, 6 Dec 2023 21:32:56 -0800 Message-ID: <20231207053633.1001720-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: nf7UI2__brOl7DNYUGvV1EHGgaLijy8- X-Proofpoint-ORIG-GUID: nf7UI2__brOl7DNYUGvV1EHGgaLijy8- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 impostorscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060160 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, T_SCC_BODY_TEXT_LINE 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: 1780600765540252355 X-GMAIL-MSGID: 1784600344934472373 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 d9972d69725..29aa7bb3df8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3707,18 +3707,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; @@ -3734,6 +3752,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); @@ -3753,50 +3783,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 6634acfda3f..3abbd6df983 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12303,15 +12303,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) @@ -12320,17 +12311,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. */ @@ -12344,18 +12344,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) @@ -12364,6 +12367,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); @@ -12379,6 +12388,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); @@ -12409,24 +12427,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); @@ -12539,9 +12539,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; @@ -12561,12 +12561,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) @@ -12585,8 +12585,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: @@ -12649,25 +12649,25 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2, switch (kind) { - case CPTK_UNDERLYING_TYPE: - return finish_underlying_type (type1); - case CPTK_REMOVE_CV: return cv_unqualified (type1); - case CPTK_REMOVE_REFERENCE: + case CPTK_REMOVE_CVREF: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return type1; + return cv_unqualified (type1); - case CPTK_REMOVE_CVREF: + case CPTK_REMOVE_REFERENCE: if (TYPE_REF_P (type1)) type1 = TREE_TYPE (type1); - return cv_unqualified (type1); + return type1; case CPTK_TYPE_PACK_ELEMENT: return finish_type_pack_element (type1, type2, complain); + case CPTK_UNDERLYING_TYPE: + return finish_underlying_type (type1); + #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \ case CPTK_##CODE: #include "cp-trait.def" diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..2223f08a628 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -8,9 +8,21 @@ #if !__has_builtin (__builtin_bit_cast) # error "__has_builtin (__builtin_bit_cast) failed" #endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif #if !__has_builtin (__builtin_launder) # error "__has_builtin (__builtin_launder) failed" #endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif #if !__has_builtin (__has_nothrow_assign) # error "__has_builtin (__has_nothrow_assign) failed" #endif @@ -44,12 +56,21 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_convertible) +# error "__has_builtin (__is_convertible) failed" +#endif #if !__has_builtin (__is_empty) # error "__has_builtin (__is_empty) failed" #endif @@ -65,6 +86,15 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_convertible) +# error "__has_builtin (__is_nothrow_convertible) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif @@ -98,51 +128,21 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif -#if !__has_builtin (__underlying_type) -# error "__has_builtin (__underlying_type) failed" -#endif -#if !__has_builtin (__is_assignable) -# error "__has_builtin (__is_assignable) failed" -#endif -#if !__has_builtin (__is_constructible) -# error "__has_builtin (__is_constructible) failed" -#endif -#if !__has_builtin (__is_nothrow_assignable) -# error "__has_builtin (__is_nothrow_assignable) failed" -#endif -#if !__has_builtin (__is_nothrow_constructible) -# error "__has_builtin (__is_nothrow_constructible) failed" -#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif #if !__has_builtin (__reference_converts_from_temporary) # error "__has_builtin (__reference_converts_from_temporary) failed" #endif -#if !__has_builtin (__builtin_is_constant_evaluated) -# error "__has_builtin (__builtin_is_constant_evaluated) failed" -#endif -#if !__has_builtin (__builtin_source_location) -# error "__has_builtin (__builtin_source_location) failed" -#endif -#if !__has_builtin (__builtin_is_corresponding_member) -# error "__has_builtin (__builtin_is_corresponding_member) failed" -#endif -#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) -# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" -#endif -#if !__has_builtin (__is_convertible) -# error "__has_builtin (__is_convertible) failed" -#endif -#if !__has_builtin (__is_nothrow_convertible) -# error "__has_builtin (__is_nothrow_convertible) failed" -#endif #if !__has_builtin (__remove_cv) # error "__has_builtin (__remove_cv) failed" #endif +#if !__has_builtin (__remove_cvref) +# error "__has_builtin (__remove_cvref) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif -#if !__has_builtin (__remove_cvref) -# error "__has_builtin (__remove_cvref) failed" +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" #endif From patchwork Thu Dec 7 05:32:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4572755vqy; Wed, 6 Dec 2023 21:40:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHlVQC8gWI9acWGA43w/ajQtnZpoYe2Xc8bIrIvTFsfNXTNuAKCd1AoDj2Ck1sOYzZ4Hd7w X-Received: by 2002:a05:620a:8ec5:b0:77f:85a:98cc with SMTP id rg5-20020a05620a8ec500b0077f085a98ccmr600669qkn.67.1701927609247; Wed, 06 Dec 2023 21:40:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927609; cv=pass; d=google.com; s=arc-20160816; b=yd49cJJN1TwM2gfuUGLUoMi6jBOGrYofakNzdrjCrHYQNdelQmJ0XcTgotXnCi8zvO rPrRks9JSauW+n9aoMs1/jdcfx0oRpF1Kr4sJVO2JeFnWcEG9RmF1EcXPhdE+5x+pGnU 6c0CrLOaZMKJ//JOxL9NFnBMgLdBhyuxKo8PR1keNPqcZVlOeN8mqiQ/HO/Boy1Ee+zR qlgZiazaE4hd4X+945PG+99X/TGPBHwGRKhshWZYaB1UyEmHarZBUK4honRy/NoD4fkJ V1XhUSh5YQCopzIb9vcA85DpP9s0MNEYQKwAdOw7EHtIWxBe5snpsR8VRwJYVpvAr8Km 33hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=T0UnzDsJD8I6fqZ79v8jldNOC82eUG8RKKORUliHVKU=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=W0XA46l5USCQE1cmoCOVSujyXu7gW9o1W46IMN/MVlqMh3mXg1LzBhxm3fIU77QYFx 2jdSzFWPEN0IOUCAbR/oKcVx0WPeKZoIkmKht4LcFnvXZ2qRcHq7kz8R2ezjuF1P/gv+ r1/3WLZqsNFYh7HKQEMCNWYRNjC2gHt1jY4rN0FJ2Oa61PhsnHoWda5aUeAU+M1oDku4 lWD569mAUqngQxSXgjVwt/RpmRB7xmqyFNqGStoOakQ5Or9JWWFUP9NxFSqtA+OMTvdM XB/zxyeK2WHTFi9h5S6B8Tl4BvJKEFivgHGke1U5QV+SeDKTzLHJ04dkkT3wwtDg7Y6p WbHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dfO2XO9n; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 8-20020a05620a048800b0077f04dc5d27si568255qkr.112.2023.12.06.21.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:40:09 -0800 (PST) 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=dfO2XO9n; 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 EE4FC385B83F for ; Thu, 7 Dec 2023 05:40:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE4FC385B83F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927609; bh=T0UnzDsJD8I6fqZ79v8jldNOC82eUG8RKKORUliHVKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dfO2XO9nyRmehvN9vfJ1kQjcua5yPfAbw/xWgHYyWgT2fgKRwWGiQxxlnpGUlwyZ1 LDOQHivbUji8NG8/6n6lh6PHkuClEF4XDPD2HYDFmDJPPqRPIddNvRAo6CzAEy3h12 Ltc+YQDSMDvphvdXNw5kl5lCIu93/75GXejgCeyc= 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 BCFBA3858421; Thu, 7 Dec 2023 05:38:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCFBA3858421 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BCFBA3858421 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=1701927534; cv=none; b=sVS2sAWVAb7aIMql7lrjUQZi+VRlpPs6jgbvCk/jyML1vi0iZ53ZSX8Lw0rwfZNYifKlV8EbQlKfrPVCYLQEmgzM2JI0BDOLmv9+jkUH9ujLtxVYxlsDrER+LguuiZhmoKDcN5helV/AeTZajQLcAxWQh5mfSNNjXMPZdLzZdXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927534; c=relaxed/simple; bh=l8bHWmmUFAMZNwuiOVTl6HXUKJIdDS+ShwLcwT6Opx4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vnzcjw3mpxZ7QO+buW4lXF82pvY4jgZKMG/zUJ1qMY4DlkrizB7fGpgPL6h+BaocpvbmeIHwTejoA2flhmrwmSAMpjsyeZ74O53BIsNGJHnfdGp2j2TG1ObXnO8MfBDfKF6F3MnAhsGH5EJr7UBzECunQNO1A4RA6hFPmqHAYjY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75cKUj019247; Thu, 7 Dec 2023 05:38:50 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu831r03c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:38:50 +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 3B75cPiW005017 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:38:25 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ3020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:38:25 -0800 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 v26 02/23] c-family, c++: Look up built-in traits via identifier node Date: Wed, 6 Dec 2023 21:32:57 -0800 Message-ID: <20231207053633.1001720-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2MFGbGASbtbzbQGI0FTtZl_-QRy5cokN X-Proofpoint-ORIG-GUID: 2MFGbGASbtbzbQGI0FTtZl_-QRy5cokN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070040 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600691225517309 X-GMAIL-MSGID: 1784600444672521841 Since RID_MAX soon reaches 255 and all built-in traits are used approximately once in a C++ translation unit, this patch removes all RID values for built-in traits and uses the identifier node to look up the specific trait. Rather than holding traits as keywords, we set all trait identifiers as cik_trait, which is a new cp_identifier_kind. As cik_reserved_for_udlit was unused and cp_identifier_kind is 3 bits, we replaced the unused field with the new cik_trait. Also, the later patch handles a subsequent token to the built-in identifier so that we accept the use of non-function-like built-in trait identifiers. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Remove all mappings of built-in traits. * c-common.h (enum rid): Remove all RID values for built-in traits. gcc/cp/ChangeLog: * cp-objcp-common.cc (names_builtin_p): Remove all RID value cases for built-in traits. Check for built-in traits via the new cik_trait kind. * cp-tree.h (enum cp_trait_kind): Set its underlying type to addr_space_t. (struct cp_trait): New struct to hold trait information. (cp_traits): New array to hold a mapping to all traits. (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (cp_traits): Define its values, declared in cp-tree.h. (init_cp_traits): New function to set cik_trait and IDENTIFIER_CP_INDEX 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 by IDENTIFIER_CP_INDEX. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 --- gcc/c-family/c-common.h | 5 -- gcc/cp/cp-objcp-common.cc | 8 +-- gcc/cp/cp-tree.h | 32 +++++++++--- gcc/cp/lex.cc | 34 ++++++++++++ gcc/cp/parser.cc | 105 +++++++++++++++++++++++--------------- 6 files changed, 126 insertions(+), 65 deletions(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index d175054dddb..0f1de44a348 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -560,13 +560,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 cb9b6f301d8..62d76c87cc0 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 9439c4dc744..ee88df5767b 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -565,6 +565,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)) @@ -578,10 +582,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index cb89d372b23..cbf280ec454 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1237,7 +1237,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 }; @@ -1282,9 +1282,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) \ @@ -1297,12 +1297,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) \ @@ -1386,16 +1392,26 @@ struct GTY (()) tree_argument_pack_select { int index; }; -/* The different kinds of traits that we encounter. */ - -enum cp_trait_kind -{ +/* The different kinds of traits that we encounter. The size is limited to + addr_space_t since a trait is looked up by IDENTIFIER_CP_INDEX. */ +enum cp_trait_kind : addr_space_t { #define DEFTRAIT(TCC, CODE, NAME, ARITY) \ CPTK_##CODE, #include "cp-trait.def" #undef DEFTRAIT }; +/* The trait type. */ +struct cp_trait { + const char *name; + cp_trait_kind kind; + short arity; + bool type; +}; + +/* The trait table indexed by cp_trait_kind. */ +extern const struct cp_trait cp_traits[]; + /* The types that we are processing. */ #define TRAIT_EXPR_TYPE1(NODE) \ (((struct tree_trait_expr *)TRAIT_EXPR_CHECK (NODE))->type1) diff --git a/gcc/cp/lex.cc b/gcc/cp/lex.cc index 64bcfb18196..a939e2e5f13 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); @@ -97,6 +98,19 @@ ovl_op_info_t ovl_op_info[2][OVL_OP_MAX] = unsigned char ovl_op_mapping[MAX_TREE_CODES]; unsigned char ovl_op_alternate[OVL_OP_MAX]; +/* The trait table, declared in cp-tree.h. */ +const cp_trait cp_traits[] = +{ +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + { NAME, CPTK_##CODE, ARITY, (TCC == tcc_type) }, +#include "cp-trait.def" +#undef DEFTRAIT +}; +/* The trait table cannot have more than 255 (addr_space_t) entries since + the index is retrieved through IDENTIFIER_CP_INDEX. */ +static_assert(ARRAY_SIZE (cp_traits) <= 255, + "cp_traits array cannot have more than 255 entries"); + /* Get the name of the kind of identifier T. */ const char * @@ -283,6 +297,25 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + + for (unsigned int i = 0; i < ARRAY_SIZE (cp_traits); ++i) + { + id = get_identifier (cp_traits[i].name); + IDENTIFIER_CP_INDEX (id) = cp_traits[i].kind; + set_identifier_kind (id, cik_trait); + } + + /* An alias for __is_same. */ + id = get_identifier ("__is_same_as"); + IDENTIFIER_CP_INDEX (id) = CPTK_IS_SAME; + set_identifier_kind (id, cik_trait); +} + static void init_cp_pragma (void) { @@ -324,6 +357,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 732d2a919eb..a416b58a2a5 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,6 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1173,12 +1179,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 @@ -1188,6 +1188,44 @@ 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) +{ + if (token->type == CPP_NAME && IDENTIFIER_TRAIT_P (token->u.value)) + return &cp_traits[IDENTIFIER_CP_INDEX (token->u.value)]; + + 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 @@ -1196,6 +1234,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); } @@ -2861,7 +2901,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 @@ -6055,12 +6095,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); @@ -6099,6 +6133,9 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: + if (const cp_trait* trait = cp_lexer_lookup_trait_expr (token)) + return cp_parser_trait (parser, trait); + /* FALLTHRU */ case CPP_SCOPE: case CPP_TEMPLATE_ID: case CPP_NESTED_NAME_SPECIFIER: @@ -11029,28 +11066,13 @@ 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; + const cp_trait_kind kind = trait->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); + const bool type = trait->type; /* Get location of initial token. */ location_t start_loc = cp_lexer_peek_token (parser->lexer)->location; @@ -20124,20 +20146,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 Thu Dec 7 05:32:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4572861vqy; Wed, 6 Dec 2023 21:40:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9D74bg/klF6Rs7AkAB934d5YKubua1m6Mcf2DiP0GBekQ4Ia2vKK37U6yaIdcEy4THLLh X-Received: by 2002:a05:6214:1394:b0:67b:e155:7bd4 with SMTP id pp20-20020a056214139400b0067be1557bd4mr2698742qvb.46.1701927637668; Wed, 06 Dec 2023 21:40:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927637; cv=pass; d=google.com; s=arc-20160816; b=D5YCBT9GUOif/OAgifOr/0vchP8syAJS6cQRUZJE3Xz2no3Ome2Ug0xbS4DbLABlDL pcyXUoGcmoG1fOlofxm7bDAU90/N4+7OPOS6Y3gklYxLZikdsM7j58ng+qF5jGVDrkHL yF3BR/xepzz7jY1lUhAPmwRL54OxKHFuqB5mQC8GFhrV69Gtvgxl4ZunALHYSRDM5eiR SZYaKlGFV3RnkrEX8b3pKYAP5qBCvpUncURASwLEOTYaeChLUGUHwAWeHEgqKzPiLkLF Ba3Q0Heqbqkpm9VKxRPSFFV9m1A791x78myglzXrnoN1ngM+Be8qjQiGAcatqsA5sHTU Eosw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=VLGxqNCskur56IICwk/tkzbJKHPMhrTmGC3XeAIdgwI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ZIAfgSKq8ZjW02he0omHvSFrLHVF0RwEjEv1FBctLZX/9fY0apdGlJhYZCRZggwZAO YE8FRY1oPs36XUckdORHh+8GE+WkLTf1UAo81tZUmzpuN1N5gTMRK80FOHiURxfh4Ea4 SK5h8VpGvdcvhlSTKuEcMme+fh0mYOqbKOlSgc39WNAg98/Vthr7r2EjgxjIP6fW1YbQ 5XaN8jl8pP3wtHjiNSYiD7zI4Z+LG6sCZQh0Y5YviMUTzLVKFFuGhOf1/nyG6WC2ItIN Vc08HxECWBCbuO/twicHFuBq1+xx6gvOqJ6cWcRX1ZQcEx2055gtU9daw8bbDQSpyrLB 7CZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TWf4UcnD; 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 n13-20020a056214008d00b0067a9759c23bsi584184qvr.254.2023.12.06.21.40.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:40:37 -0800 (PST) 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=TWf4UcnD; 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 61424385C400 for ; Thu, 7 Dec 2023 05:40:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61424385C400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927637; bh=VLGxqNCskur56IICwk/tkzbJKHPMhrTmGC3XeAIdgwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TWf4UcnD0AFgnZLwFRM7M6eItIIZC/QPZQwTewnwVF8IEx95ubiALRMCLo6K+lAwC BhGq+4doSdhEd/RY1LBtE/zToHpYQUSdWc1AkZI14WdFHA3KMUpqzcRDXkj+uPLvHr bL7l1EGvWkS0RdXQtHXUDplDOf9WIrP8k9MjaEPc= 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 B7E7F3857C4D; Thu, 7 Dec 2023 05:39:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7E7F3857C4D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B7E7F3857C4D 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=1701927596; cv=none; b=LNUFwVmBTadxIcWJ1v2fwcyhwMfYn1SSVhcBbSDyKbSdK5MsQ4IIrcqYOws1qsTVUw5Y8U5RZroON5zRA6W7gUdXgoOhKK/a8L1KrnK4QfQrPh8A56hEPMElKD+9v4OpxAFmWCDuMoMNi444Tt0+1MQ2jX+cOZAYGo2LDppfjfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927596; c=relaxed/simple; bh=Z2OBwP9PyfmVefR1khkSQmNCIgpRgRPLjggF0OtwFx8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZkKRm8RrvmjNf4l+EfAEu5DQ3KmwcTlOolL7UvnyyIFL5lkd4ge7dvslpunbKhMUjLryoS2BS1fDMzInk0YfacSl0QYTQzxON2rx6QpQRSIIsElBQ5rMlpM4gDp9+Ko4LOgl64QXRb/+iyLEhNvlbXxM96Pz75rD9pMoM8H9wwQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75SCkk005261; Thu, 7 Dec 2023 05:39:53 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu3dmhry6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:39:53 +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 3B75dU1Z005183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:39:30 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ4020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:39:30 -0800 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 v26 03/23] c++: Accept the use of built-in trait identifiers Date: Wed, 6 Dec 2023 21:32:58 -0800 Message-ID: <20231207053633.1001720-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 5PTnKZTEe6n-m3K2g3vmHYn9p0tUS6_k X-Proofpoint-ORIG-GUID: 5PTnKZTEe6n-m3K2g3vmHYn9p0tUS6_k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 clxscore=1034 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070000 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600751035871883 X-GMAIL-MSGID: 1784600474851751965 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 | 53 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a416b58a2a5..bf5add5cae9 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,12 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1188,15 +1188,29 @@ 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. */ +/* Peeks the corresponding built-in trait if the first token is + a built-in trait and the second token is either `(' or `<' depending + on the trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer) { - if (token->type == CPP_NAME && IDENTIFIER_TRAIT_P (token->u.value)) - return &cp_traits[IDENTIFIER_CP_INDEX (token->u.value)]; + const cp_token *token1 = cp_lexer_peek_token (lexer); + if (token1->type == CPP_NAME && IDENTIFIER_TRAIT_P (token1->u.value)) + { + const cp_trait &trait = cp_traits[IDENTIFIER_CP_INDEX (token1->u.value)]; + const bool is_pack_element = (trait.kind == CPTK_TYPE_PACK_ELEMENT); + + /* Check if the subsequent token is a `<' token to + __type_pack_element or is a `(' token to everything else. */ + const cp_token *token2 = cp_lexer_peek_nth_token (lexer, 2); + if (is_pack_element && token2->type != CPP_LESS) + return nullptr; + if (!is_pack_element && token2->type != CPP_OPEN_PAREN) + return nullptr; + return &trait; + } return nullptr; } @@ -1204,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_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer); if (trait && !trait->type) return trait; @@ -1217,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_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer); if (trait && trait->type) return trait; @@ -1233,9 +1247,10 @@ 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)) return true; + + token = cp_lexer_peek_token (lexer); return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6133,7 +6148,7 @@ cp_parser_primary_expression (cp_parser *parser, `::' as the beginning of a qualified-id, or the "operator" keyword. */ case CPP_NAME: - if (const cp_trait* trait = cp_lexer_lookup_trait_expr (token)) + if (const cp_trait* trait = cp_lexer_peek_trait_expr (parser->lexer)) return cp_parser_trait (parser, trait); /* FALLTHRU */ case CPP_SCOPE: @@ -20151,7 +20166,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); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Thu Dec 7 05:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4573005vqy; Wed, 6 Dec 2023 21:41:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM9V1EeE/2rIlyYbD7QJm2bJPKCPLP05+SIdQ1J7KEk32ifTVvgI5PshtswM5y6LXMkYZX X-Received: by 2002:a05:690c:e0a:b0:5d7:1941:ac2 with SMTP id cp10-20020a05690c0e0a00b005d719410ac2mr2108988ywb.93.1701927671509; Wed, 06 Dec 2023 21:41:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927671; cv=pass; d=google.com; s=arc-20160816; b=P/VpeCOKMmuqXQxl2WZMkj2k1yGGP6jKlDyvnjfI61HqFz9o56jbSPRxbCPuvC5Xa5 jm1HjMptg1Yu5sWVIaK0nAMkwEcUbWXORL+OD0OZHOfsKivS/1dKl7xuyPQYhTsT1pOV bRM+gQwgHEnOzyrC4kzALp1pO76CKM2aM6KyzLRh3coFush29s7h6+ph48C5a44XX32p GCdRUW0hyJW6mZTbBvF+DWWqYD75NpqGXT1PF0RuXE0lnwxVWJScBcnyUVPvH48V0VPT Mbg8kLTm/irg28DJvcZVZMV5uH0oCwVMQhbss+OOyOAf0whHiIJKtlJO7GZq0Z0SNGO7 WTGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=24cn14JMlg/2Ae0mj5tcgppmKyieQsCbofjV+3Q/uP0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=qVgxspz7obO90yH3k4+rLw2XDoOtwlfZBeP05lXt1wt3TjSNZwlFw3k1bQTnWdJE9p dv/8J5XplT7apx88Cm5q9H+yuRU3I3owqo6nKbhIRH8aJPZDkehyqC4OjddOi6/k8xB4 95Pss6FWJL2XtbN5wLz1BX/zo1TFKundYfOYJkv34Yh6x8RT5mwaIEfzhPkFRmvAMTFl rDyc4HIXr2ev8iVf2YIoSWyfk/9eqwhVetCk8wp2nAyVXzQXtJYe8d9xElcKlFJnrGlZ +iqresnC7wvtxLIrWYWREciPfQy2vZMnDrVHXB9ldripG+yLS5SvKODgFXRauby098ND z2oA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NIeobt44; 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 x25-20020a05620a0b5900b0077d859f0db8si536880qkg.763.2023.12.06.21.41.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:41:11 -0800 (PST) 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=NIeobt44; 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 4149B385AC38 for ; Thu, 7 Dec 2023 05:41:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4149B385AC38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927671; bh=24cn14JMlg/2Ae0mj5tcgppmKyieQsCbofjV+3Q/uP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NIeobt44hhhcrgv4EePyvGA6Y19CM76dLe3PI9EXOq37WARN8VXqv4G/Q7nBnVh4r 3JLXqUnTGQ55kDQ5mBbl+pzt/tF3+JfcLBclHGwy5yl6UpQqKYWu88xHJS+tzRZ3wB ITBWZF+pz8Iuv2dJQNEtWgaRKeHsFmdO65vxz9Xg= 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 9E173385C338; Thu, 7 Dec 2023 05:40:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E173385C338 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E173385C338 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=1701927629; cv=none; b=yCrHiashnWU047xOhWqA7/YEjvxQoDQ9DrEwnlH3WWLdjDccWJQqYbq1E8iMpwR6tmMGZJLAtHDt0BMDZ+L4fd/7z3gN8G1ipoO10CCzLlThaLGmmrpz7W+ArIuk5YaJLPlZ41/jWGVvZts2WnGg7k8MoFlDFlcQtRaWGgRVy9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927629; c=relaxed/simple; bh=PiSlsYRhdF8Hxl4770lMEPyNX39lhzlzHF5t/24F9JU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=p/dJqRsJcBcRDoivF5XkMk6klFvCe1EaICsuCuQD59IneHcZDZ+wai/CiZMQSNGbr2P4BWiTo55aqQ47yjva/ArKZ4HPyc4gNGLyAAr63RpPq8JhuNEho5wkWIVBNJDj+XHKOqoO6bEISEYJB+ZFs0Q4MP1P9XyemxQaDDORWYk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75dbdV011800; Thu, 7 Dec 2023 05:40:26 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu035uxrr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:40:26 +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 3B75eLQl031788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:40:22 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ5020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:40:21 -0800 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 v26 04/23] c++: Implement __is_array built-in trait Date: Wed, 6 Dec 2023 21:32:59 -0800 Message-ID: <20231207053633.1001720-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: wgxMU8hUHiU-s53pxg9TJzbE2iZI1Or5 X-Proofpoint-ORIG-GUID: wgxMU8hUHiU-s53pxg9TJzbE2iZI1Or5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 suspectscore=0 impostorscore=0 mlxlogscore=693 lowpriorityscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600843348346467 X-GMAIL-MSGID: 1784600510311761805 This patch implements built-in trait for std::is_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_array. * g++.dg/ext/is_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_array.C | 28 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 29aa7bb3df8..d75132e8e82 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3719,6 +3719,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 0e48e64b8dd..759f10a3532 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 3abbd6df983..aa551638a78 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12356,6 +12356,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); @@ -12583,6 +12586,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_ENUM: case CPTK_IS_SAME: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..6b9437f7c47 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Thu Dec 7 05:33:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4573335vqy; Wed, 6 Dec 2023 21:42:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvdhi3DyAFeSmZyH2IdGQvDzT53MBzcxT6G+ldaMyWIzhZKwyt+vjrtw499FhrJPYaoGW+ X-Received: by 2002:a05:6214:e87:b0:67a:a721:b1be with SMTP id hf7-20020a0562140e8700b0067aa721b1bemr2549627qvb.121.1701927765919; Wed, 06 Dec 2023 21:42:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927765; cv=pass; d=google.com; s=arc-20160816; b=QOfPN/DtgchcZYBFSHX0F3+8cGKqMskbH7gB8ycWhnevSB8Fe2NwGlH1Asrgxz3R1K S+m0yAMkowT1a6soN8ZZZPDz3ilh1iaDl48TlrInx45Z4apn1o6gkgxN41qZ3EpKgeUH bmVuUeYxQiUp5u4P7x4SrlxRUuSmWHOv5uSrRLOz7DOnxRGsPnRHqbkt2hzs0Blv3YZb LaujBw6qQGARgfOw9wWkF7qhK0LsO5G3wspGkaXROVPYyiVXJJJ5kGJoZhsOp5mCbKdr ohd2vDZJdv9q45b9tmx3RYTbV2cqWu6+mE0MwDXYUbpkNBSRL2FwN9TSBfDx8WPO6xol QBvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=b00NubKsReiaPFe9Tjq1VC19CXkRHigcSllSqW+dgXA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=AhhGVKfRZq5tNTUfHL/HJcIsf5eazjJui5Pq3j4pd6Ey6t9/CHXn1t/A0srowRLL/A Vr/FWwjlU3Ia3VLv1ytbsIU0F3utd7sQwHNvCZffIfItfPp1nxtzA8DACw+ImkxPAFGM qUdokAiJXDDXjnkUBqwizsdJz8TF4CUD9Vs31qxtUi+2kguM5lQDJkLqraqVDrX/KZ7g MML/xsM7oHvxjXHiI/A37+ZxELAX5pr6obieqdI2QNmkWtDOp1uFszrsfxRDJnB4N+ct jjnTbEyOly+tYbN7gnM6G6oYEv6ZBm9KZLwzEy9TM9N0/+Me6NkuKf1C0IroTvPwv6SK n4Yg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UzSA15CM; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e6-20020a0cd646000000b0067ab9afc26csi556919qvj.452.2023.12.06.21.42.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:42:45 -0800 (PST) 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=UzSA15CM; 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 A51E43857C40 for ; Thu, 7 Dec 2023 05:42:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A51E43857C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927765; bh=b00NubKsReiaPFe9Tjq1VC19CXkRHigcSllSqW+dgXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=UzSA15CMRMidmhx9VUgLYSGFBfMQfSxdsFQJ4u36hwIDospQpMf1cztJDVtFAxm4b 4yitwQCzf+p5YU/UHVpC8oBwWaaMMUX5fNewRMUGbtEmqQ0FjKQRgW+XDbDW1+tJ4b 1HP45t8Gfix2kgTrX0JSteNajOS3zEGN2YgokdFQ= 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 E4A583858C29; Thu, 7 Dec 2023 05:42:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4A583858C29 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E4A583858C29 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=1701927725; cv=none; b=b/ZL6wmz/WbTHMpVaL29yCBl+bCIpETTfcvVoH91nq101AmJl9onb9KmMVwwh4NgvCQ2iqKr9jYwhiTJQ0njp0Zayg9DZX0VYXMXGQNu1luMLjR2C/rl4GO1kBZBjI3fLlleUzYxe/efM6lj6YbdJ25Ig+5ft8cO2C/e3prny3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927725; c=relaxed/simple; bh=lJAtnC4L6cZ5qiADLRNu3O2bnpoIEA20TsGZscELKZ0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Br0HHKmUcN5lT6nJonHy5+REY1k+YKXiUhcJJvSFJdyvOmhK9fFsf0BuRu2Be2VE1BvpPX1bm6lmfce8IgmIp1XdSHu2lGkFvHTIEQlTDRtMRxjLHqjvCC3gt0eHhdgWt/r7gZambsg+HreIp59z0ekm/oQfCq8PrBa3mg6mT1w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75Y5Px010448; Thu, 7 Dec 2023 05:42:03 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu0y1u550-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:42:03 +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 3B75fsIM003817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:41:54 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ6020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:41:54 -0800 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 v26 05/23] libstdc++: Optimize std::is_array compilation performance Date: Wed, 6 Dec 2023 21:33:00 -0800 Message-ID: <20231207053633.1001720-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: USbUk3usQvMJOzsCwtiMNMPbfiURUatt X-Proofpoint-ORIG-GUID: USbUk3usQvMJOzsCwtiMNMPbfiURUatt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=386 impostorscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060160 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, T_SCC_BODY_TEXT_LINE 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: 1780601102679743632 X-GMAIL-MSGID: 1784600608924513712 This patch optimizes the compilation performance of std::is_array 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 677cd934b94..64f9d67fe29 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 @@ -3169,12 +3176,17 @@ template template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) +template + inline constexpr bool is_array_v = __is_array(_Tp); +#else template inline constexpr bool is_array_v = false; template inline constexpr bool is_array_v<_Tp[]> = true; template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#endif template inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; From patchwork Thu Dec 7 05:33:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4573630vqy; Wed, 6 Dec 2023 21:43:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEz2iWv4ordiMTz2PnI1WGoKz2dtbKn4GcUNQDjZj8J0x3sTlF4T2hny8ZQDF6YqqA8much X-Received: by 2002:a05:620a:6293:b0:77f:9c9:70cc with SMTP id ov19-20020a05620a629300b0077f09c970ccmr780202qkn.151.1701927831951; Wed, 06 Dec 2023 21:43:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927831; cv=pass; d=google.com; s=arc-20160816; b=rvKjQnb7rbmjlP606PU1CvG+UH0pVTy4cQF0/k3+sAW4xAjjkMYuZQ8tfU8YFGHfqW 3Ou45OFEd3EzdVJp34BqDZdExoLhJnUWZf8Jd0i8HTIHOJpNDkhst7uhs8poH6y2aEtw QeNtwIvmfBvbPc/aT2fbBjtgOANH0lrmK8IU3nqQHU2QPk5UPOCE8r4b5PEJ0UikeODS BuM/Ua2q+aPeCZqDxH4hKDMusmLVfmzSqe1ROeNPHE5VIHSU279vLFWUlBzDSXlELidf NEIDXIco3R/OvMG0Gjr6DxqlahpqjH5ewU20CgYBA/XU/4YzWJjvHazB0VBNhc3RoDQg sW5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=lzJ3oyndY2kGPGC8ZABt/7LufQuId+zQ3C9jo73cDg4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uJDgMCUEJXx+S6rvYF10jN1uOJ/u990L4dmtfw1pZN7HFQTTgXSr7RWhQTrdQMSbLY MWbJV3kP5TU3HpiPqSptjXIlSm0V7PMpDqQBH410MMlQbZkC4lV+eFAYcjIEDT7wlxLo lBIx/oc0B60zEgVNpRHMjiYNxtkW+YO3GXWMLbu2zKiL0SnRajqr8erSmUx6TlP3ZXfU za1B3l6FYcVlxCW3iTVpADCXP/qOEWjeREfWFUVm+TBu7g6RjKpW0CSl7lvldw7W3DZv LsRnUexkJjl6LA5SSoOhOdfW+TH8fBjRBThfyt1zrTPdnV9SPJvo/XR4P4Y0enxdT8ST GUow== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yAUgZJzL; 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 x25-20020a05620a0b5900b0077f080c53b9si559802qkg.478.2023.12.06.21.43.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:43:51 -0800 (PST) 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=yAUgZJzL; 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 A9BD43857831 for ; Thu, 7 Dec 2023 05:43:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9BD43857831 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927831; bh=lzJ3oyndY2kGPGC8ZABt/7LufQuId+zQ3C9jo73cDg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=yAUgZJzLZJW6ySEEiodZnllNZxOUCo8IsBeLS8xuNnUcAcbl0KF6aPlY1cZQhGxUJ cXkfpDLaHAMqI8fIk/4hkrIs7RFlevUE0Emd/YbinCfBrBnNz+/DExBQFeV2kloFgy b7qYxKluri+RDO8LJs+CKliC3h93gYFCZ+Ob+Zac= 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 E59793858C29; Thu, 7 Dec 2023 05:43:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E59793858C29 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E59793858C29 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=1701927790; cv=none; b=h74iJuyKvirOJ1HHOA7sSetuSQTjIXzyOrAgGtk2rDp2zv4GHxcZNE0xqDZvS210NpOhARetVobPkVlED/U/ueR9DWZ1e0n9Nbs67Oa1SPT+3fTLpxU5TfSSYwpmdxLQwrKMtD4/FWzZzDGudYVxdsLpbt+eNM5sAgiUM1qNSUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927790; c=relaxed/simple; bh=1HprCSwO8suNW51yZZf13l2g3kGQ3b/MMBFvqHlUVwk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QDFFcG5W32coMNYLuerjdj6u9tzfVgqaaEsswPAr21p4uNV/ZV5K90OynrTGBGCOLQ56By3QPw/afvWFvLFkDmIibw+Hdsfc18jepgoAqAjE/cTpMetrGJE6Y3FrszaxRcRflDrUILcuScjIUFFA6tppbHTw/wQ9c0FlvHir8fM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75SnYE029488; Thu, 7 Dec 2023 05:43:08 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu22cag8p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:43:07 +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 3B75gpRk032045 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:42:51 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ7020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:42:51 -0800 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 v26 06/23] c++: Implement __is_bounded_array built-in trait Date: Wed, 6 Dec 2023 21:33:01 -0800 Message-ID: <20231207053633.1001720-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 3cWjq1oTPLuZHbG5Iq37WwnsXMaFRuL7 X-Proofpoint-GUID: 3cWjq1oTPLuZHbG5Iq37WwnsXMaFRuL7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 mlxlogscore=520 clxscore=1034 impostorscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060165 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600968872603197 X-GMAIL-MSGID: 1784600678087664992 This patch implements built-in trait for std::is_bounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_bounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_BOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_bounded_array. * g++.dg/ext/is_bounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_bounded_array.C | 38 +++++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_bounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d75132e8e82..2311bab28c4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3728,6 +3728,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 759f10a3532..0e93e2b7114 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_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index aa551638a78..e3ea835a6b1 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12367,6 +12367,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); @@ -12587,6 +12590,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_ENUM: case CPTK_IS_SAME: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 6b9437f7c47..4cfb817788c 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Thu Dec 7 05:33:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4573876vqy; Wed, 6 Dec 2023 21:44:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp0Etl4/M9jjZ5WJnvzkucAZ+VLifh0mmcihsknlSS0vi+6AH9VJQjvUQsgpIXCcwIoW3r X-Received: by 2002:a05:620a:4141:b0:77f:31f5:ae52 with SMTP id k1-20020a05620a414100b0077f31f5ae52mr699744qko.123.1701927886335; Wed, 06 Dec 2023 21:44:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927886; cv=pass; d=google.com; s=arc-20160816; b=HwhiUxSsnX7yFZJwg+jBLbcKeqKeGDTxagutYeX+hBzwKEpGpDeHw0weoz0AjgO//h EXGDXgLDT+9n9KwBOludK915IhLCR85mThYxbahzDIiZySUbPcqs+/SwkFCG4rL90OtK u2qKjMMI0NxFU5pTqFZY6C6grGtep7iEixSfx/DBnaNVGvMY9ZYQ0V04Pqs041z5yCUB 0zoS7sEmHGwS8OltBHoc0ScrdwiHmfQeFgOoTvNNZhqz49XoG1IN5xT4eQ9cfIK7KDNe SLNJaGel9mThWx3HJ0HS0+HCNSu3d2uckX5r21oZ9WKQ805bdg0r+5NRJ4bUtCWOaXKM ykNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=Ay1o3ZMyWk4vaHADnOqas9k3t3XHD4YlQ3swchl8RVk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yPPEqI9x96nvO5KOq0YDI/rw5jUoQ0Q/BuGBOGrBX88iOKpei/lupC2DRM6+BAE9hu R/6ef7iTMjIi6z+5SlY0fUtrDjhmUJ5xAWbDWs6Fi9ImJDa/G135q2yoGZnARGjgzOzM vZgUoQYj5cDiFb2GYL6MRLT1NDAY+4KbmfrZaAgIAaaIHC7QvF/oUZaRWYhpGPSpnleA 9Wq8sgWJJUizSJzivnIPz2xemynhDP/n6CKrAY8+yCc71UJ/L5GGhWhwD2cTOlKEiBMK iAivXu8TZqxyvyqvWgrvePygXs3vVRzdQnIvMHSf7GBVUBHQX9UZaxdo3lzh1dTQajqb ZvOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=idiSxmbZ; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u7-20020a05620a0c4700b0077d87e2d618si596730qki.472.2023.12.06.21.44.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:44:46 -0800 (PST) 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=idiSxmbZ; 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 163EB385C311 for ; Thu, 7 Dec 2023 05:44:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 163EB385C311 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927886; bh=Ay1o3ZMyWk4vaHADnOqas9k3t3XHD4YlQ3swchl8RVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=idiSxmbZ8JzTmFwiQ2dmZtK9+qM2mxo+jHisCeTWeWAuEuBVr1n2P+snBqfSGfDXj LON0jZ2U3FQAsYNaVTTPNiVzlFMrejSycFaTRt6oR6/v2vd8b70qvC6w0/XE0u4qhS QCw0sC8/Dzk+6rZEy1IlBdid+kQ5/lpBPMxexfQs= 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 59D4F3857831; Thu, 7 Dec 2023 05:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59D4F3857831 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59D4F3857831 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=1701927844; cv=none; b=In0tpXPUqyvNJZlPnCo3umbJ0ZxY4SPIJZIBNHytLU/wpFcFNtrrZvhKVjJg7bq+EIyk/aYrrCyq7nKlBvAMzz5Lw32POjPOyxyNg8h6jGzffD4tcOoXrTcvB+mThlGM3b3C6NzGGG/HbB8YiGbx+e51oFbW2IuBfiX2E24DdE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927844; c=relaxed/simple; bh=3CfPjTAKxyc9dpgq0Q+FdtXBqjwVDCr3YZmWLJWtrnw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ocp4MA5+gTpkgZ8LIqHQu9m62NIwC0Er9IoL5O8OMIJIwGPIr+mhWXFelEBZBZzGPBCGUAXm4niXWoMokuaa/WQ80zO7anhNCMMw7efhkJ6FSIR0CryjIhs8NEm1U+fh1amX9ijyQaxYuq4026U890EKNNPj4hAa72K6iR8SwKA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247479.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75XtcX015887; Thu, 7 Dec 2023 05:44:03 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu3u49ne6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:44:02 +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 3B75hd5k032160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:43:39 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ8020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:43:39 -0800 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 v26 07/23] libstdc++: Optimize std::is_bounded_array compilation performance Date: Wed, 6 Dec 2023 21:33:02 -0800 Message-ID: <20231207053633.1001720-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: D2akZt-vjSxl7YflW_CwSR0Kjcq-YPFm X-Proofpoint-GUID: D2akZt-vjSxl7YflW_CwSR0Kjcq-YPFm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-07_03,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 mlxscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxlogscore=399 clxscore=1034 impostorscore=0 priorityscore=1501 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070043 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, T_SCC_BODY_TEXT_LINE 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: 1780601168542841525 X-GMAIL-MSGID: 1784600734912454249 This patch optimizes the compilation performance of std::is_bounded_array 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 64f9d67fe29..2a1a0aa80ff 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3506,11 +3506,16 @@ template /// True for a type that is an array of known bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array) + template + inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp); +# else template inline constexpr bool is_bounded_array_v = false; template inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true; +# endif /// True for a type that is an array of unknown bound. /// @ingroup variable_templates From patchwork Thu Dec 7 05:33:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4573950vqy; Wed, 6 Dec 2023 21:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHN2gIJEsQbag96DvVKso8WvI3rdDGz//BaUt3HIcmaSWTHxdGcsWcH84yuvBxF3yWZsgQu X-Received: by 2002:ac8:5c0c:0:b0:423:9f28:5eb4 with SMTP id i12-20020ac85c0c000000b004239f285eb4mr5637477qti.11.1701927902807; Wed, 06 Dec 2023 21:45:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927902; cv=pass; d=google.com; s=arc-20160816; b=JNeoey9TKyH8jYmiBwD2oRKO6GlWuRUG8Kkm+HbsWr6/tdO2KVxD2U5CXeSXFGBvg4 fiABBxgk2jfYKPJISOGUYXlFCw0OkCp+0XGTJGEaNe4diqNVPcXLsQva7z5sLDcd5Fui P9lnyopBj/CZV8bHIK8/3TC5/D5Sd88QZJdBq3BGurxVwHKq2SQDzPUXL5cTvbdgt5tN 1ODfh3N85FC+JRdL5GDGo7ACyEgu+uoYS8BfgRwj/ZgcgZGddpc9fIJznNkCWQZXa+Ix XLAO6e13YhzJnXmroGRgdGQL9/Wfz3k76JJwHmy5X759FLsq/GBzwt0O9kV2WtZOHXsD qQEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=VK51EMzmy/tKaoo64r2EwfOP9BXBTUpfD4tDLx5tFjE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=AtKddH19VQzaSqOyNvyZMQKRbpQNnIhyDGOavY6F57sCnwucUc4qukq7I+aSw3yXfV SvkmYwtWapjE+CUF+7fe7v9EspeCRB6apB0aOzaFU0DFcNIiQpMLz0V6KY4m4MMXigZ/ Pbn4tjOKZwnIcDn6HKrZMwZBMmV9lS3OxTTh0LeV/ENvLa7ZIZXEd5M6qjUAeek7DBNz sOG5RCHem/Y5QaqRetZaF3eIeGbjnoS1QvP5LNEdrudPGYMg9wZVcGF9z7Vp9aHpfug0 5stSw0Wstnwu3OJRgM61EdbWu3wTzcCW+K7nSXuby3bVHsyYFQOm+oF/7rHA/tmfoYNn GvqA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="epR1Z/VN"; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jr17-20020a05622a801100b0042550af1234si591055qtb.373.2023.12.06.21.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:45:02 -0800 (PST) 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="epR1Z/VN"; 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 89A3D385AC3B for ; Thu, 7 Dec 2023 05:45:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89A3D385AC3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927902; bh=VK51EMzmy/tKaoo64r2EwfOP9BXBTUpfD4tDLx5tFjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=epR1Z/VN4ec7juDITjK0YvwRTKf0/MC5ZXvFr4/a3bfwoBTb9jCLZFMLiLMArE3SW V8Dnh0Q9sA3SeLckqm5JMwNGhHNOtg+8MU9NaXXXZXSF0Emr/CfumVbx5Bd5sC/TzB C1ik4g44zl0ttYXq+wWIQFPYknj8HBL2bwXC47g8= 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 0F728385B530; Thu, 7 Dec 2023 05:44:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F728385B530 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0F728385B530 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=1701927861; cv=none; b=jPlyBPlCnZT7C3bOyvO0/lkzWb0TrJ0ujrPBkWCzXTR0q8yLXHAfC63oxMsSbNobRmqhqJP9JV4bmXVQuAeNRgt5Jx0m3EPHU9tjC47oPJCnZp+JgELNVfYj6dXMtzWH8xJCqng/ZvKVFixJxE7TK5pht8rp653Gh7rf/smB+T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927861; c=relaxed/simple; bh=QNOs4q2lqqLhI4BEFrMhqBQklnQ8uEHS1WuOqGvBfc0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PO71q4LaBHgThO3mSNrYdL2o0IPRmy4HiCjCu+H2g42bwjDBzQgJkmpmty+TFCw2jWltwSqDu0s0gRlzF8NJVSkCkYloqilcH/qzPJ5KSwO315wfwOHkugwBL0doEdxqnoLZvbAZg7Lm8n8tIPLeP4z0DYwRN+eZAUrXQzFdTZM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247481.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75fJCa019504; Thu, 7 Dec 2023 05:44:19 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uty6dv9yv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:44:19 +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 3B75iEIO008724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:44:14 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQ9020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:44:14 -0800 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 v26 08/23] c++: Implement __is_scoped_enum built-in trait Date: Wed, 6 Dec 2023 21:33:03 -0800 Message-ID: <20231207053633.1001720-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: T5BPJjcaHcGwXjvinY0wQcWiHe7svrA- X-Proofpoint-GUID: T5BPJjcaHcGwXjvinY0wQcWiHe7svrA- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=749 clxscore=1034 spamscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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, T_SCC_BODY_TEXT_LINE 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: 1780601678277733646 X-GMAIL-MSGID: 1784600752740055325 This patch implements built-in trait for std::is_scoped_enum. gcc/cp/ChangeLog: * cp-trait.def: Define __is_scoped_enum. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SCOPED_ENUM. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_scoped_enum. * g++.dg/ext/is_scoped_enum.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 + gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 + gcc/testsuite/g++.dg/ext/is_scoped_enum.C | 67 +++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_scoped_enum.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 2311bab28c4..062dc404ccf 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3783,6 +3783,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 0e93e2b7114..9d848f6f77d 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -78,6 +78,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index e3ea835a6b1..ea85da3b41a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12415,6 +12415,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); @@ -12594,6 +12597,7 @@ 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_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNION: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4cfb817788c..744cfb3b42f 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -116,6 +116,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Thu Dec 7 05:33:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4574142vqy; Wed, 6 Dec 2023 21:45:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY8venrOKeTqdTuFMAZAaeGTG2uVEC08RHOuZVF6G5eN61X8HpoweJ3HHQKNbVegCPR6Gt X-Received: by 2002:a05:622a:3c8:b0:425:4043:18a1 with SMTP id k8-20020a05622a03c800b00425404318a1mr2862464qtx.84.1701927950787; Wed, 06 Dec 2023 21:45:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701927950; cv=pass; d=google.com; s=arc-20160816; b=OfoXHs7yoWT6rBpEOYFGVH4tQIA/O61l1m4VbU419xZI5plEGTTIKh9Y2VqtdCq/nN WnIAGtIjAlp8bWrt1YLSdXc0Tepp/tKRJJkeeX6QFiE8YmsOgn5qbuZjAXK/TOx1f0aA 6MTWWzg+O4mXB+KPd9yNfwkKsHsYHma/XXbUCpV5YWEYtlDpl6pPqZczr58z19cFJw/9 hbHz1R96Tc8Yomfaau0QIKwFe+6a58Msldb7RG4n3hb6B7gfK2Su8u1CEu21OUzVQiUW tZqMX8RIqhWWP3UYaltYv7XBzmWIdHh9iMFCV0YuP73yH65hUqfmdSLCJXZJKBrYUCZe 3Rmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ZneT6SXH05OMxm3tHIquPmgC3m04vrMHO4EAmh1RQDI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=wDy86qqr6MrFCI9OK8mYyuJSDON0CtMEL2vll3h5geh6episL9VUAwuWso58ftTj82 S4RbwPwAN9MmclKFIUq3QlwVO7nUnUT+h/ue5lYvCfsRnZHUH25DyLarJ7f8hVLdMq4Z WVTm1H56UrtQwvZ0UMDQikCul3g8R8wVkO3kjKiEIR4oMyFxJHO5RkkALzYxxqsqbXf9 VgktDOx71W7CQ2XPWUc7j43wOXbrOa6ioNAuUILgpBfCN4N6vH8S8l3RXZYGcqno6E5c HxYmR3B9SrUMmMTZZGEnmD90fUEYW7ldEsq9uIKFJXhxQluz6x9EY25uh1GpmmRS/bn2 nRfg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uawNlKdK; 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 cf22-20020a05622a401600b0042552f02547si674732qtb.240.2023.12.06.21.45.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:45:50 -0800 (PST) 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=uawNlKdK; 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 8577E3857400 for ; Thu, 7 Dec 2023 05:45:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8577E3857400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701927950; bh=ZneT6SXH05OMxm3tHIquPmgC3m04vrMHO4EAmh1RQDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uawNlKdK8tIj9rDNpB8w+iYd0su7ep1JE7w8vySgo5caUcWVGPLD0zFKFmKURuHGI Sp+LLv1ynWIyDx+BKXXmgKsb80YU+t9gbkftO2VikPQbbLzsX7r45RUkDNKiHPVN/7 Gc5uUw9/A5opyTfwQlpnLVi3RQ6cAQCqvfcBNF2Q= 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 34AB5385B522; Thu, 7 Dec 2023 05:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34AB5385B522 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 34AB5385B522 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=1701927910; cv=none; b=YIPemgyRYckjejke7IdcFuaGhyuCmKebrDeVc0pBKMRyOy8gw7fHX8mvbx5Prf+yB2lcpoPQzECIvsOtPD07b/1vSsEDQzn9djzfPG7D5UOdu7wqTmP/xMx0rydxryqDYgb/vrE+hlsAeexe5pzXcqF2xECgmHvz6BSE1ha5scA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927910; c=relaxed/simple; bh=bt2u5sC5TCWxnvMOAx5CAjGPc4bV3RZfiQsjg6wg8Ks=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=P7lAWnRUDQZkXo9M+Rn2k69dzkmepWyJxXavTWAO+wtCrdsedAUwd/yteJ3pZ94VQBE0CCmwLi27lYXMhlGFpZsckEzX+Ib+zQnpkq0aoFw+HyieD8dk8tSH8undVAMc6IdaW9nvhZlRkst1+vwduth20JsVBxk+IDFpvLhtcAA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75dlGJ011905; Thu, 7 Dec 2023 05:45:08 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu035uyhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:45:08 +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 3B75id3r015721 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:44:39 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQA020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:44:39 -0800 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 v26 09/23] libstdc++: Optimize std::is_scoped_enum compilation performance Date: Wed, 6 Dec 2023 21:33:04 -0800 Message-ID: <20231207053633.1001720-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: xC5sR_rk3g2JSCSd8zFTidqupsLB7Icq X-Proofpoint-ORIG-GUID: xC5sR_rk3g2JSCSd8zFTidqupsLB7Icq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 suspectscore=0 impostorscore=0 mlxlogscore=794 lowpriorityscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601238448506991 X-GMAIL-MSGID: 1784600802742891173 This patch optimizes the compilation performance of std::is_scoped_enum 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 2a1a0aa80ff..4a5068791af 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3602,6 +3602,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 @@ -3613,11 +3619,17 @@ template struct is_scoped_enum<_Tp> : bool_constant { }; +# endif /// @ingroup variable_templates /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp); +# else template inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value; +# endif #endif #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp From patchwork Thu Dec 7 05:33:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4574367vqy; Wed, 6 Dec 2023 21:46:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWf8IvnoHg8+XZw0mKKf72DNIeKJadGsdjUe579LPOXIK9jaTj1lDMDfmFjk3asOyJnq6U X-Received: by 2002:ae9:e40c:0:b0:77d:7a49:8933 with SMTP id q12-20020ae9e40c000000b0077d7a498933mr731540qkc.36.1701928008589; Wed, 06 Dec 2023 21:46:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928008; cv=pass; d=google.com; s=arc-20160816; b=k5WjKFGDSjRoPb5Y0d1P+kXZcY4YjbOWXO5POEMHbzpT5MLPJc6ufcBywdu/fDLmlp IGLUcglZ1+dekcMnN/DOGW8KapSfnsufkwbahh4ERenMNgk5RAUQ5LoVbqwRVQlARlCP 3rNAa41lBHo3YHhdgkF1JkpRK38Ir8HU15PkuUpMtmjZ5qYSMaZaqXXSPyXhwSUUq7dC kt/hOsvoSjtr88X1UsQLEM4uiemWhaH/FziuU+yTlvjYMmD55x0huBdSCnW6oHZmUJPs ubNO2mSZ0T9DmWXAU5IV0GHLKrw9bZ0GqbuR73Q/ovEBIaRbP0B0qZFxqXS2qQ+qAyYa hwJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=zm4TG7p+iIu8Od8xvS8zOkbQ0eCFQ541uU4xFaGVIPY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=sMYfZfbcSkyVPdJXBdzd+D8SjM2kowUmyZglMG+AhIcotfvghGgrHVMH/fa7qF1z+B O9lGK3hMNv/dxfW/akvMn35y8MB31hqEHG1RiS84UCOclIKVYFXuCuxLWzF3k9IAoRhi 2ZSyvFjLOmCXXBBNOqLthKc+lpUoSl+axwMHFl2xXBse0zFD7i8n7evh/gmUBZerkGbK P/QjeuSVTzDElJ7T+gi1z9sVhdKQHjWcO8x1c5u9QGBWIUCrVanjvqr3FUwJq08HZeke TjCDhXb9HAJijGsr7+cy2G7Njx+WHFpIDxTcYpQRsYURpSx2gs0u1SDuG+DmWxbEQQ0p 7JHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dQTOMLnq; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e12-20020a05620a208c00b0077da5e25a3fsi556894qka.618.2023.12.06.21.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:46:48 -0800 (PST) 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=dQTOMLnq; 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 50955385C413 for ; Thu, 7 Dec 2023 05:46:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50955385C413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928008; bh=zm4TG7p+iIu8Od8xvS8zOkbQ0eCFQ541uU4xFaGVIPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dQTOMLnqixpjgv3J2uLk3u/xeImpnoLzvdENLcFKGbqxIg16GXL1Bq0kw5/r2QeVc AyVN9RQ/qdZVyVdIh7WcPurgSAgNYpIO2FkuGbEMkw7NeP1THLQSaoKkWe0WhfEeq4 kCvZNp1STrM6LoSt6iLb4+CqY6wpvoWXWqSJsbSA= 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 F213F385C306; Thu, 7 Dec 2023 05:46:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F213F385C306 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F213F385C306 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=1701927967; cv=none; b=i622zJ9f7hCVM9Nes9jJOhKPdkKpO+XCz8CLuKq+XFO+5+qDUa0LyCItP9VUZWU7U0DY6CH4dvv9+TbMipa8gdzPgUkYl0f50AHloupOgYPudqxqPjXWf8ZypPAXJ6JAn6f2gNG0W9xC/SesBibL7D3Nl8dLXCZPlz0jGsBmDMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927967; c=relaxed/simple; bh=5xCBbMdo3dAnG//NGqmlK/J9WBLJOyrTW4X0HqOq2tQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tzjeTMWdZTOxPw+bDlaFBQErL2qQFz9m8PFTrkjwA522IKvu8U27v0cpDkgaFcYnex2cs4lXf3Gvq+/WMZV/4jfRcbOSAaSzc7GCZCRfRwiHvnGu6ViXrIYHRav9hJzN0iayWUs4Os7JFyjVJhGFxMkoZSROW3Y1bxFj0iLiZpI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75fB3r028477; Thu, 7 Dec 2023 05:46:05 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu3dmhsx0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:46:04 +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 3B75jjER010911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:45:45 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQB020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:45:45 -0800 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 v26 10/23] c++: Implement __is_member_pointer built-in trait Date: Wed, 6 Dec 2023 21:33:05 -0800 Message-ID: <20231207053633.1001720-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: x_Xok_Uzfyc69wcI0CaY4w6rPA6yT0eq X-Proofpoint-ORIG-GUID: x_Xok_Uzfyc69wcI0CaY4w6rPA6yT0eq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 mlxlogscore=814 malwarescore=0 adultscore=0 clxscore=1034 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070000 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601423962986500 X-GMAIL-MSGID: 1784600863194633225 This patch implements built-in trait for std::is_member_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_pointer. * g++.dg/ext/is_member_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_member_pointer.C | 30 ++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 062dc404ccf..fb150e02ea9 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3758,6 +3758,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 9d848f6f77d..e17f5eaeac4 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -71,6 +71,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index ea85da3b41a..050808b96b9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12394,6 +12394,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); @@ -12596,6 +12599,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: 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 744cfb3b42f..349fae7104e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -92,6 +92,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Thu Dec 7 05:33:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4574513vqy; Wed, 6 Dec 2023 21:47:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEdBel+cfBM/gQv1hzbZp+yedQKedQZLoNxWUqI3jTJ6Oh4WVzWJXE+KnnJ4qrC6/wa2Xd X-Received: by 2002:a81:f20d:0:b0:5d9:b970:b8de with SMTP id i13-20020a81f20d000000b005d9b970b8demr1772086ywm.95.1701928039354; Wed, 06 Dec 2023 21:47:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928039; cv=pass; d=google.com; s=arc-20160816; b=yhfdyP/Uoc+6U9TSqEJ4F9PvFrW5bZBhSV9ClOI8pMCIioj4ZbsyEqnmkTOO3vb2la G2yAC5g1HPRX7JskEIlHYInLkWHlERs4U6LbCmKadbos88m8N/dqs4TGtd1MbtVGEcCv K1JR372uLL7NOd+Nk+wDQBMmM6gmV6AcMD4p1Q2BASr4gHSx93AeCfVVkkKn4EduiqwT Dzmg1IaKTNA8MutpekR3TTJ7afFBFdEIrfT4jo3wYb1oEQKcl1Bc0PREj/oRrjL0IDez glUoTJT+O0JxFNcZGZPT9CZ3WDUBN1Lz+Ln/0tr2nhZbEXOJkW3gW3LFoQZ/UsV1RG/S Oapg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=1CSeJSegMbLd3OiBF5i5KaXrfKqK4vUdQ93cL4kHl/c=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Pw/tvSg5sHjIbSHaCbTWCiWOsWRK1ik9z5Qv1fB7fhvRe97+ewPljsUtbD24sP0MPE 5W/nr2qXwOilZOi5aDrxJ801J/+rQP/C0sT66qo+j7EEaZQmdD6OtdFN5XoSiKo777J9 9o0J+2n6KzNHwIuLwxSlJNfrL9gFw0EJMb9tAwNA+Z2W9hcl8kQHxbZ0KNfjE2X/H4Ah ZN72uxwO0Pr/iUicTnIqS39JZ6fT/5koDSEM+/dq0rLw3qFbpZt7NwDgI6XXBEOZQixk buSJ73EUoG0R2Fr4jXQG59LOohF1y1VwWEJUUfMSXrs2ldC9TcVJpBLrv8eGznkWwsdM GpBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wUmEn36f; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c25-20020a056214071900b0067abd470accsi567297qvz.554.2023.12.06.21.47.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:47:19 -0800 (PST) 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=wUmEn36f; 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 1C7D1385BADA for ; Thu, 7 Dec 2023 05:47:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C7D1385BADA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928039; bh=1CSeJSegMbLd3OiBF5i5KaXrfKqK4vUdQ93cL4kHl/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=wUmEn36fMyDPeT6IAk+/CP4l3SPwpelOpul22+69oDyK8ZJhFXRAijuMf9rjvT9r9 2CbjXk84khVtKZ7uJxvE3fF9CfzUcSm3jZyq3P85/QSbjkh5lVUK1JRfsKvM50cqvB o2sBzVligOdk7v0o2Wv3S2c83TFuYCxw54ot64JQ= 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 31B88385C420; Thu, 7 Dec 2023 05:46:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31B88385C420 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 31B88385C420 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=1701927998; cv=none; b=o98qbDogsy97fx1JZzXOvwEUcP/b1pUhucYWAALBDBqRxH6zdeh8VDJpsslKjQZohtGJOmcGDrSq5dFCjzpXytBpbqAOFCs3HeZP/gz0lSxGKmrmhwx8lifezNoNQ1tyZncnvA5tsuKOSTIXr54+h5Hj7CfSwOOs/MrDwrt1Rrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701927998; c=relaxed/simple; bh=6NWmxjXw8bxhGCLFT6N7wdF6NIh9tdHcWIMJ/xhpmJw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dRmRGArNn9hrZuT7e0TD8VQ9qFORgczw4Z0XomwVUMn3p+xxP0CBhAP1sYoHfBWGbvEGkoIxasr3LTVHaPJpsjYpm6qO+HHUuu6B6GCjrnw7qLHOzQvXW+1z3fm6W5LZKYn6Ko45UH7SYCnTevIE3AdCcFzqlOEEYAOcn4nwHMo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75kYLP024234; Thu, 7 Dec 2023 05:46:36 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3utyjhc113-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:46:36 +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 3B75kFLS011050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:46:16 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQC020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:46:15 -0800 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 v26 11/23] libstdc++: Optimize std::is_member_pointer compilation performance Date: Wed, 6 Dec 2023 21:33:06 -0800 Message-ID: <20231207053633.1001720-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: aH9CZ7g__H8MkoCHt2jOPymbVW-Poopz X-Proofpoint-GUID: aH9CZ7g__H8MkoCHt2jOPymbVW-Poopz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-07_03,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 bulkscore=0 clxscore=1034 malwarescore=0 mlxlogscore=525 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070043 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, T_SCC_BODY_TEXT_LINE 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: 1780601103665571273 X-GMAIL-MSGID: 1784600895602269585 This patch optimizes the compilation performance of std::is_member_pointer 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4a5068791af..4ab1d29ff51 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; @@ -3228,8 +3235,15 @@ 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 + template inline constexpr bool is_const_v = false; template From patchwork Thu Dec 7 05:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4574729vqy; Wed, 6 Dec 2023 21:48:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvj47IRuwcfH2Xrno9D1Jy2WSAo7BuOphbLbqquu8Ole/zDwZbYVz6B+72gXs3JFjeg2o+ X-Received: by 2002:a05:622a:5cd:b0:423:7f74:2126 with SMTP id d13-20020a05622a05cd00b004237f742126mr2821866qtb.45.1701928096055; Wed, 06 Dec 2023 21:48:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928096; cv=pass; d=google.com; s=arc-20160816; b=G2Lx8Rn/aEiBZxp69Gs0eSjjUHwWbjHkQuf68+2JUDZK0XQpba1mKwURA6lsO1XdII UsR7ab7pFY43RWrsleR4HMvBX+wDmewLjsFgUL/sCyFo7IwQPK5XL1sgTff9J3RUXbXj XYxdlEcF4g3/6qKg8BzboSi3nG2rM4Id33L2lqCbR6OeS0XsPAokK/AzM8RycRU7w8C6 XX5kQcJDRWNrNw2hifO07Y65c7iJEmWfjEa17g0/0h9AWDft7XGgoSPlx/BwD4oO8pOx fpb1awSFi6n6E6oml1DGGndb6kiqVxR+QuC1/fA2Lp6erd+qD+1Fe5FMPLXSxUlkQRBf 5prA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=mkGAZWgag8m3wiAUMJZg4e3238cxRNEr8suzSpe86bY=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=r5S3SAmsi6S8XtsQrqq+vE/T8yYoQKRTj5UEP/gCyupvo76PwIU6zP3zwNeYY38eNg F20snRJVdJMRX4wUILn7SO00N32D8uWs+4NPbSetwcqE0tJHIlbnZWkGlBS9kDCt+mTU H8RY8s09ruwRbO1/qijov9Pg8rLjC1z7VnoHwXHquaxu6QUzLrhd2AuVxDl1+uYcfuNm u4a/IK24b05NHtuscYf1IJNE6dotHsZEZ08GAWg7GcgP0n3kxvfASUGG6FpInxSHlj8z RFnRm4atnKzF9KuuYL0dMSHMIUOUTmZ1O1eXoEH0lW6azMnOrs6fm+J4bv0Rf/E+ReGG lLdQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gy+af3VO; 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 d4-20020ac86684000000b00423f2f520a4si606085qtp.801.2023.12.06.21.48.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:48:16 -0800 (PST) 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=gy+af3VO; 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 C525C385BADA for ; Thu, 7 Dec 2023 05:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C525C385BADA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928095; bh=mkGAZWgag8m3wiAUMJZg4e3238cxRNEr8suzSpe86bY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gy+af3VO+d4F0EaadCMwyiK6svNzWDV+V8Fpn9+6ZWKN/98zpr+Fcg5+fn+AjBSbZ Q2nVTjAWXDKyE2MqoCKZBwHzxaaBaMGLpcwGBaye0NS590lg7XeHyjWVafdmmaLfaz seTwAwmn9JbCNVa2aoQE8csDT5s28OEbPtFjNvqQ= 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 57F51385C405; Thu, 7 Dec 2023 05:47:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57F51385C405 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 57F51385C405 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=1701928051; cv=none; b=dsT6cri/ndeAKnoS6Vn+e+Fdsyjtotp80RKxJBSAxmNj6uPuldB8c9pz506PZSjVPa+d/ah5tSM2EFBOS6qkEYQLtWb1YXhtWDt+xLxpAYenJglQhdtyWxE0c/m5f+ChQPC/ctvIZ4165RGN3yqV2x+JFtFEJQ7NsGlYa3NLsyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928051; c=relaxed/simple; bh=agiJs61847A2stMySp/NCK1KezRrrEhv9YobJELY54A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=AUA8E9iuFN9wr4nHDL1LJkDAkO1qvhM+IaTYCpeCVjDabwDjzjTsUx6bWLFG+Y3oisBomcOfBLP4aMPZLTxuJmejhCXewfwuUe2tWaQdYP6qRKUCFKAZIPIGR1xVcBz8AwvabGUZlF3kLIpA217AsN9ECC+8oUDuSWYoRgyB56Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75fB3x028477; Thu, 7 Dec 2023 05:47:29 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu3dmht46-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:47:29 +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 3B75lKhK009151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:47:20 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQD020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:47:19 -0800 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 v26 12/23] c++: Implement __is_member_function_pointer built-in trait Date: Wed, 6 Dec 2023 21:33:07 -0800 Message-ID: <20231207053633.1001720-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yeGePa_dh-CXJVN-LDwc6_0uyTuhMh-4 X-Proofpoint-ORIG-GUID: yeGePa_dh-CXJVN-LDwc6_0uyTuhMh-4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 mlxlogscore=865 malwarescore=0 adultscore=0 clxscore=1034 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070000 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601549305511704 X-GMAIL-MSGID: 1784600955084917602 This patch implements built-in trait for std::is_member_function_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_function_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_FUNCTION_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_function_pointer. * g++.dg/ext/is_member_function_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ .../g++.dg/ext/is_member_function_pointer.C | 31 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_function_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index fb150e02ea9..1efc7983039 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3758,6 +3758,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 e17f5eaeac4..03a5cc28020 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -71,6 +71,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 050808b96b9..eefce24ac2c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12394,6 +12394,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); @@ -12599,6 +12602,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: 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 349fae7104e..fb17680d3b0 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -92,6 +92,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Thu Dec 7 05:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4574974vqy; Wed, 6 Dec 2023 21:49:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IED97UVufZS3meIVbWNmWGshTuGm3uywG08nUvPFliW3cyIKABwVvSfkwKxN3UdNHapye+P X-Received: by 2002:a0c:f6cc:0:b0:67a:a721:9ea1 with SMTP id d12-20020a0cf6cc000000b0067aa7219ea1mr2070990qvo.82.1701928151911; Wed, 06 Dec 2023 21:49:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928151; cv=pass; d=google.com; s=arc-20160816; b=BesOC0AMKlSepEPyQwxGhS33Rya+b4yeK5aNsT0MwRR9tGQi7l31jBSrg0scYPanYA YXunT/5adEIENPAULIrCULL57MLsrEK1CF98Nb6f5djPyLdi0mpdlg9gHO79akK5NqzZ zgVZlQcRmODME5KeoqUx18cVNUNW/4KRCSUBgAkw/IEralA8evYM4fzXUTHnlIt4N1zs VsQI7PWqQaYxNuqg04lVP0RBDwCgQQQiSfOxWObWowygmmNRdqdfvSFRRqsUsMlKapwQ FUumFG+eGq78Q+yZbsNsGKbodUlRwOVMOL/qLlZlvFiSu/2FpIvbAeqEJyyzd1sgmzG8 eWMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=F54EgXl5Fp5Dpyj0daY5r7cFQmA6yt0dIlXWTglM4hA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=dyTDO2zuarp175i9BYcOXMnWP08GW5kj/JvXX2Mr7Q9oSfEHNEbrcIX44zmo/wi9vZ XYVyWVSwk58uYpdU6g8jzzvJ3A1p6MYZkAg1yhWLrD2bSDZBlyVl2pX2K4QPEveWKGRg Riry2+pAZMVROwMKcL60XfPZGzmibAFGgi8iLBPTxw1ZaSgntfcIvjeEd6y3AsA3bKCN CUAUckAjb8ugN6glR6tYZ6ubya9qV1f/c1KTE3dLcD6PFlqI6xGNbf5Ykykaf8PAR/Rf akVGxMG3jQcMQ/bLuCtGV8smYOyZ5DMc7as8/0YJUOHPPw8XuCblf+uc4wsiz4dQ7vF9 HZuw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jrZyuC1X; 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 l12-20020ad4452c000000b0067aa7681feesi546065qvu.616.2023.12.06.21.49.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:49:11 -0800 (PST) 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=jrZyuC1X; 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 8C361385C335 for ; Thu, 7 Dec 2023 05:49:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C361385C335 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928151; bh=F54EgXl5Fp5Dpyj0daY5r7cFQmA6yt0dIlXWTglM4hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jrZyuC1XJzSmibSEhBFree2FRM7LW6Jt6pN0ng82+r1lbv0H4Yj5Sdvpch1CsMl3E c/wa1+PQq/yuIEhTyDAPIVg7HnbDyphFFLo/H8Nss9U5g3Z1gxpr+/BT6nY62jcOP9 C5uUqJNXPcTJu8etWKMODCFMhGORdIV4v41m8xho= 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 4EB88385C400; Thu, 7 Dec 2023 05:48:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EB88385C400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4EB88385C400 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=1701928103; cv=none; b=XAVC4N7mK4lQVnDM2UtmYCs4R+jqAyY7SdxlcZ9jrco/92ugfJNGrK+75U0R3VNJXxau7x86CUzGrZ2J4cgHYHuZ9kQT5HD6spJoS7fbu623lzrRgs/+jQVrJVBYH5b5W13ZccpAh7MzVPJugDv9HowXpZIMRd8mpleAocAqS9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928103; c=relaxed/simple; bh=uHo3oXqxsFkiR/8HR/VKygryAaeuvL2o90EcvkfRtZg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GwdGpmB7iOVZFoPyFQtkLhmlgJUdXm8jCEG0vVeGXUg2KR0VaSoGXygjAnUW1QuJVGCbi2AYGhZ6KXfKidmNSHwTwaFcTJxQQhEFYGmOANOEb3xarNNdFddybirtPlhK5Ne2YG49h1exwue7Qpg2t103YZiEW7NO+YYK0BS8iBw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247472.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75iLXN030156; Thu, 7 Dec 2023 05:48:21 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu831r1q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:48:21 +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 3B75m2oH004957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:48:02 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQE020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:48:02 -0800 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 v26 13/23] libstdc++: Optimize std::is_member_function_pointer compilation performance Date: Wed, 6 Dec 2023 21:33:08 -0800 Message-ID: <20231207053633.1001720-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -2zN8CR0_N9q6Qjo0wzROUMJtT5wfOpU X-Proofpoint-ORIG-GUID: -2zN8CR0_N9q6Qjo0wzROUMJtT5wfOpU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1034 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 mlxlogscore=452 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070040 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600954817613804 X-GMAIL-MSGID: 1784601013770100737 This patch optimizes the compilation performance of std::is_member_function_pointer 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 4ab1d29ff51..99ae825301c 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 @@ -3208,9 +3216,17 @@ template template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) +template + inline constexpr bool is_member_function_pointer_v = + __is_member_function_pointer(_Tp); +#else template inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; +#endif + template inline constexpr bool is_enum_v = __is_enum(_Tp); template From patchwork Thu Dec 7 05:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4575189vqy; Wed, 6 Dec 2023 21:50:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFB+zl14F1UqkBjp4q5ceABodkJfqiqYFn5tNaX30JweVezSWF8NdK+6EhJvKDE4e+GmWQD X-Received: by 2002:ac8:7d50:0:b0:425:4043:50d9 with SMTP id h16-20020ac87d50000000b00425404350d9mr2408913qtb.104.1701928201241; Wed, 06 Dec 2023 21:50:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928201; cv=pass; d=google.com; s=arc-20160816; b=ijhljdBrAp07lAphJv9yw3KrwyyyoaKcfYvX+bRq7tYhU84wONYpPT1FAkGsqe6mpO 8eMOWYeYnqs2mcahK2vUJ6NhxY4gIT2SKE0NlslnlhDhYxIo/yO0pJrwoNv+iJ2jbAdL duxEqPSHe5T+K8IFk3HaDL8gCjGNKAi/JZjMBhfSZH8DQJqTqh4y3AnRUQTRrOQwSb0q xAoeRL0BJNRFVvgkTLQnSgFzYXDpVMWjcq9NVIdn1Idv5BM8OVmrdJluS+EI2HPTXgea V2uKSt4254X2D7bHcD7TwHTxrhCWo/1e5MTQfYp29TF/865c6zinEJSPyfaTlVhvLukE QujQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=rFA8gu1U+3BFBSE7jut9twK6sueOoWVC2zzz9eg8400=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=nZCg0LgNlO4AzsEHZ6cmTanDlCaYfeEoM8rWmqYuHyQFJ9LTvs+OSMmP19/to7qQvM 2TUJJAlKztUksjW6Hh7DDp6iYJXabeXUf3kiYdRc/p3aDEFrlugKC2zSvCaUjRcO4nrN jPhNR8LtI4hdJZU68BWeL3nHNJ0q+uHj3ZcZvk2iGM+vUl3/wSGQA8J+yZFJ5bLErZj/ c+T0QVuEO0ZSS6ow8PdKmNRfadn2SpV6i0siJpMWfxD3uzYzRTkWeoUFwk0coDu9OM40 7JlSTm40TRVnnwaTQ8YJIE/i6RgiAJAeNfR4bOc3vr80DWPVwLslBRzu62pEJNK5XIbx ZJ8w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qFNuFnCO; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y20-20020ac87c94000000b0042540184032si634830qtv.336.2023.12.06.21.50.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:50:01 -0800 (PST) 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=qFNuFnCO; 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 011AF385C6F2 for ; Thu, 7 Dec 2023 05:50:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 011AF385C6F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928201; bh=rFA8gu1U+3BFBSE7jut9twK6sueOoWVC2zzz9eg8400=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qFNuFnCO1fRSZqpIA0+C1mDf5lP/IElxXZRrjip+XVhQ2J8fvTahqy8zW5cZF1o/m bLzdtiSA4dWA6GQNftxdDJgk1y+1wF2vvssTQwfJE/x2UJnTzud3MwLJh2GClOsBv5 ClGT+w6zzuF3yw0YXm3025+7Df8q4ATELa96JZVs= 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 1ED74385C409; Thu, 7 Dec 2023 05:49:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1ED74385C409 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1ED74385C409 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=1701928158; cv=none; b=AbnJLjKS0G6DXLGkoI/9WZEryR1cWjLDprs9Z2cCJYLh+bzqFiD7PMHwOcaMC22gY7ajrXjSvZTq9/zWgK8+c1Tb580hWGobE5Fh4j1uy7dk74AJVPG/GvywgxLxBAcywLwks0qbv/mV63KTfAEV5FtIw3mu8bgW+2Q2XhOVVe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928158; c=relaxed/simple; bh=WFOpNSdYjF+7IWup442n7SJmacOas6mXS5LAkOZiD+0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ERKw+a9scvDNerpuyxRHfV+oj4TBrbmR0IRsbPbaPOiM8iQu77e7/j5NE0AKkWIjIehdPAIwdriXxtj7yyzBtW1MAy8eeooI9D0sgfd0OLBfEsXxYAEXyig76fAOCDWZkbYcnKCh8mDrhKKCD5WUVvqBlAp6Xknk7c/b2wqCkGQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75ceQV009714; Thu, 7 Dec 2023 05:49: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 3utyjhc1cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:49:16 +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 3B75mm7G016419 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:48:48 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQF020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:48:48 -0800 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 v26 14/23] c++: Implement __is_member_object_pointer built-in trait Date: Wed, 6 Dec 2023 21:33:09 -0800 Message-ID: <20231207053633.1001720-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _8owCxCibRcEp1rPgipC3oPaIxdzqDMQ X-Proofpoint-GUID: _8owCxCibRcEp1rPgipC3oPaIxdzqDMQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-07_03,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 bulkscore=0 clxscore=1034 malwarescore=0 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070044 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, T_SCC_BODY_TEXT_LINE 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: 1780601609439820438 X-GMAIL-MSGID: 1784601065980806297 This patch implements built-in trait for std::is_member_object_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_member_object_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_MEMBER_OBJECT_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_member_object_pointer. * g++.dg/ext/is_member_object_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ .../g++.dg/ext/is_member_object_pointer.C | 30 +++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_member_object_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 1efc7983039..204b9989b6a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3761,6 +3761,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 03a5cc28020..f5efffdfc99 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index eefce24ac2c..557642d6089 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12397,6 +12397,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); @@ -12603,6 +12606,7 @@ 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_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 fb17680d3b0..b5797075d52 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_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Thu Dec 7 05:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4575630vqy; Wed, 6 Dec 2023 21:51:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4hN6FCjSW1BqV2hPn9HqcbPykpppuWa3VNjnqlQKYSUJo8uUIMDMCzXwXF6GbunbKRHyE X-Received: by 2002:a05:6122:a22:b0:4b2:e003:e16 with SMTP id 34-20020a0561220a2200b004b2e0030e16mr2388158vkn.3.1701928299318; Wed, 06 Dec 2023 21:51:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928299; cv=pass; d=google.com; s=arc-20160816; b=kQYZH0jNrUwV/ohkcoKXh4PCumA5TqjbKODeTQeXma5Bo01VbsGf1u8oOJ452JSO1o ++BoByZl/m8dCQ/IsU0VXQQU81yKi9Hc0VLGDOq4YAo2206ThtMqlSsOCpRZgqbS60dq XzQqfncAO/YAmrSpb/1MrjaHN1yP61Yno6VNEjxBfRgG5V5y5KsYENLU8S6IlxIll/+c ZUj5gARa+K+zIF6omiph2Hj1jmc1Vyf41pNjckFEFKhYFFzMAALp4DJaN3H2NjFiUimp iPWnLIx0D/G+EDpVlNy28PsG4BvhcQ813j/286HWE+mjaOCW6oFupDDFKaXm4cOx63YI HV3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=29+2ieOd1DYGTwo3gbrtvyhW2O5XLFUWh+QvxkCzSgU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LToxrLMypGC/oxNE81n6YaBrjhpTgKTDxX2VD2ah8cr4bJEY/OvIcbCwomEDAbmzLt ssZ68RCjPNk2FHnnHORAGOyVoQdxg+lK9g78FdR2KanYEnUQY8P+h1Zl4hBQdEjUjsvk 6AqyqYPsk9QdhGVxYFoVxDEFJ4bzMPNGeID39pl0mbW789F7gQQ09wy36zqvae9ghoh9 vaSLsc0737dAIlssziq8E4JpP9EM5ngxXB64E0klDA2Z20CN0fxPPil0f1F/nQNipmql t0/5kewQBDrzVo/1ELyv9oiQ6itPTm29EVxERX+N9Sq2Mdze2N0l0jwmsy8NedU6Fv2K YtcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tm8YuByO; 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 z8-20020a0ce988000000b0067ab630e73bsi573007qvn.478.2023.12.06.21.51.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:51:39 -0800 (PST) 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=tm8YuByO; 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 114AB3857340 for ; Thu, 7 Dec 2023 05:51:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 114AB3857340 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928299; bh=29+2ieOd1DYGTwo3gbrtvyhW2O5XLFUWh+QvxkCzSgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tm8YuByOOyML4/wFFe8msZPSNag5dNyae40gar3HEvydeuISDjGighArRksCkvUVP PAAwnsLyEPDhjuLSKrqZL33ciW7OM0TkysBWQGAG//3NNwX1Fm74KkPc9z8IwskkVc DK6Oz4iy74LYYkM4gpxDRvyrkAfH2Qvd5dit8Iho= 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 382F6385800D; Thu, 7 Dec 2023 05:50:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 382F6385800D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 382F6385800D 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=1701928255; cv=none; b=Kr4aXH1wiZll8BOQKX8jFif9LHoDlcRca32p2uwiNoNFlfbOkKRv+sHSKpKRJNd2r8oNmtXVPI0ukQWJ1Hyy9CSR3OnJNDjYU9x0gL4XeaJ9Rx8DnkP7h4/+QDd5JUR/pHSACyZQ1qftrpu8B9cT9/36229gG+va2R/PCVx6s0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928255; c=relaxed/simple; bh=EM46pzAHnAaWoa37zj3SssDfcMqNmVcDSq9ayNXTZ7E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YpeusMqxJ6c7vAKY10rxTk0QOHmAuhWjUrT/xobZXd5+Ezm9QXwIyXByWyfa5L4NeAqFeVq022AQdFFvP4VouCFKKa/utWzdHEDepY16qVWhPTXrKbrUwM5d6TD/4BxZifrCD1BMzsYWR0PWUUWEeBclWUPo5/+dmXMOMAJw/ZE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75k2jQ024280; Thu, 7 Dec 2023 05:50:53 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu035v0ek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:50:53 +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 3B75oNcs000636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:50:23 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQG020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:50:23 -0800 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 v26 15/23] libstdc++: Optimize std::is_member_object_pointer compilation performance Date: Wed, 6 Dec 2023 21:33:10 -0800 Message-ID: <20231207053633.1001720-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vLgVSBDegzCwMs1Qeih68X6bJMVDyo14 X-Proofpoint-ORIG-GUID: vLgVSBDegzCwMs1Qeih68X6bJMVDyo14 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 suspectscore=0 impostorscore=0 mlxlogscore=503 lowpriorityscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601035717656705 X-GMAIL-MSGID: 1784601168410848583 This patch optimizes the compilation performance of std::is_member_object_pointer 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 99ae825301c..1edd05acb4c 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 @@ -3213,9 +3221,16 @@ template inline constexpr bool is_rvalue_reference_v = false; template inline constexpr bool is_rvalue_reference_v<_Tp&&> = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) +template + inline constexpr bool is_member_object_pointer_v = + __is_member_object_pointer(_Tp); +#else template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) template From patchwork Thu Dec 7 05:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576114vqy; Wed, 6 Dec 2023 21:53:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IE13jAtxdBoyEKT88tDTt2MyKIarU7i1J/WbEs5C84nJsmFh9nCBCgVz9vNetcTQx++foa9 X-Received: by 2002:a05:6102:c89:b0:464:5d92:a63d with SMTP id f9-20020a0561020c8900b004645d92a63dmr2363129vst.5.1701928419190; Wed, 06 Dec 2023 21:53:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928419; cv=pass; d=google.com; s=arc-20160816; b=lZ7mtPA8PgHVlvYCUCtKFEa5ehiO7SIF+N9GmYL3Q9stJmjspxmvuDEsJJ3LxiwLhm r/Jvyfyc7XFSELnI8Y80724MgcmTOBXq/oFtgufdLx3Gf7w1eQKDEejLfUfBv5FTbPaX P4e0JTgP2HPocdw4bCry2HHxlPtcPFhkcxBSNVEYTV1f8jZZcXAYedVzCg7ca2ax7LnR j7yDCfwX/JLUSLsUrtJ+DI7tQMsHf/53FYPALwBm12ASvTxJSUj5SWrH8s04qrHmSnR+ 4d2IQkZ9rw/8hQR1CXdzhjWP85Fnq5IHEBCcJvBae2R0jsnn1siw9urhM064Md0CxwtM +7BQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=fyiW+SOOI4DeCunVLDLXnKUSfz1vWLzaEWaA7zx72hQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=QbVxZubrygYWdwDZ53blujpqhk9ODw+bVKL9V17IsI++6XkGVNpS0EiX6ceEXHed6n 4WqAZH+HTab5UO4Mulv0RwEGfnbXmKzyAewxLq8P+FL4EexcNSywk43LT3rj5lJU90PP I9e/DHvdYtJxrkZTPK2EUmW0PtXRsOtbgCWsewqX4CLeO4WQL5b88e3t6AUZqNFSn+2m u00KBTExBrQr/BJSn/mZse3NLg+1PdB3KlIHv0c9ewlgpizCTwMzbCMq20m4E8zRxMyP onFwGScOCdv1zvEav6ibVtv/hebajKzfOKyJcWlwKo+rL8bGQp9upKHhruhahY7uYPlT sJmw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ARVOMkln; 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 i12-20020a0cd84c000000b0067a919a2a18si575971qvj.560.2023.12.06.21.53.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:53:39 -0800 (PST) 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=ARVOMkln; 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 E4FAD385C41B for ; Thu, 7 Dec 2023 05:53:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4FAD385C41B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928418; bh=fyiW+SOOI4DeCunVLDLXnKUSfz1vWLzaEWaA7zx72hQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ARVOMklnesKYzoyNKEDSJk/gGs9jXM1hR9BVNAnS1wNLBay4RMhQMG68TccwhVygI ERjMl9T4TQwVqlv3e6irLiuxmdAPNT85y565NyaNaBV5DKOkipUjnKMsIdP32xOXgi ZEcASTJQuBO98fccSCHzAB9Ddu3IyaSBgKDF2ydE= 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 F005C3858C30; Thu, 7 Dec 2023 05:52:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F005C3858C30 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F005C3858C30 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=1701928377; cv=none; b=oEIrYluHztqCyG9x57MnL575CO3uFjXVGtTN5dbIqSDHHSLtUeWnxEINaFvPMNWUd3/lOlfOSFHLDtXh5u4td+Op2XLHNrMM3C6PGl7+lxMbjGkptuIkUvnwNUZUJqZgK03QTK/WkjXqG6G/1wVvAzulcK0SxcWb0ZlH4IWR7T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928377; c=relaxed/simple; bh=OwO+pUVGECP211VEs6GjxmBjGgR1SPeAKae5WvZ5Muo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=E6E+V1aoQ63zs5GLxKB7NyzRuTXWM1GIJFnA5KW6wlzalRxMq82w90z9ssBZ1XenCIpEJlx8qhr8ymEsbuFXvAhAYsZ3J4dTEOs7/J6O5AXJ6CAm9JA3Zl52ipIznJ1rXqhOPFXkHos2BeH4Xa46hNLMwsJFOxpl8Pc9tIdKSL8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75nMaT018153; Thu, 7 Dec 2023 05:52:55 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu40y9jx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:52:54 +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 3B75qgFc017088 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:52:42 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQH020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:52:42 -0800 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 v26 16/23] c++: Implement __is_reference built-in trait Date: Wed, 6 Dec 2023 21:33:11 -0800 Message-ID: <20231207053633.1001720-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: DO-C_enS9bsnKJg9j1u_g7jj6cFfaq8i X-Proofpoint-GUID: DO-C_enS9bsnKJg9j1u_g7jj6cFfaq8i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 clxscore=1034 impostorscore=0 spamscore=0 mlxlogscore=772 malwarescore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070004 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780600917161887625 X-GMAIL-MSGID: 1784601293979332731 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_reference.C | 34 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 204b9989b6a..aa42017f67c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3789,6 +3789,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 f5efffdfc99..2d82ed3dd35 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -80,6 +80,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 557642d6089..b637798f605 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12421,6 +12421,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); @@ -12608,6 +12611,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_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index b5797075d52..b667b5c33ac 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_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Thu Dec 7 05:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576276vqy; Wed, 6 Dec 2023 21:54:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUfJ2T+/pCnXJP5i1SvvuvYpkSYxrIUu4kNYXMXqNcuTvsndcHJKP0JWnQHx8ENNkD0xvp X-Received: by 2002:a05:622a:1902:b0:423:b9e3:f54c with SMTP id w2-20020a05622a190200b00423b9e3f54cmr3103953qtc.45.1701928451833; Wed, 06 Dec 2023 21:54:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928451; cv=pass; d=google.com; s=arc-20160816; b=v8fsS2iIkQoLgmVdXJoamDf6Rv/mTZnjBPVyOkPUe4TcnnA0wyERp5Pf4pC4HUGKNf Y2ceq0OIggVAE0YfGvCY1t4UzobfQNAq50icnVkxW+Pz82NU+FPll32njIVAWDHIVlP+ K0sEMjsL9h/D/bF806tzw0F5wkCu+7UwBrXmM9ablOupAKZcghurwhDrN58d4Kslz1hx 2SuDwYnk0zH+oGDdHzF864IB0QyOEVpQZChRZR/RIStzQOirE1Ptq62vIWITmbbQvDb6 6iTNMoZwJcoJDu1TcAPRhV6tRzBmxkYk06WUhxZFu8KrEKMIR6yJ1ad7NzotsX5/rPzn 99Xw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=UyR7MfWOTjpG7o7yLKhtDFfADUPY01PsS9ZEM0FNL20=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uO9qHID1KLkPn6RZNiKQgrVEs8okR3aw3H6z9Y0wTS1WQ/ymG8qcvZsd+TrUyDN/gS C/vIrJiaboVOp5mAfwFgTWAxFDLkpcFoJAn6J5OsJ9icwJCsGqxr+2KzdPufGuPg3jcz 2V1gu3H/a9GLtruJiBlSLyqu+1ZHWns1jKurh2e4SopurUzgvjFfdibhqja0gWUSDupT 9yiVCIeBHDP2LrBFC7quXVGIaT60MPOldlfoeNTOU09rQb/DfEXWm8Nc8Kj1D0mN3GUO bkUhVxqmQGQVckLUDFbWLhB2BpkXue3YLYIRIG5FUpZ29C8jn7m1XbJZnM5In1Va2x0J PBJw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=devNcyc2; 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 r12-20020ac87eec000000b00423a1258c3bsi631948qtc.219.2023.12.06.21.54.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:54:11 -0800 (PST) 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=devNcyc2; 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 8F933385C6D6 for ; Thu, 7 Dec 2023 05:54:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F933385C6D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928451; bh=UyR7MfWOTjpG7o7yLKhtDFfADUPY01PsS9ZEM0FNL20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=devNcyc249dL2IkjYo72I2vGQK2OIJ9D2ihgaht9iPP/P/O/XLF9tEirf6PTZ1caO UykIqYuy05R32YqRfUTasDAn1IEsfg9c+POZljJOnhHhBmkXQaDqjMoOsGlWWe/DAC j6+2UKdilb9EQCATTDw5C5gtL4mTv57pLTmthnfE= 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 09DC7385C32F; Thu, 7 Dec 2023 05:53:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09DC7385C32F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 09DC7385C32F 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=1701928408; cv=none; b=NJqsb8qxgiqHEcIeu7QnDkMnhHe38RJyHkT+MDfhxmHwl+ngcsgwgl26Qlr3R73ML9xwW8hLpxscnET6gq5D1Sr08TON9qJyMJB1gXOOqMRq53/mSKLtwo4sBD3swv9KEOKEyJi+VPpJswi3UJ0PnLJrxHBePw+58hB3BVdtAw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928408; c=relaxed/simple; bh=W4ySPpiY8zmhzZFNjTs1EnM7Bx4j6zswp1xaTgiVf88=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kcxQBipSUCR7lP5u3irPTdpOozcpmBI/FHUI+MP2BZSccYtEipshavn2c/7QzMcMUQ1rKLId+GJLwRswowDsbo8QSVX9NsEjVFtBMsJzOK4l+8VIo3r+BSzbSVZ6GxHDz/Lk7w9fqLYFpjnWB+gmpHEN75N6cGbkQ/jlehK+/QY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75m716002002; Thu, 7 Dec 2023 05:53:26 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu0y1u6rp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:53:26 +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 3B75rPid017245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:53:25 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQI020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:53:25 -0800 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 v26 17/23] libstdc++: Optimize std::is_reference compilation performance Date: Wed, 6 Dec 2023 21:33:12 -0800 Message-ID: <20231207053633.1001720-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Fir1Mgti3cmCqCu-gDNmsBMGaFarYJW1 X-Proofpoint-ORIG-GUID: Fir1Mgti3cmCqCu-gDNmsBMGaFarYJW1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=695 impostorscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060160 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, T_SCC_BODY_TEXT_LINE 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: 1780600750884623446 X-GMAIL-MSGID: 1784601328391014752 This patch optimizes the compilation performance of std::is_reference 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 1edd05acb4c..db880d87f60 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 @@ -3250,12 +3257,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Thu Dec 7 05:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576350vqy; Wed, 6 Dec 2023 21:54:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjZ77RYfrPzwI55lkWdEjr7O7d3XTIP6rnbCei8KlPHhkbvUoAq06vZjpWH1E0W499IIUp X-Received: by 2002:a05:690c:3688:b0:5d7:1940:7d81 with SMTP id fu8-20020a05690c368800b005d719407d81mr1942656ywb.88.1701928468424; Wed, 06 Dec 2023 21:54:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928468; cv=pass; d=google.com; s=arc-20160816; b=xzaNkYvOfUvPr/lx8q3PyiPLSZ0tL2XvuhrL8uA+JNHhZUAdSjQqvE5VDqj86YJaZ3 paTZMRJesMlAAgyZAxtJPdiJvGcDyM2XNYpTXnUqqe9F0ML/fOZMARQjRurAIFsNR47K OVGkyni2S6WY44NqxRPxqhh1Uo2zy8NTYzDNO7zwI84XQhAtOSXx3nMAa4pu7uKH5XES q/Jg/0fiHvV4O9jMKHHls429JNyOZIESzKkYf5AVud5TKIIi1Pll8H5T8meVwIh99wLn FoUpYlUSxoSytob+mRcDRVE2JxD1o56Ua7x4wiPUXT8nG8t+GxnH+p3UeqPXSzIUwqpI 53DQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=mDmrQGoRsupCc/E8Ms/1qfuD5UpzrG4NP64xIgm9B+Q=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=SKLOoeUPBkbZZQdhS4wQnpilG+8gqnUx4NhEGFwutLDQ2qR1/rz2KB7HUAPiJ+Ekne 5AE1K+n/q5dfpq4oADIeQQ9Lx+a59pM7s9ONXd7BATBrjFXcN8JHGtENxUTJt52+TlLF 7wZbtrMwjxugOiiPVYDipu9+Nn9IlOoIsUs9KquZHSI7OgQyibSXz6tn/vWazJGAVvWX gVAsAiCyeQ+3qkEe2lgKie4vq6lk9fEC68sBBu0Yhe411+sWUK0LpbIVpzIYEyzX1XQf VDx9W4oXaBHj4IjIAz5HvSGrdaDzWaa2LCGZFSRFqV1wStLJuN7Q475tkzas4l3pfT+d 0t8w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iqnz7g6K; 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 j14-20020a0cf9ce000000b0067a26f41da3si615640qvo.79.2023.12.06.21.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:54:28 -0800 (PST) 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=iqnz7g6K; 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 25DDA385DC05 for ; Thu, 7 Dec 2023 05:54:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25DDA385DC05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928468; bh=mDmrQGoRsupCc/E8Ms/1qfuD5UpzrG4NP64xIgm9B+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iqnz7g6KrkWf4GzjLqdE2LAv7bEMHWpbebXnNBDN1Eo1KOY6Q+yRMvgYdTZuOmCUV 5pLpYG95ElGJeg3rFteYe5R6wMK6O5Jji+KIV4ccwx0p4AQ+7hneEwy3BEVOcYZDTF BIOJrHmTVWYBUsIOd3tVna8QHxmSTpqonI8QirfY= 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 77421385C31F; Thu, 7 Dec 2023 05:53:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77421385C31F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77421385C31F 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=1701928426; cv=none; b=GInRiqu/MyHwIdboak1Kfvxm7Eu+FEY3a4oATGG2W2KwVcIK2N2KkGhtI/wro6rKt9GuBtn1VXuELIg+L1QtYGhcnz6yjCRCq3F+ZkTq6nvTvYLb/R5QREHceOvBvmiMwgu4LoDAwXFYnx1YPP6VbqJiQuHeKSlHZrkP5c+kxEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928426; c=relaxed/simple; bh=w4eGzFYek05u/NF0aEMuh8JV1Znc2sDnftvPwknNzv4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=knQ08ZTzRS5AJlMoxBCJO4OcJGy2bmk02rgnIcqSygIgEbKyUThoBsRYt9Ostl3Hv+se7Kk00gjE5E16DFRZ9jmbB1hlGIyTvJAUICu2QNLgysfa2O80dkf6OFXwbv8Jk4ite2XrJIGTZvvXWrNNN5idx55bEXbOK8GwMM8SNVw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75pGaq005248; Thu, 7 Dec 2023 05:53:43 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3utxdbd949-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:53:43 +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 3B75rb9p005850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:53:38 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQJ020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:53:37 -0800 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 v26 18/23] c++: Implement __is_function built-in trait Date: Wed, 6 Dec 2023 21:33:13 -0800 Message-ID: <20231207053633.1001720-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 00um_5BAAmsHv82kkoNk82IwHBKOBW5h X-Proofpoint-GUID: 00um_5BAAmsHv82kkoNk82IwHBKOBW5h X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 mlxlogscore=898 spamscore=0 clxscore=1034 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601213154564259 X-GMAIL-MSGID: 1784601345302302466 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_function.C | 58 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index aa42017f67c..4bea6089791 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3752,6 +3752,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 2d82ed3dd35..89712f18667 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -69,6 +69,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b637798f605..50330922d70 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12388,6 +12388,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); @@ -12608,6 +12611,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: 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 b667b5c33ac..5215da27d6f 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -86,6 +86,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Thu Dec 7 05:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 174943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576820vqy; Wed, 6 Dec 2023 21:56:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpZb0Q0nzXNqL+ZY+XQpWhNhJLP41W1mzYV6y/gylIrR8Ktz78jAwB6Usp7c5HTAg4L7Kk X-Received: by 2002:a05:620a:8dca:b0:77f:3253:6f2 with SMTP id rd10-20020a05620a8dca00b0077f325306f2mr543313qkn.18.1701928572803; Wed, 06 Dec 2023 21:56:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928572; cv=pass; d=google.com; s=arc-20160816; b=my+C2iBxoBqNFr0SMMp9sn19hL40L8YISrpHqc9VnZ53eJU9Ejro8dcTXVL1zqtoh+ krF9VX4TAgxs4lQU4NTQ28DOr/zfxDcyVag+YjSYttIADI4a9WOmHMqh/eX3e0Yq7w9X ZatjVs/phzdOlG6VF3MyMMOCuECKtan2ZAilL7lGFGVKiVHo0hLmTm43EYqyuD+PNkzE zgWGbcN+0/RQwCAncqxYLjH/whir5LXzZqcytz4ZBQ/ozs30Efp9iRoPsooGfy/AqkHR dmQuos9CA9TzgWLfAw9X58WidStDT+fiRWmpdrZjDNRcSfelSSuNk63DhYrs9gr5XXzG 8rOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=AbrRnA2Rj/m2cWdN++GYFc/NhKARJVJ9a3lwQ2RAQTA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=i6XZHHUxFMDhx1jts5gr/cbzuyjHc3jCfEC4JsnSdQnlPlYsKSlBFjHdxzAEc39Q0p USpdCBp9avZq1FsuvfItmCtKQvSzQeCzFC70bVi8vy1PS+ATN5+SkMEr0GWWIelygP8P cxEOhqwQc+6DdcP+/frjUYMBy6qtk2A/KwL4CKW56QI3aOTfbNFClPj3zVC1DJ4Y03uN h11PGrJcQMjAoXMWMHRKU7qs1RZEtDg1oavoerFsfzq1eiMQivFiLuYxBEZVd3B3QF72 ChwksaRAfFDtm0R9QpuciqXlqWUBy5sK7OwRaXyRXJsqZYoUJqBEjrCKsCUXqZwKqiJ9 oiDg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=o6UA6HPk; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h19-20020a05620a245300b0077efdc96f7esi650800qkn.66.2023.12.06.21.56.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:56:12 -0800 (PST) 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=o6UA6HPk; 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 D189E3860757 for ; Thu, 7 Dec 2023 05:56:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D189E3860757 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928571; bh=AbrRnA2Rj/m2cWdN++GYFc/NhKARJVJ9a3lwQ2RAQTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=o6UA6HPkhAV2PbRu4Ul8SVhBP2WVCO8lmHAe3DcFKoGC6RbNrggKp9sOzawtHfhkG NmB9aEgj8yem52IJMvHV1f3XLccPlQkw+d597n0AgCAEu50SE4vBEjUnwj1O4sCZKx e4oopZ7kPMjstoej7XLX78LQ3zB/aTPvSOvl4CBA= 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 0074D385C6D7; Thu, 7 Dec 2023 05:54:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0074D385C6D7 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0074D385C6D7 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=1701928472; cv=none; b=RRd3zkpMtd9b2YkJ/BgNL+r6MfvAcLREE7MNheEw2Q+TbdaX5C3WS3ZLSVRN96YURX1NC3XX7NXzfikkIAYXE82rAZMkuoAad15qFELFGzr7GjrhWj5GVN8Scp64H2BpOs4sF5VWg5QpGuv/1gL0wyPzcAlyhnAbtqZyespPo0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928472; c=relaxed/simple; bh=3qcEhnoUoxUxq3PdYXV5ThYCAyqSsj7IVD9hyAfsfzI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BjOCAQRstlIgZk8lfzVcY8VpABQR78ZClQHQaEmvsbi200GElHJb1DcQzzau5fzNROH99Y9xBbnWPnG/7Ygh8FmC5JyzQcUY4jTKNSOw1F+TPt6inzfppnWSFGMT+foXiAzexIKlCYSDteVmaBIFgX868XOeS4Qk/3Wk5+unWn8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75s9DQ016797; Thu, 7 Dec 2023 05:54:30 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu3dmhu36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:54:29 +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 3B75rx30001043 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:53:59 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQK020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:53:59 -0800 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 v26 19/23] libstdc++: Optimize std::is_function compilation performance Date: Wed, 6 Dec 2023 21:33:14 -0800 Message-ID: <20231207053633.1001720-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 92Gku2vMlKaNoMyddz2xaDaV6yabKOtr X-Proofpoint-ORIG-GUID: 92Gku2vMlKaNoMyddz2xaDaV6yabKOtr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 mlxlogscore=340 malwarescore=0 adultscore=0 clxscore=1034 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312070000 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601109600252087 X-GMAIL-MSGID: 1784601454894737295 This patch optimizes the compilation performance of std::is_function 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. Move this under is_const_v as this depends on is_const_v. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index db880d87f60..b6d0441129b 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). @@ -3255,8 +3262,7 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); -template - inline constexpr bool is_function_v = is_function<_Tp>::value; +// is_function_v is defined below, after is_const_v. #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template @@ -3293,6 +3299,19 @@ template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) +template + 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 + template inline constexpr bool is_volatile_v = false; template From patchwork Thu Dec 7 05:33: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: 174942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576723vqy; Wed, 6 Dec 2023 21:55:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXAuKK2AUOIwq0+buoz88R++xX+ICONKyqWcBFtxUhkacQRDFLwtZGXnp6f+qDqBYZFkZI X-Received: by 2002:ad4:4523:0:b0:67a:a721:e118 with SMTP id l3-20020ad44523000000b0067aa721e118mr1958662qvu.69.1701928548892; Wed, 06 Dec 2023 21:55:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928548; cv=pass; d=google.com; s=arc-20160816; b=Hcn0jv4cVFCrUQfsSYFyeNL5lqy8aZHWHnFE1A4xHGIAjG2gZPqtbpm+GQ+uQj+7f5 bQBPdoWKtxOD9ayVgDx7tzxwPico9HUVZfer25q/S9Bd5dC5rVe1KXo4UMBQ1tujKVl2 dn17I3gCjJOgVadM/ouhYCHFjwLKKExAr6l7ZG4zN6S4+XJSMxFFMTYCGBGlM+9Jxfas BywtmETKg1FRDK8SWdLqR1blESSy8JxDEGgwoHM1VC8CwQ9y2KyeXgFgSAWRJbwXAGHt hlUc1UgCQksm0n6dZrA+LqFoCAFH8QARHSslkpDQ+9cVz9TosR1rDzqbBZpAu4ZwtVpl BFTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=vsBGQzl0AR+gv9wTKwBPbc6r+/F1wj+IwlkvkGYIsqM=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=y/uEnvJtZwuefZSp6eTGYzQYERMbHHdHDjKbJsPJuJ3a7S9mcuhLIjIT/NdDhdkCKP JhWETmEZGX4Lbtr6JpURYMnUAVjkFHoN/mqEM9HI7X0U9bNrA3H6zyM69bNT51VXumd9 Wn12nkX4YsiOzOedC5Q1Mk/nvMHG11V9CRX6W6xlnq4LLZhcuTtkzWtq4/tcWwcccYSF akNt/WIfH1Cmb9zsF1NWACtEHw2+Lpbmt5PMlUchvaaQnhcZ3nPdVLgLyrZQbSq3CGVR 6H0mIPMOcb+cQSH3prsJfP6a+xSHPoADvwzV2Mnz4VHDeBccYecefTt6zRTvrz7q2ihc jJPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=omozvYtQ; 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 b5-20020a0ce885000000b0067a261b50fesi587587qvo.320.2023.12.06.21.55.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:55:48 -0800 (PST) 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=omozvYtQ; 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 539C0385DC02 for ; Thu, 7 Dec 2023 05:55:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 539C0385DC02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928548; bh=vsBGQzl0AR+gv9wTKwBPbc6r+/F1wj+IwlkvkGYIsqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=omozvYtQxtj8uvmMKsjpRLsIrJW3pQGgGkolbiR7OyGsimU+vZP/pXDYIGQZu/Alz QVjdUTwZ9dj2xgLG8XsgDxQVowiuAzrKY4/MF2ClYynmMO3Gjmyd73NI4OCiY+Quwt DclM6BmO3lXExoB1sbtUPdicj6EeoJc2TCtUygBo= 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 70E883857340; Thu, 7 Dec 2023 05:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70E883857340 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 70E883857340 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=1701928506; cv=none; b=qAPTl/YkMWcGpMMFq1P4BulAkeZxIGuTaaszF5aME1LKwiq2NqUz/un1fgmppGrviKHClC8LjK9DGOUXbJMMPcPZILcQmiayhXmJedq4pu/UiS3b0eQNV7G3q95h428fwbxpRicdlfC+6gjHHBitPCbQO8ZlHddw6SjRhHCwJ9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928506; c=relaxed/simple; bh=6WDO5J2Y4MPQco/JZdM3bS1j74fI0l/j4JYOGTvnEcA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=HOKiTgbmwePyYMJTkSDt99jodmvoEgKvuDa8/Hf9SExxaKwfW8Nn/Z84bmD9IyGqu3aldZrd79stz4goymVl3dr6jsy0NvNbxkEudM3MGA1PUctyGxrAUxaL47pV8VDjrHHqF9W6O+bARV+wW8IlDu6EEl50JODXy0bbD42xRZ4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247476.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75oAR9004476; Thu, 7 Dec 2023 05:55:04 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu0y1u6xx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:55:03 +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 3B75smA8010103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:54:48 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQL020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:54:48 -0800 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 v26 20/23] c++: Implement __is_object built-in trait Date: Wed, 6 Dec 2023 21:33:15 -0800 Message-ID: <20231207053633.1001720-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: aagKDGPnwfHC1H6kd4mNHnSZDvKK7cgM X-Proofpoint-ORIG-GUID: aagKDGPnwfHC1H6kd4mNHnSZDvKK7cgM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=904 impostorscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060160 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, T_SCC_BODY_TEXT_LINE 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: 1780601035887003230 X-GMAIL-MSGID: 1784601430546541566 This patch implements built-in trait for std::is_object. gcc/cp/ChangeLog: * cp-trait.def: Define __is_object. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_OBJECT. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_object. * g++.dg/ext/is_object.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 6 +++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_object.C | 29 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_object.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 4bea6089791..eeacead52a5 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3782,6 +3782,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_NOTHROW_CONVERTIBLE: inform (loc, " %qT is not nothrow convertible from %qE", t2, t1); break; + case CPTK_IS_OBJECT: + inform (loc, " %qT is not an object type", t1); + break; case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: inform (loc, " %qT is not pointer-interconvertible base of %qT", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 89712f18667..b833efff26e 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -78,6 +78,7 @@ 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) +DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) 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) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 50330922d70..cf3d5476dbb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12415,6 +12415,11 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_CONVERTIBLE: return is_nothrow_convertible (type1, type2); + case CPTK_IS_OBJECT: + return (type_code1 != FUNCTION_TYPE + && type_code1 != REFERENCE_TYPE + && type_code1 != VOID_TYPE); + case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF: return pointer_interconvertible_base_of_p (type1, type2); @@ -12615,6 +12620,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_OBJECT: 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 5215da27d6f..2242276f633 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -113,6 +113,9 @@ #if !__has_builtin (__is_nothrow_convertible) # error "__has_builtin (__is_nothrow_convertible) failed" #endif +#if !__has_builtin (__is_object) +# error "__has_builtin (__is_object) failed" +#endif #if !__has_builtin (__is_pointer_interconvertible_base_of) # error "__has_builtin (__is_pointer_interconvertible_base_of) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_object.C b/gcc/testsuite/g++.dg/ext/is_object.C new file mode 100644 index 00000000000..5c759a5ef69 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_object.C @@ -0,0 +1,29 @@ +// { 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_NON_VOLATILE(__is_object, int (int), false); +SA_TEST_NON_VOLATILE(__is_object, ClassType (ClassType), false); +SA_TEST_NON_VOLATILE(__is_object, + float (int, float, int[], int&), false); +SA_TEST_CATEGORY(__is_object, int&, false); +SA_TEST_CATEGORY(__is_object, ClassType&, false); +SA_TEST_NON_VOLATILE(__is_object, int(&)(int), false); +SA_TEST_CATEGORY(__is_object, void, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_object, ClassType, true); From patchwork Thu Dec 7 05:33: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: 174945 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576970vqy; Wed, 6 Dec 2023 21:56:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV/q0xkUJScmQ6f9A2lvsiwoqInQIIR5Xk9KOtdtGjSWX0w5SiDF8PK4bdx9FfPeUXzJIs X-Received: by 2002:ad4:46cd:0:b0:67a:a721:b1a8 with SMTP id pm13-20020ad446cd000000b0067aa721b1a8mr2193384qvb.99.1701928609511; Wed, 06 Dec 2023 21:56:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928609; cv=pass; d=google.com; s=arc-20160816; b=AGrxMXDmIcIwEyjNRaXXaDt+qfZ4Z7JWkipqq8fdpAwzhxXGuYpbpFdaaHF/gWLqoo Nw8+gKq8dg/jjD53cS2UF5RUCSIX0Pi1VE8s8mWevCPVs2WR8EPQyDp0Wtsj5cvNJnjO VC8sQXxbCAUGRsVGMFtFNElMAgJ75P1hbuluBVeDt8nKuN27TgV55EpK8UkMsAA2d8cw NMyg2FBjBsFmAFC7df1XAdqUsjW0VPQyjoaZi5QeppVwAnC3uXplynDbc2SUlyaUKMJt ifyhgIepN8/XP0IxdBlVqX5Avqoh56SYluV3aEguaMB+5ScZGCOzYKWb+LVzGhTPv9X/ ieoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=xsppsy2tCFO7Xq3LpfBhM2tdEEdTj2jMEo5ON5ayh1I=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=z5b3X2RrTXWVl/PNl7HCeZkoMr7p74Ve7FiGgAmT1QikV6j2X5PWd0WFi1g9bSbvMq +EaEqTA9j9BBABWQURD6y9kW0pxIwJURh1ADDUd16DyaYkavWlCL2cyfmGAIyjALwanj cXtjrFT8Ry++X/a1yLGiYuQg8d+NB2yosMT5iS069im/QyX0YFXEHexkgzIhKOiAUy/O b2CWEQzOyQ6ljDdwiTUybM8SoLwITpKr6fWwZuED4z8Pbjv6M8Mfs3n6aWo0rr1vIonH ryhSFxpXLW/CYG3vE34Q62On6mH5gxMlFiPvycR6nUiPBQcyjuUa6FPuIXl+HBj/oIy5 oXeA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Kr6CmjZS; 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 b7-20020a0ce887000000b0067a99de3e08si567250qvo.541.2023.12.06.21.56.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:56:49 -0800 (PST) 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=Kr6CmjZS; 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 3174B385E006 for ; Thu, 7 Dec 2023 05:56:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3174B385E006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928609; bh=xsppsy2tCFO7Xq3LpfBhM2tdEEdTj2jMEo5ON5ayh1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Kr6CmjZSuqtvAC85MdvEa10yOZPukt578fYpf6+IFDhrqAjeJIrCRHzrpuHh3H7bb LFKXBVcMEa3NC1ojAbFxD3+D3LaJA/XoqN+3IwtjZJUTzModCSZ0U7/R8ZRg0EKtxE 2xGamIBbVtnqu/b+Ep5qsE2qrxtVsGpMaQW26vv8= 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 CAD81385BC13; Thu, 7 Dec 2023 05:55:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CAD81385BC13 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CAD81385BC13 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=1701928533; cv=none; b=uhFefM6yOOjwW+C+yW/5BgXTob2fDvuDxk/zgsENFUQnrUbrIf4I+u4gWYPG3JgdLALW/766aM1ij0BwUGFndV/KXwNMzqFMmoCSnzX6mHDYec4jPLmYBHK6SsyME4/0Y74rzMaxO2eH1/UYxziA0DEeyzNDQdgcwa1G6Yla+SA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928533; c=relaxed/simple; bh=QISN3Yu40WPGRlDOE89RAUtl5p/A0wNUbJUfr6WdX3M=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Aqs/Nt5y+K0UqNsdGfndefqwTt1M/kC9vGVWO1ssy4CG2x+SKax9M10gNinvOVocmHHtNs1ue2vNONdBrp6cSBaz+j+0yMdoDU3/wbx3NMqhbDI2ONNWDAxxVC/svvALTe4AyR1Gx0czTaTNP3dLLfI5A7jIHBsJ02inJttAL9c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75rTGA009003; Thu, 7 Dec 2023 05:55:31 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3utxdbd9e1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:55:30 +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 3B75tGrc017569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:55:16 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQM020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:55:16 -0800 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 v26 21/23] libstdc++: Optimize std::is_object compilation performance Date: Wed, 6 Dec 2023 21:33:16 -0800 Message-ID: <20231207053633.1001720-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: WbqN9i4WMy4vH79c-4BwfYt3h1tYqk_Q X-Proofpoint-GUID: WbqN9i4WMy4vH79c-4BwfYt3h1tYqk_Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 mlxlogscore=696 spamscore=0 clxscore=1034 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601041635982856 X-GMAIL-MSGID: 1784601493578010606 This patch optimizes the compilation performance of std::is_object by dispatching to the new __is_object built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use __is_object built-in trait. (is_object_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 b6d0441129b..2979d79a801 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -725,11 +725,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_object) + template + struct is_object + : public __bool_constant<__is_object(_Tp)> + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer; @@ -3280,8 +3287,15 @@ 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_object) +template + inline constexpr bool is_object_v = __is_object(_Tp); +#else template inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template From patchwork Thu Dec 7 05:33: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: 174944 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4576965vqy; Wed, 6 Dec 2023 21:56:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6TJjgZ57QCv3iI7SgaYfx0eeeK7Ck+Msr4tsY5QZd1U0cwPCMuKMaGi1zjZei0cWFcTNn X-Received: by 2002:a05:620a:8705:b0:778:8fb1:7a9a with SMTP id px5-20020a05620a870500b007788fb17a9amr593146qkn.41.1701928606674; Wed, 06 Dec 2023 21:56:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928606; cv=pass; d=google.com; s=arc-20160816; b=lj19NjEzN9s6rPnxMinsmuzMqx0Fp88DzczMyRLuss2AyvgnHSUGY2S5f3zMN6q1Ps 1xNw01tIxAlWu8Cw2P9BD9ci0FFtjVUkNW1225cP6AwL+zqeAtrf0mlxoDJrNJP2zkL7 PSB0+6VhJ/4BPhuAMOj5BTz5bA0ms1Ll/vC0QcuFrrOLKRamUBaFWydv0wZR+4gASBUA 0LslvPGhhEBsaWtP4V9+JeptIgjCpOJddFvwMq4Dr2yEwvGp6gxIr7o7FqrXPMRH0wy3 rVTgor9sUEmmFsz6z8Db05c94nDZua18mvUFpClIkFvpCXUViP5zziTiuo8swHS4a60a qmwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=yDD9NzYtc5s2PI89IQYpt85tlVqDM5758mMrGjro6Ig=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=E5jZOKHNl5KPQzNzwUYU7GHRCYAyBXF2pJt4x5GNgCn75lhknfGv454QhmQVrGYgYJ 485rU2zHiqUTtdw3sL/tK2Iw+O5YwMsNe+qFthXzII1EXDqQ0jJegx2KyWgSZzPXPKyf OYI+p6ImdgSRjgxi+lUOGhRMoNbi30+iKUX6E2CzyiOMWRRkGeMuOxRDNzuYY247e+xF 24gXL/7Ibxu5JqAJ+aKgURMsvCgbgX5LCdcBufiiOFyXX2llYLkOScyOMFbYf55DJhVR 1Fh1atc6RHIFkKxfsbMZjIZz1UmtXv6laJgZMWaWXuQmx5X/L/hh0wIPzJIo52p+StrE uOUw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=X6VIH+2h; 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 po8-20020a05620a384800b0077f3d06dfb9si555253qkn.617.2023.12.06.21.56.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:56:46 -0800 (PST) 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=X6VIH+2h; 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 69CF7385DC13 for ; Thu, 7 Dec 2023 05:56:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69CF7385DC13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928606; bh=yDD9NzYtc5s2PI89IQYpt85tlVqDM5758mMrGjro6Ig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=X6VIH+2hFpbFb4rjKLOBN/vfQ96b7R2xYO3pEbUyFemivBuv2NrqR+5V5GFQLhqxH 7uu+bT3kILuS2A3U/SLx7jDcTV/F0ltZVzkzHSVwDsU4f3hI/jspA+oxwZsU+AcwKV +umy55o0ESswgtEThr3JHpDoxiNfX+sd3fSjh+hw= 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 D9587385E001; Thu, 7 Dec 2023 05:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9587385E001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D9587385E001 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=1701928565; cv=none; b=dw8ZXOYGdlOqGikrwW8XOJxMnld9bJLldprhY/vZ2slS2zntakZhxWi5b7oh5NLhKG1MhfteQ/rgl0CeANEFs5J83kQpr3C3Kccj1S4GS9TuBL1wO8SaKRsLxg2Lh4G3wPHwf1GLI50yHwrq1hipPOgKGCaI3Io3pI5FCEhPpgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928565; c=relaxed/simple; bh=eLGDae3681lct0jbAdawG/qk+Llmta1jUYlqZ9c0dwE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EXxRtIPFyZxHG+JE+7SSPPLjO/svfRpKf35JNvMrMYdTf4WS5IhndO/9Fm6sOmLMorK1Gp5yETNtrsTVcvC29INPPI79jrIeAuOZfGcJtuRltbFrUnfz1FX3B/wzQykDshHAZliwYWC2X3OjAw2sbCPeK5FP6zbIGPjqMGR96Ak= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247473.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75u1vS014791; Thu, 7 Dec 2023 05:56:01 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3utxdbd9gf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:56:01 +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 3B75txD7012664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:55:59 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQN020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:55:59 -0800 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 v26 22/23] c++: Implement __remove_pointer built-in trait Date: Wed, 6 Dec 2023 21:33:17 -0800 Message-ID: <20231207053633.1001720-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: h87UcmkASQzd2tZ-EXiBOIe-Mg8S-vR_ X-Proofpoint-GUID: h87UcmkASQzd2tZ-EXiBOIe-Mg8S-vR_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 mlxlogscore=608 spamscore=0 clxscore=1034 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060159 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: 1780601491404965857 X-GMAIL-MSGID: 1784601490246364030 This patch implements built-in trait for std::remove_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_pointer. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer. * g++.dg/ext/remove_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 5 +++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/remove_pointer.C | 51 +++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/remove_pointer.C diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index b833efff26e..394f006f20f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -95,6 +95,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1) +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1) DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1) DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1) DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cf3d5476dbb..4b3acbcc767 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12695,6 +12695,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 2242276f633..02b4b4d745d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -167,6 +167,9 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__remove_pointer) +# error "__has_builtin (__remove_pointer) failed" +#endif #if !__has_builtin (__remove_reference) # error "__has_builtin (__remove_reference) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C b/gcc/testsuite/g++.dg/ext/remove_pointer.C new file mode 100644 index 00000000000..7b13db93950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(__is_same(__remove_pointer(int), int)); +SA(__is_same(__remove_pointer(int*), int)); +SA(__is_same(__remove_pointer(int**), int*)); + +SA(__is_same(__remove_pointer(const int*), const int)); +SA(__is_same(__remove_pointer(const int**), const int*)); +SA(__is_same(__remove_pointer(int* const), int)); +SA(__is_same(__remove_pointer(int** const), int*)); +SA(__is_same(__remove_pointer(int* const* const), int* const)); + +SA(__is_same(__remove_pointer(volatile int*), volatile int)); +SA(__is_same(__remove_pointer(volatile int**), volatile int*)); +SA(__is_same(__remove_pointer(int* volatile), int)); +SA(__is_same(__remove_pointer(int** volatile), int*)); +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile)); + +SA(__is_same(__remove_pointer(const volatile int*), const volatile int)); +SA(__is_same(__remove_pointer(const volatile int**), const volatile int*)); +SA(__is_same(__remove_pointer(const int* volatile), const int)); +SA(__is_same(__remove_pointer(volatile int* const), volatile int)); +SA(__is_same(__remove_pointer(int* const volatile), int)); +SA(__is_same(__remove_pointer(const int** volatile), const int*)); +SA(__is_same(__remove_pointer(volatile int** const), volatile int*)); +SA(__is_same(__remove_pointer(int** const volatile), int*)); +SA(__is_same(__remove_pointer(int* const* const volatile), int* const)); +SA(__is_same(__remove_pointer(int* volatile* const volatile), int* volatile)); +SA(__is_same(__remove_pointer(int* const volatile* const volatile), int* const volatile)); + +SA(__is_same(__remove_pointer(int&), int&)); +SA(__is_same(__remove_pointer(const int&), const int&)); +SA(__is_same(__remove_pointer(volatile int&), volatile int&)); +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&)); + +SA(__is_same(__remove_pointer(int&&), int&&)); +SA(__is_same(__remove_pointer(const int&&), const int&&)); +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&)); +SA(__is_same(__remove_pointer(const volatile int&&), const volatile int&&)); + +SA(__is_same(__remove_pointer(int[3]), int[3])); +SA(__is_same(__remove_pointer(const int[3]), const int[3])); +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3])); +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile int[3])); + +SA(__is_same(__remove_pointer(int(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int))); +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); From patchwork Thu Dec 7 05:33: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: 174946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4577124vqy; Wed, 6 Dec 2023 21:57:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhIoVxBl2rl2mwF6JmqxwTaRO6XxQEDK90kfdWnfWRh7ELsejzPXIhagL4X5WEQEFvUPFj X-Received: by 2002:a0c:edae:0:b0:67a:a721:d768 with SMTP id h14-20020a0cedae000000b0067aa721d768mr2286270qvr.78.1701928640486; Wed, 06 Dec 2023 21:57:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701928640; cv=pass; d=google.com; s=arc-20160816; b=Z6KfejLhXru9PHbhntEqcTUyPJOCDcrljs7P44HBtlp2UVa3itPhf9sCxLwfjEgJlV JfcQhxJJ7MBaAkZianu5Ax0iDMbEjKtHmplqvJpDKgURIMLYVy+WSd+bIg8N6dN8HzNw HU3i+9MHk8eg316gIXb3mwmK0abTr6LduxfLsGxlkr+bhyhAYs1MS8ALUM8agbbqJ+6Z XPdyVYUPu6MFyx9LI51QzQj4Mq5JtnhKNeDRfT6KAwOWffUTUvem8lJ8Z0YPGy+7XVUP cECTe8DMtX7qqXGeNoAnwyTk8u4JsVagNC7MjFON30TKaqQM0JW81jpH/kxGv25xxxZj q28A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=6dLvoxg3yLfk1ni7KqPKi5+eMebatmLsne9rxc+qqf0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=WZY090QSvUZq9BIDza6KA6PlkCw6knBwlDmRL6rw7SfZWkOwOCLvcx2FAGz1urjIrT GSt4G3RLee2mXBJeZSgaiR9hkUPDp5ZccSEIoxuM8nIMeBul1xdRQgYi1XjbVRVebCq/ NvXychUfDIy9dbSPxpaLDR9AraY5qj/STl3w75QUkPI9a6d3TWI/8sYo0hRC9V/8JlMe 7HfPje7KiHShV6iYvrYIvlDiEGYxgPkUGPGc13xC4wBp9Tklt2YyHYpMfIwwpwTYViyI 2OD7esiQQpGlxQAX6KRppptLV0bUesugCbpRK2WYhpmIatXW4n9j6eFVAePp77lLtnDr 6BBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=phI3XsX1; 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 bd16-20020ad45690000000b0067a96a2b4dcsi622897qvb.21.2023.12.06.21.57.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 21:57:20 -0800 (PST) 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=phI3XsX1; 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 3ADB03854828 for ; Thu, 7 Dec 2023 05:57:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ADB03854828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701928640; bh=6dLvoxg3yLfk1ni7KqPKi5+eMebatmLsne9rxc+qqf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=phI3XsX1dZNeGEMnVQwi1hS1+UV4458ltwSK0RjGRotVWzg7u0tG22uBGu75M59s/ 4HTiqCo2VCH3zmdWFuzWJbHbtJjhHBkgvwmPQVmi63111XXZo1Sj0Ar4DeLb3G3S3x S1a2v2CRfGphH2pnU1Ea6qQYRm2KdGIxw1MzVmxY= 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 CD3DB385C6FC; Thu, 7 Dec 2023 05:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD3DB385C6FC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CD3DB385C6FC 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=1701928595; cv=none; b=dorMfNU/4nfxtzCYRt+WpDTbjMkM/gu6Ibyrcpc/Xi3eiVHmlYSAPeZe0kTy3nta5+39SNi/gonWr47FT3jdPOg+c9wrS1oN2r2Xm8f1fzMOk5AfQVhUJs0992L4s1Xcin+rrAyZREqc2qSXjHNF3P/yHQuLai6YR8Xcj1VDJq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701928595; c=relaxed/simple; bh=hzTdHXFqA2VXyzDdRgErAkGU4JBEIxEcO3xg7yxGjF8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VGosSmffY+gDffeb+aTwqNgTYYvaTNwIoLM8O+zcT6F6wfsrc+LH3xQ6h7+0jmtFJjYg74Eit7BRWjDLCVxpKh7expRQXYrS1X7jZC9EYyazNzM9wgp3S5V6oq3JWnTn2TLGLJOeRCrCrm9rW4ejoXpB9WBKsXeZamUbfnmO+uQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B75rSRL005101; Thu, 7 Dec 2023 05:56:34 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3uu12qb5qq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2023 05:56:34 +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 3B75uLOc017762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Dec 2023 21:56:21 -0800 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.154.75.142]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 3B75adQO020981 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 21:56:21 -0800 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 v26 23/23] libstdc++: Optimize std::remove_pointer compilation performance Date: Wed, 6 Dec 2023 21:33:18 -0800 Message-ID: <20231207053633.1001720-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207053633.1001720-1-kmatsui@gcc.gnu.org> References: <20231024020424.699427-1-kmatsui@gcc.gnu.org> <20231207053633.1001720-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Gaa4jBrSLGerLw6DliuULhPeq7MT6fZW X-Proofpoint-GUID: Gaa4jBrSLGerLw6DliuULhPeq7MT6fZW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-06_20,2023-12-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=566 phishscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 mlxscore=0 malwarescore=0 clxscore=1034 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312060160 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, T_SCC_BODY_TEXT_LINE 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: 1780601483466351462 X-GMAIL-MSGID: 1784601525720423321 This patch optimizes the compilation performance of std::remove_pointer 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 2979d79a801..f00c07f94f9 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2089,6 +2089,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; }; @@ -2097,11 +2103,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