From patchwork Tue Oct 17 11:27:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4067542vqb; Tue, 17 Oct 2023 04:34:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUKwHdHxZiqouALjOvkRzGZnPrLT3sdRDQTxVCGjj05c2tR7C+CndZ/WjyKCZzQVoD5bUF X-Received: by 2002:a05:620a:a18:b0:774:1c49:2d72 with SMTP id i24-20020a05620a0a1800b007741c492d72mr1746642qka.76.1697542462441; Tue, 17 Oct 2023 04:34:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542462; cv=pass; d=google.com; s=arc-20160816; b=YKej9p+37m1Rb85d0b0RqwSd4qZKjZWTsIuEOZ+z2LStTSQ+wKtoA8cTE9qzyW8IZ/ Kt46CVdT45G6swjFit35Qt85E0mPmKKFWfCcFXPGZo0jOgZpZdPPszariXDe5MTxYfMd XoEe7N+eersb6va7emEvHn5TyLAziS1sPPq/WwwPVLwSqCFY1h3BwNBxmo2hfhcRqYcP hWE9dQKGgiKtgwF4zmA2JOrvE/8KFN4cP9hVLSLv6ht2IceRsEsQEcpDq02w6VZy56hO mUTQv4CN6ZLZSNPr7sgRkPd+KReb016UTJ3QRZouIHvzyJLFyqBpdJ4KmuoQuDtVQlJZ ECGw== 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=XzQ6JaLHSfbRkzy9sMHe6fCo10/gBbC7RRRFQ9rcaoo=; fh=gWaPAOlkBn4NfXWp5OzPJhAUieocQfCW2y/drQDuE0I=; b=b6AhHGazgBq9UTqR0yPURDlBU6vJvjP/hF+wDdJq9q3dFymhnxEXlStVT2COu/iXZN S3kJBL/H+Rr9njYIpxhprdkEOStmzdbdu7pZwNftnNJfvyY5E/99uTSmAi8JIjRqK20s vxxdS0VOEJj6G9bGh2vE8kH+IgN3V3rx0aBVIuO7qRktDYLKZBewfK4Pd6OvTfrqyR6i CxxDypgatf0H/TIVChhIYszJ+aLq2NI8CwZqeYzo278LH9DOad4yWi17jxqq3QBG+Pnh 3oRcAKdXF/yo8L3nQPJPmikHoaz6vfr+iISYCG+9XiT0H3nxIJhsbsn+MSbWg3KKk6Fx XHww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LFQ27aVF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g3-20020a05620a218300b00774382daec1si904754qka.536.2023.10.17.04.34.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LFQ27aVF; 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 2CB9F3858418 for ; Tue, 17 Oct 2023 11:34:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CB9F3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542462; bh=XzQ6JaLHSfbRkzy9sMHe6fCo10/gBbC7RRRFQ9rcaoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LFQ27aVFo4Quh31QT/TqlxMAHpNsR1Rq96BLEPFX7Au4vA1/IpSVBGfbRks9aiXGS GeQlFAIrDm9IIQoaVjQ/d0fAhzaNJiEJBlKo52nEwUOIKZilkoKT1HNUAJIBxKPaSK LZMNV0TcemnBBFXvf28j8pMv9cwtIhB6oVC+vBMc= 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 0EC233858C52; Tue, 17 Oct 2023 11:33:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EC233858C52 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 0EC233858C52 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=1697542419; cv=none; b=qPUKp/78+b7YwhWi0HQyOJBHNtiaij59ZawczjIkR8MILLxahe8Pug9DLFhFGnk9P3LJMivwkvMKRO9WT7MH1d5ZXE4X8WyMu4hrAQar4shSjKUB7p2l5qfCf/rjlxVwF2eJMtRhweCbo14jerQLJwEf4/A4bkmh03SKQniOGpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542419; c=relaxed/simple; bh=a9doAL8xaU26Jq7Wrb8cklSUyV+ncv7L4Jw4Kidz8BU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=I61tDBXuo+MYLKTNT9n5ed13202Sc0DrkIKPs7jPBQZ6P5z32sVFc5TGfnxhpASGy5eZxhhF5eMIjTm/ugGGn6eEc4cniOvkdMDVYZG0OzND72+14KvTwRT49zqCteRMmev1nIlSsn6x/6qM8ynZz3BurePuWtEEXTcF0NTP2BM= 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 39HBTqDM023863; Tue, 17 Oct 2023 11:33:35 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tseh6tra5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:33:35 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBXIFF011883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:33:18 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiME001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:33:18 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Patrick Palka Subject: [PATCH v21 01/30] c-family, c++: Look up built-in traits via identifier node Date: Tue, 17 Oct 2023 04:27:32 -0700 Message-ID: <20231017113242.664523-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: PiYVRsMQrHhSCtU2HLGHFD3yy0qsqo0l X-Proofpoint-GUID: PiYVRsMQrHhSCtU2HLGHFD3yy0qsqo0l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1034 mlxscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779868979596920251 X-GMAIL-MSGID: 1780002284860666338 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. (num_cp_traits): New variable to hold the size of cp_traits. (cik_reserved_for_udlit): Rename to ... (cik_trait): ... this. (IDENTIFIER_ANY_OP_P): Exclude cik_trait. (IDENTIFIER_TRAIT_P): New macro to detect cik_trait. * lex.cc (init_cp_traits): New function to set cik_trait and IDENTIFIER_CP_INDEX for all built-in trait identifiers. (cxx_init): Call init_cp_traits function. * parser.cc (cp_traits): Define its values, declared in cp-tree.h. (num_cp_traits): Define its value, declared in cp-tree.h. (cp_lexer_lookup_trait): New function to look up a built-in trait by IDENTIFIER_CP_INDEX. (cp_lexer_lookup_trait_expr): Likewise, look up an expression-yielding built-in trait. (cp_lexer_lookup_trait_type): Likewise, look up a type-yielding built-in trait. (cp_keyword_starts_decl_specifier_p): Remove all RID value cases for built-in traits. (cp_lexer_next_token_is_decl_specifier_keyword): Handle type-yielding built-in traits. (cp_parser_primary_expression): Remove all RID value cases for built-in traits. Handle expression-yielding built-in traits. (cp_parser_trait): Handle cp_trait instead of enum rid. (cp_parser_simple_type_specifier): Remove all RID value cases for built-in traits. Handle type-yielding built-in traits. Co-authored-by: Patrick Palka Signed-off-by: Ken Matsui --- gcc/c-family/c-common.cc | 7 --- gcc/c-family/c-common.h | 5 -- gcc/cp/cp-objcp-common.cc | 8 +-- gcc/cp/cp-tree.h | 33 ++++++++--- gcc/cp/lex.cc | 21 +++++++ gcc/cp/parser.cc | 120 +++++++++++++++++++++++++------------- 6 files changed, 129 insertions(+), 65 deletions(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index f044db5b797..21fd333ef57 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -508,13 +508,6 @@ const struct c_common_resword c_common_reswords[] = { "wchar_t", RID_WCHAR, D_CXXONLY }, { "while", RID_WHILE, 0 }, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - { NAME, RID_##CODE, D_CXXONLY }, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* An alias for __is_same. */ - { "__is_same_as", RID_IS_SAME, D_CXXONLY }, - /* C++ transactional memory. */ { "synchronized", RID_SYNCHRONIZED, D_CXX_OBJC | D_TRANSMEM }, { "atomic_noexcept", RID_ATOMIC_NOEXCEPT, D_CXXONLY | D_TRANSMEM }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 1fdba7ef3ea..051a442e0f4 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -168,11 +168,6 @@ enum rid RID_BUILTIN_LAUNDER, RID_BUILTIN_BIT_CAST, -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - RID_##CODE, -#include "cp/cp-trait.def" -#undef DEFTRAIT - /* C++11 */ RID_CONSTEXPR, RID_DECLTYPE, RID_NOEXCEPT, RID_NULLPTR, RID_STATIC_ASSERT, diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 93b027b80ce..b1adacfec07 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -421,6 +421,10 @@ names_builtin_p (const char *name) } } + /* Check for built-in traits. */ + if (IDENTIFIER_TRAIT_P (id)) + return true; + /* Also detect common reserved C++ words that aren't strictly built-in functions. */ switch (C_RID_CODE (id)) @@ -434,10 +438,6 @@ names_builtin_p (const char *name) case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: -#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT return true; default: break; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index efcd2de54e5..81a5c06a574 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1226,7 +1226,7 @@ enum cp_identifier_kind { cik_simple_op = 4, /* Non-assignment operator name. */ cik_assign_op = 5, /* An assignment operator name. */ cik_conv_op = 6, /* Conversion operator name. */ - cik_reserved_for_udlit = 7, /* Not yet in use */ + cik_trait = 7, /* Built-in trait name. */ cik_max }; @@ -1271,9 +1271,9 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is for any operator name (including - conversions). Value 4, 5, 6 or 7. */ + conversions). Value 4, 5, or 6. */ #define IDENTIFIER_ANY_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE)) + (IDENTIFIER_KIND_BIT_2 (NODE) && !IDENTIFIER_TRAIT_P (NODE)) /* True if this identifier is for an overloaded operator. Values 4, 5. */ #define IDENTIFIER_OVL_OP_P(NODE) \ @@ -1286,12 +1286,18 @@ enum cp_identifier_kind { & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion - operator. Value 7. */ + operator. Value 6. */ #define IDENTIFIER_CONV_OP_P(NODE) \ (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ & (!IDENTIFIER_KIND_BIT_0 (NODE))) +/* True if this identifier is the name of a built-in trait. */ +#define IDENTIFIER_TRAIT_P(NODE) \ + (IDENTIFIER_KIND_BIT_0 (NODE) \ + && IDENTIFIER_KIND_BIT_1 (NODE) \ + && IDENTIFIER_KIND_BIT_2 (NODE)) + /* True if this identifier is a new or delete operator. */ #define IDENTIFIER_NEWDEL_OP_P(NODE) \ (IDENTIFIER_OVL_OP_P (NODE) \ @@ -1375,16 +1381,27 @@ 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. */ +extern const struct cp_trait cp_traits[]; +extern const addr_space_t num_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..872ca970545 100644 --- a/gcc/cp/lex.cc +++ b/gcc/cp/lex.cc @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" static int interface_strcmp (const char *); +static void init_cp_traits (void); static void init_cp_pragma (void); static tree parse_strconst_pragma (const char *, int); @@ -283,6 +284,25 @@ init_reswords (void) } } +/* Initialize the C++ traits. */ +static void +init_cp_traits (void) +{ + tree id; + + for (unsigned int i = 0; i < num_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 +344,7 @@ cxx_init (void) input_location = BUILTINS_LOCATION; init_reswords (); + init_cp_traits (); init_tree (); init_cp_semantics (); init_operators (); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 59b9852895e..ece238c2072 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,6 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; +static const cp_trait *cp_lexer_lookup_trait + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_expr + (const cp_token *); +static const cp_trait *cp_lexer_lookup_trait_type + (const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -279,6 +285,21 @@ static FILE *cp_lexer_debug_stream; sizeof, typeof, or alignof. */ int cp_unevaluated_operand; +/* The trait table, declared in cp-tree.h. */ +const cp_trait cp_traits[] = +{ +#define DEFTRAIT(TCC, CODE, NAME, ARITY) \ + { NAME, CPTK_##CODE, ARITY, (TCC == tcc_type) }, +#include "cp-trait.def" +#undef DEFTRAIT +}; +const addr_space_t num_cp_traits = ARRAY_SIZE (cp_traits); + +/* The trait table cannot have more than 255 (addr_space_t) entries since + the index is retrieved through IDENTIFIER_CP_INDEX. */ +static_assert(num_cp_traits <= 255, + "cp_traits array cannot have more than 255 entries"); + /* Dump up to NUM tokens in BUFFER to FILE starting with token START_TOKEN. If START_TOKEN is NULL, the dump starts with the first token in BUFFER. If NUM is 0, dump all the tokens. If @@ -1167,12 +1188,6 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) case RID_CONSTEVAL: return true; -#define DEFTRAIT_TYPE(CODE, NAME, ARITY) \ - case RID_##CODE: -#include "cp-trait.def" -#undef DEFTRAIT_TYPE - return true; - default: if (keyword >= RID_FIRST_INT_N && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS @@ -1182,6 +1197,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 @@ -1190,6 +1243,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); + if (cp_lexer_lookup_trait_type (token)) + return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -2854,7 +2909,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 @@ -6029,12 +6084,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); @@ -6073,6 +6122,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: @@ -11041,28 +11093,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; @@ -20089,20 +20126,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 Tue Oct 17 11:27:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4068300vqb; Tue, 17 Oct 2023 04:35:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUmYsn+3xgQ5vEwJ91XFXpC/qBOP2XRm2dmpwB6zf5bT3Y0vL1bmBYAZ61/IFaTv2JMDvl X-Received: by 2002:ac8:7d4a:0:b0:418:21ad:fafe with SMTP id h10-20020ac87d4a000000b0041821adfafemr2605193qtb.28.1697542551103; Tue, 17 Oct 2023 04:35:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542551; cv=pass; d=google.com; s=arc-20160816; b=CRYwuFegIrDsVuYAwukSugrwSsVGmr0PGHpztAEmjgye/eweSdeH0f/ucCud+QLTu8 M9oaHEXHMcCoi9/TVFjnKK3ZZcDa3yZmKQFPcfzYzJoo8AAiU7WdT8isXQHxL1mDkl5u k9oevkok4EWdU5Ab4xqL0ej9xLEzf/jSVR0aDBQx6qpdIFVcUCtFYLIIaYOJHHxxKrFr Oc2S0nY3WoDL8JqYFgGZom1DLY1uojHlFYOgSM3mC6DLFRY2ZY15bmoL3s9Q7ro7Wp8D vf2qwWJUkoDVwODek5FqG/Row+IpTAXRtwvaW5qyF0gTugKTVomfbB40kkUQfgj9c/zg O9iA== 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=12dNqlgpFeavMSJPZSk02QTDoCt42Gr025LrayzUMxc=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lyB+FUZnA8YD0D42KN7uqOitgBPA6ri2/IRIrGVR/glU7cA+1GfjahOYfj9D5YLQ+s UbSldzBEQ5giI2p18YPzau0T4lyWekJJYkcmE6RhWH/9E86o70KxvHcg4eB6cqWPUzKZ Pn2Km4H22yXlCL/01oQAi1nHkdD731FWWi5cW/cznm1YW3KOPZQCxFjOz8VI8duZNdda 46Nwu7DzmKGEHGSAQW1/Yr9U13xJju1dY8LzoLi1pTzW/M6l4ztAh9PDV+aVRfaGybNr ChixUTXp8Bfjr4c9pWXAdSxcGZrkDn2mRob+YjG+Hd6d1qn+vmeJgzdDpafjzPvDjDou sOpQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nAj4UGB5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k22-20020ac85fd6000000b0041812c64671si952545qta.487.2023.10.17.04.35.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:35:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nAj4UGB5; 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 D05B83857359 for ; Tue, 17 Oct 2023 11:35:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D05B83857359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542550; bh=12dNqlgpFeavMSJPZSk02QTDoCt42Gr025LrayzUMxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nAj4UGB5RsNdFhMO83gFOnbw8+qXaKCBdHk+kArKeZ3wrv2iSNuvP4Xb5PX+ENd1j b9/1QCHcOuTDMcp6u4Y9YI/5yryP0aF/+Emq9k3ibWOXX6EYLeNTB/q3CWdURvtG1i 8nUGbKK8xSNDNIOMlIGaNJEwXARvrlAeyTmCE4Uk= 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 1E3C83858D38; Tue, 17 Oct 2023 11:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E3C83858D38 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 1E3C83858D38 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=1697542506; cv=none; b=s9nYlsbGOJKcCin4y2bk5b2bbEggao/fjpazFGxJmbQWWzEvk9L4Ek1dFhj9EiikutK9ok0a+Nl3I0MaxKmiQal4BQ8QeCfMuRf3hZHYDANk7y1Upn8VkuN+FlHvHaQpAB9niW0qY30e+9yoehR4fIBTGBA5LonN/rldEnxRsv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542506; c=relaxed/simple; bh=RfJ8hl0s/l6P20aQsfKPF76bH6h8zlFHEJKAl6sYyao=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=S+ewVFJ8d1xbdaKrOsuK6ZUZo1DGGZ6QQIHn9yXLtjMq/5A/mywiWB+uayfdb3vnwNJIrtTX4DmZiA82K/0NGDttM1HVYYGqd8Xo+Gp0TGpP4+mcq0o+icK/iOHrn7Rcm+4wg4qd/kiVKiznCNwkhyOH9SSswLL+LkVhc3Mc4hY= 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 39HBQcNr005527; Tue, 17 Oct 2023 11:35:04 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf8x2eke-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:35:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZ1vP017648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:01 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMF001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 02/30] c++: Accept the use of built-in trait identifiers Date: Tue, 17 Oct 2023 04:27:33 -0700 Message-ID: <20231017113242.664523-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 3VumQg3MgSvFXasCrGmrYPFxZ6HY3lA1 X-Proofpoint-ORIG-GUID: 3VumQg3MgSvFXasCrGmrYPFxZ6HY3lA1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1034 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779681961607250764 X-GMAIL-MSGID: 1780002378527606293 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 | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index ece238c2072..e4c45190313 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -246,12 +246,12 @@ static void cp_lexer_start_debugging (cp_lexer *) ATTRIBUTE_UNUSED; static void cp_lexer_stop_debugging (cp_lexer *) ATTRIBUTE_UNUSED; -static const cp_trait *cp_lexer_lookup_trait - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_expr - (const cp_token *); -static const cp_trait *cp_lexer_lookup_trait_type - (const cp_token *); +static const cp_trait *cp_lexer_peek_trait + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_expr + (cp_lexer *lexer, const cp_token *); +static const cp_trait *cp_lexer_peek_trait_type + (cp_lexer *lexer, const cp_token *); static cp_token_cache *cp_token_cache_new (cp_token *, cp_token *); @@ -1197,15 +1197,27 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword) } } -/* Look ups the corresponding built-in trait if a given token is +/* Peeks the corresponding built-in trait if a given token is a built-in trait. Otherwise, returns nullptr. */ static const cp_trait * -cp_lexer_lookup_trait (const cp_token *token) +cp_lexer_peek_trait (cp_lexer *lexer, const cp_token *token1) { - if (token->type == CPP_NAME && IDENTIFIER_TRAIT_P (token->u.value)) - return &cp_traits[IDENTIFIER_CP_INDEX (token->u.value)]; + 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; } @@ -1213,9 +1225,9 @@ cp_lexer_lookup_trait (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_expr (const cp_token *token) +cp_lexer_peek_trait_expr (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && !trait->type) return trait; @@ -1226,9 +1238,9 @@ cp_lexer_lookup_trait_expr (const cp_token *token) built-in trait. */ static const cp_trait * -cp_lexer_lookup_trait_type (const cp_token *token) +cp_lexer_peek_trait_type (cp_lexer *lexer, const cp_token *token1) { - const cp_trait *trait = cp_lexer_lookup_trait (token); + const cp_trait *trait = cp_lexer_peek_trait (lexer, token1); if (trait && trait->type) return trait; @@ -1243,7 +1255,7 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) cp_token *token; token = cp_lexer_peek_token (lexer); - if (cp_lexer_lookup_trait_type (token)) + if (cp_lexer_peek_trait_type (lexer, token)) return true; return cp_keyword_starts_decl_specifier_p (token->keyword); } @@ -6122,7 +6134,8 @@ 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, token)) return cp_parser_trait (parser, trait); /* FALLTHRU */ case CPP_SCOPE: @@ -20131,7 +20144,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, } /* If token is a type-yielding built-in traits, parse it. */ - const cp_trait* trait = cp_lexer_lookup_trait_type (token); + const cp_trait* trait = cp_lexer_peek_trait_type (parser->lexer, token); if (trait) { type = cp_parser_trait (parser, trait); From patchwork Tue Oct 17 11:27:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4070285vqb; Tue, 17 Oct 2023 04:40:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLxUgV+BxzDc0QDA3zlTWMR/Iy0yh1IN+yzSl1BLit5neq98nBpv3QaJfcNJRSXtgxYUY3 X-Received: by 2002:a05:6214:daf:b0:66d:15c3:62cb with SMTP id h15-20020a0562140daf00b0066d15c362cbmr2490326qvh.36.1697542820542; Tue, 17 Oct 2023 04:40:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542820; cv=pass; d=google.com; s=arc-20160816; b=L8XqXV9VHIyiiyWwuPQQvztyi2U59EWjtJogfwSPjWI/1+3b3KfrHfRqo30LEilqw5 gXTdwjGtrRm2NlHDhuZPD4vARxe2ViQyOOWQYbbQeN8ktl012ujy/hMIE/UM+iH7Yt2U iB852OV1PBQz2JKuANsQ8qfK2SFEEBZkWlfVhtwJg6BBhGoMkSaJ6rO2cru+TH6aRWO7 DZtiamDWBMsu82JEXPIAZnSb6wHsrNmuos57C8oxSQXgGXBq/jTI2YApzymcDMmOKrnO HWt6Lz0JCLHYPGqfQw3oejEwr2iFRUb4HzH1ZBs1p/+nu1AqXAfuxw7Zbp0xnKKRn+M+ W3cw== 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=YFgz3JKa50S1VxfkIDu3wJrOJMs1VKbfdao+QHPwjHE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=cvE5TEGSIdaraPwTGNcCi4EQFSciLSxSuF3+Vtl7KlXqi+/TkLwLTCodgEcwBIYZaq UNm7pZGfO+A80ntOsRRS8SZ8mU9UcBjeHmedY5HrLzNgBBfWmdRFDOzHTFY2Xm/IMV5G qaDJV7LSZdNWj5w9VDOYzwwP8Tzm+etOdmoV0qF8me+5I5aObnVX62yywE1OpTUXKzQh B0VB8hoBcCZy8z5UXJeu56C43ruFzLC/T22qcjOY1jUxqYD5FRt+jv2Mn8/TAzEqPsav no3xmYGC2hcv4LQy1neb5Ly4183ETtGAvlBQr8dbKmLOH3mItf+yk/FUs3YgUN0bA1Dv XR+Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NHSsbOoW; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id pz28-20020ad4551c000000b0066d20b83674si812830qvb.75.2023.10.17.04.40.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NHSsbOoW; 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 5FFCE385C8B1 for ; Tue, 17 Oct 2023 11:39:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FFCE385C8B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542777; bh=YFgz3JKa50S1VxfkIDu3wJrOJMs1VKbfdao+QHPwjHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NHSsbOoW5++wbs8itcfhoEaF4ef5uo+3+wCzEkxuAht4GZd50YfQxp+Gv5NhdLDTh twe4fUX1WjGFAwLUtJzp2meir92yX88AWPZ3yEfdcrTkKeDYTS71s663tNmEM656u1 jAhkjb/g9IY8zZlXcDWLikS2Ngwsb1bo1i32H4io= 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 466DD385701B; Tue, 17 Oct 2023 11:35:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 466DD385701B 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 466DD385701B 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=1697542548; cv=none; b=ttcyldk6oyZYOnP/OK37uSib59o+3BFMj7cNRqgsjxuPv78q9hXWutmWsorEn+UGP01VW2d1Z/A5sYs5B1UvzJcJ2ne13/wv7VwmKsY4kHzaNuL8K6cmLFmSpGKIn4DHyNPzdDuzdXIAqEeUf7TerOTGe809cjYTGLNc611pEuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542548; c=relaxed/simple; bh=Nhkst8uA8uBdTogdmoRZMARPpCFeWcQCWm0H9ZsIAxs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=uvi6Bbsdo7a+9+XMY2vDtTFoAXRWIg01OI05QDKcNQ3nJIO+Qwks8QidgZTZBbd2pp0jgETPNUHYuq4cd46cLD6AeE3V3PrLobah6G0wxemrCVSZLlByNDF43kGAnuN/ynBObxcuqexZzPtgT80NZKxsa4ojEE7qbCImI4vbZjs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBO6tD028389; Tue, 17 Oct 2023 11:35:47 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruvda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:35:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZidZ028994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMG001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 03/30] c++: Implement __is_const built-in trait Date: Tue, 17 Oct 2023 04:27:34 -0700 Message-ID: <20231017113242.664523-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jjEqS9PnBlVMC6jOXjzpj89wQXmFQdpz X-Proofpoint-GUID: jjEqS9PnBlVMC6jOXjzpj89wQXmFQdpz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=937 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996525378678276 X-GMAIL-MSGID: 1780002660419619811 This patch implements built-in trait for std::is_const. gcc/cp/ChangeLog: * cp-trait.def: Define __is_const. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_const. * g++.dg/ext/is_const.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_const.C | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_const.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 41fe2812ac4..41d9eef7227 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3724,6 +3724,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; + case CPTK_IS_CONST: + inform (loc, " %qT is not a const type", t1); + break; case CPTK_IS_CONSTRUCTIBLE: if (!t2) inform (loc, " %qT is not default constructible", t1); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 0e48e64b8dd..9e4e6d798a0 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) +DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 144cb440fa3..7fbcfd7ccad 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); + case CPTK_IS_CONST: + return CP_TYPE_CONST_P (type1); + case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); @@ -12371,6 +12374,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_CLASS: + case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 2223f08a628..e6e481b13c5 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif +#if !__has_builtin (__is_const) +# error "__has_builtin (__is_const) failed" +#endif #if !__has_builtin (__is_constructible) # error "__has_builtin (__is_constructible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_const.C b/gcc/testsuite/g++.dg/ext/is_const.C new file mode 100644 index 00000000000..8f2d7c2fce9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_const.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_const(const int)); +SA(__is_const(const volatile int)); +SA(__is_const(cClassType)); +SA(__is_const(cvClassType)); + +// Negative tests. +SA(!__is_const(int)); +SA(!__is_const(volatile int)); +SA(!__is_const(ClassType)); +SA(!__is_const(vClassType)); From patchwork Tue Oct 17 11:27:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072118vqb; Tue, 17 Oct 2023 04:44:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHE3GxsKHF+T4PPjgiKIn4cCsFk5hA3fnlo2jL2ZI3rrQMeQBJsw04Ny6qsbPKGBSfvaEmU X-Received: by 2002:a25:d14e:0:b0:d9a:c28f:274 with SMTP id i75-20020a25d14e000000b00d9ac28f0274mr1811757ybg.31.1697543097458; Tue, 17 Oct 2023 04:44:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543097; cv=pass; d=google.com; s=arc-20160816; b=fVSU56cwaATNwReIfHwKy6DlQK2giNTrMQWbWFHdM2nj2mxrwVVoN30eWp4eXdpClq g7ppTIctvJ5/NCZkCJd846/I5BXpe3+BIG7vzhM2Z9VcLvYimAC8pCv/MEvSi4F/aAgp 3JqO6HfWVCifIawpWQWSoJSnMKv5+GFWRs094eMw3DU0J4Jfg/0AhPjZLj45Vu2dVQUg JWrkgRYtg6fllpFfwGU3cKB+7JY0p8F2k9CAU2iM/soCPOVFDgQRp0l6FWGh50wU7MSq vsfkDJ4eg899W9wbIoeuKE2E0ECAwVVNLAKs0nlSg4EXB3mhtNQwZRioOI0i9v6/6v7Y svyw== 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=qyC6olmDOD3xclF1RvY+2S0/j2J8XJ5zV7CYrN+e5lQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=oR+16AYc/UGU6thk34G/4ojd6WCbV8aei2N06symZR2+voaE/R/u7B8QVTe5XAke8Q kqxKI639cduF5pX160KbDHyLS2NLsHKi9lgCcgGareDAcDKxrrS88kJn/WYLCjmyEt6Q noI/QC6YWeTmvWOg4JkllgEAO4wp97NiWH2pfXjE845GscBSkDyzq7a9dEigCsTPhaHH 0DbW4+0oALPA3Rc4p3MHaw2l+lb8YGG+fDgkGI6TmQIPlcSDMjeXJH4/0jF7Cdwp5+40 9S2y8h4vL+GQxZhBSFoZZhwk0RBj5ERBfPDhwDJ52GJJBpQV6yxDfBN5oHx9sa9cNzfX Wnfg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DYVvzbGz; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ep20-20020a05621418f400b0065b282ad457si837016qvb.168.2023.10.17.04.44.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:44:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DYVvzbGz; 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 85D28388215C for ; Tue, 17 Oct 2023 11:43:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85D28388215C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543016; bh=qyC6olmDOD3xclF1RvY+2S0/j2J8XJ5zV7CYrN+e5lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DYVvzbGzSJcB1jFtI4d581EXwLplg3sBuBuQ68g32SXkaqf/VqLaE29ktlbCzOrXS +JBfEybm0K4ZlO/SL0iJvlQg1txosZ9J6brRGZDODg/3cyxdUENCIvUI8eMc+TmGdL oGg8Re8Md5lCw4B873RjrNhSNket3jv62ne1v1Aw= 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 5DF3C3856251; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DF3C3856251 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 5DF3C3856251 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=1697542568; cv=none; b=XdPOSA0Os6U4AkrLyqCi4ObIbRpOzohzOLbc0l/s+xMs58F4WE4mw9R6ilik3on3UHbJSTs2y0p19UsPxchLpD9C5So5Ae+eTV/3G9VEuLNuaTQfstiw7AJ3xNLUPLryMbnVFCVFpO3Hf6wzAlx7X3XXkHByer2PdlCQKrbm5Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542568; c=relaxed/simple; bh=/1qcFEm4P/QLiMl/jAKWkbnYQhruObr98IEbIB0r71U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=eFtdDguyOcVr+o3cZINZYC4HlmKmDpHcupKAFXuOP8/werQfwFr13vtnkO0N+0n372a8QHKOqzVvLhFFxhuWFFkXcAZaWHRZOTOvCjNSsocw3H2Nb8Vg9s2dT+MDGXdxXNOXPTeIUh3rHH6JDpXDJEx0WTVwCLErl/wpuIO/Xbw= 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 39HBVrMu013824; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40afvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZieY012234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:44 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMH001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 04/30] libstdc++: Optimize std::is_const compilation performance Date: Tue, 17 Oct 2023 04:27:35 -0700 Message-ID: <20231017113242.664523-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Oil9W7XAhoDsK5izRDAC-on5frkCBvbL X-Proofpoint-ORIG-GUID: Oil9W7XAhoDsK5izRDAC-on5frkCBvbL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=765 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002951185557558 X-GMAIL-MSGID: 1780002951185557558 This patch optimizes the compilation performance of std::is_const by dispatching to the new __is_const built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_const): Use __is_const built-in trait. (is_const_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..686e38e47c3 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -784,6 +784,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Type properties. /// is_const +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) + template + struct is_const + : public __bool_constant<__is_const(_Tp)> + { }; +#else template struct is_const : public false_type { }; @@ -791,6 +797,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_const<_Tp const> : public true_type { }; +#endif /// is_volatile template @@ -3218,10 +3225,17 @@ template inline constexpr bool is_compound_v = is_compound<_Tp>::value; template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) +template + inline constexpr bool is_const_v = __is_const(_Tp); +#else template inline constexpr bool is_const_v = false; template inline constexpr bool is_const_v = true; +#endif + template inline constexpr bool is_volatile_v = false; template From patchwork Tue Oct 17 11:27:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4070954vqb; Tue, 17 Oct 2023 04:41:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpwWUUFxdUUyIbUiWhXB+J5qTCK8jtHe/0+UMGL49Q95QDv59mMR0lLJ+uwGOVt7AKh5we X-Received: by 2002:ac8:4e4a:0:b0:418:d18:56ae with SMTP id e10-20020ac84e4a000000b004180d1856aemr2363172qtw.25.1697542916028; Tue, 17 Oct 2023 04:41:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542916; cv=pass; d=google.com; s=arc-20160816; b=jiNvhtkPJe8cYWkBrsxqJsvPdMCHPzVJMrCh55emi12kqmDb779xxgOEbzVZsToYGF 5k2FUflMLYaPSPIjx2mrTfGDWD/YgsBHaiHASQdg7qe8EL7fgmOxFlaccrNO6vnzbF0c spi1Ejd875VVhP2aBe3bF1wj/Lqivxzr5NRPPel9PUqeDho4LvPIfaNBrqde4+mvU3Gt gnIK++wo1qhc4/VXPknAZbpW44qY7QEifiCnSGXSx59I25ExELCOY8Jyea8EZFfxOMWY xscURK9ctWI8Mr1rN/YpqZwKyxt1a50dns3AYYZ4HHrZCoGHhVChXsQa5Z+DJlhZkUNm lJ7Q== 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=GHfL9y42s9AOw4KCQO/a6ZjHqW2NAxHIAkgovCmo5GI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=LMwMeA3IOIAzvgKQv8MWYgasx1rlg1c1IG7JaJWwY6/Nbh00K5Hts5Jya1IYdDA0e8 r8sHFqzK8BD7M2if8dtMYS0lIOMp0cueAsijyR8xg74jl3iDVgIwGJk6pCBJdkVjeHrR mPkIiVFzlC6xHFtKILej1mP+smRZ9AHnt5+ovSIQv1Aj6FpJ4nPjt6t2m58vaXVIwZeW joXPV63wHW1V2p/7RYMn4SMYcp+fm0Ykm1hQvcKCxqgLR7jErE0PcNxS6og0d+hDUQs+ IepXm8V7KDsCY/wlk6t1BTVip7EwxMfrmzU2gA9gAVe0+Bmaj0ySVAso4vuJ4IpTv16f 1Xhw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cihdEcwk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 1-20020ac85741000000b00417f199f9e5si986907qtx.738.2023.10.17.04.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cihdEcwk; 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 464C23853511 for ; Tue, 17 Oct 2023 11:41:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 464C23853511 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542860; bh=GHfL9y42s9AOw4KCQO/a6ZjHqW2NAxHIAkgovCmo5GI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cihdEcwkZjIQAZ3WvxO3H8rp5OSbai8zCoNTS4+BwHtof/8BaHGauYkx26GwD8oFt HxZZ4pmvbZ8eA/MS3TnKb9SUI6clN6cyv/3hfhotiQB8dtA5qCSvSfKZA06TeaX3oL wwqO9odyAn5of8N/f6AZ973F3hnOx4NtmIHIuBJg= 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 42DB4385703F; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42DB4385703F 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 42DB4385703F 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=1697542569; cv=none; b=j9YMLeAcDiEg1aEohdPjU1FPjgkDaps42JVxKRk5os10JMjE5gg8+cTg1qFcLv9jxSvdXCV1/Ec9wdn30kOm/96h9SMCYn7JXUN+3BtfDzaLUn0ERUYU3cm1gLGgfT6ySGJrRkJXF66RsrlnRsWHN9tru3/fi1EZlqgDVPJeUFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542569; c=relaxed/simple; bh=1rHsyPoqaQXKsQOFdJbK+nBdkfKdFE5DDiprWTj+Wuk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UxapwhXIrBylZx1rBJHwJfDbIYyVm1607/DNdDVumFzfv+O6tqWr4OwjBehCc4cAiCY6aea9uxVxyKWBacTQKvpIbm0HO/GDmj5N3xWb3yXaHEoJ5r5cdS5u45kZmJANe3oYAXNT6Adg2KdpVqjq2tKPjbJg4vUCdWKzSTIToXw= 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 39HBX1rm016916; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf8x2eqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjb8006890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMI001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 05/30] c++: Implement __is_volatile built-in trait Date: Tue, 17 Oct 2023 04:27:36 -0700 Message-ID: <20231017113242.664523-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: G3q8M4BlD47M0X72mRByInE0xCLTSLbV X-Proofpoint-ORIG-GUID: G3q8M4BlD47M0X72mRByInE0xCLTSLbV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=909 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1034 mlxscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996916785922643 X-GMAIL-MSGID: 1780002760554764212 This patch implements built-in trait for std::is_volatile. gcc/cp/ChangeLog: * cp-trait.def: Define __is_volatile. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile. * g++.dg/ext/is_volatile.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++ gcc/testsuite/g++.dg/ext/is_volatile.C | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_volatile.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 41d9eef7227..54782a167dd 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3797,6 +3797,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_VOLATILE: + inform (loc, " %qT is not a volatile type", t1); + break; case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: inform (loc, " %qT is not a reference that binds to a temporary " "object of type %qT (direct-initialization)", t1, t2); diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 9e4e6d798a0..d786f47e60c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7fbcfd7ccad..7726fa99711 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_VOLATILE: + return CP_TYPE_VOLATILE_P (type1); + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: return ref_xes_from_temporary (type1, type2, /*direct_init=*/true); @@ -12378,6 +12381,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_SAME: case CPTK_IS_UNION: + case CPTK_IS_VOLATILE: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e6e481b13c5..fb03dd20e84 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif +#if !__has_builtin (__is_volatile) +# error "__has_builtin (__is_volatile) failed" +#endif #if !__has_builtin (__reference_constructs_from_temporary) # error "__has_builtin (__reference_constructs_from_temporary) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_volatile.C b/gcc/testsuite/g++.dg/ext/is_volatile.C new file mode 100644 index 00000000000..004e397e5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_volatile.C @@ -0,0 +1,19 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +// Positive tests. +SA(__is_volatile(volatile int)); +SA(__is_volatile(const volatile int)); +SA(__is_volatile(vClassType)); +SA(__is_volatile(cvClassType)); + +// Negative tests. +SA(!__is_volatile(int)); +SA(!__is_volatile(const int)); +SA(!__is_volatile(ClassType)); +SA(!__is_volatile(cClassType)); From patchwork Tue Oct 17 11:27:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072464vqb; Tue, 17 Oct 2023 04:45:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYtOKnqqbhZq1eQlsLWa9DxBIo0dMSuJ+RrpFU5aksPlBImBqYI0nzjfweB7MxK6IR+rgD X-Received: by 2002:ac8:7f95:0:b0:410:9626:f0bf with SMTP id z21-20020ac87f95000000b004109626f0bfmr2360171qtj.13.1697543133810; Tue, 17 Oct 2023 04:45:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543133; cv=pass; d=google.com; s=arc-20160816; b=IJymyebjxKoeP3FQXikEKsyR+Gve4nKioxShg/jUd0LusMS7qc8Ktc+JLua2aarStz zgIpiQxd0p2ntTOgpEvSexzcqUb0XEIZW54tVYpDkv2bQ1ZbLVu6L6ujPUcXPIA+mMs7 iqmuBj5AVASm2Xw9pX1rilXsRWMf6yMk/67+VG6S9EcZsv4hCun+b9LFzvBlAL/Vlp8A JrGadJ8yGdHdRcwQ/9xJ/izBbnN2mbESh1dY2CIo2VuefcRm0YI2RuAJGnDGTOzRa38t TrOoZr6zXnEBSZXCmq9HxWxL30PfFRNOkCluNeAZjfkvm4kOJC8jAM4Nt3Rf2WC9PasJ ctcg== 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=QBj39jUSu1bVKtAdYFimfBXba1UDQ3sncrIoT+Jf20s=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vCuySPdnYfOu+EPZFBaTekN4m1E4nQyg48KsL551LZM42lc8SsOCQnGu+G1LOMuFvx ZOE9tX/lIMRL1iGiyyiPl4GCHK0ka3JWNyPJjRgBtcAr06OMVaHTeJNGGzwM3HgN0YPP 6or9kJ7ahG8WCkGcAB06ohPU8KkQTsPgaEomrAlkd00oNPNdLXpZMwJ1WsKegGkrIoXr JMP0pV1z8Ud6jHAxlpNdHz/jUtOAt+ghth9+9C9wSuXevpxAmEvXWENL9Vf07AjzJOd0 zCfl4dDdXpGhjPXk3bevogIT7WUadznJ7xPwC2Qx66EzfrJ7dUn2DocBMOxmDQQq5wrF vP0Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="ucRAr/Xb"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a10-20020a05622a02ca00b00419856ea1casi1011828qtx.123.2023.10.17.04.45.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:45:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="ucRAr/Xb"; 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 146333895FD8 for ; Tue, 17 Oct 2023 11:44:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 146333895FD8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543049; bh=QBj39jUSu1bVKtAdYFimfBXba1UDQ3sncrIoT+Jf20s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ucRAr/XbKZQKvm096qdmVfqMwZk1xReXJLb/6idgpTTje84JlCpL0bYoh8HvKTZDk GF10tEDkIXLH4yWwU+SNJkCKR6FAwlWvKbx3EkhhG/T8vFDZpojn0oOajP46S7BRK6 3ArOB0Rx/MC8mVeMtudc6PG2nadJi7y05Do0gXmk= 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 33E56385771C; Tue, 17 Oct 2023 11:35:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33E56385771C 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 33E56385771C 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=1697542548; cv=none; b=owhxGv/3xSXf4j4o7ZM7pH8IuFAk8bmodnNYQZdBCC410HY0uB0BZ0ZfpuoIalRqT0JqvYj+ddSXskCIsuabPfY53x9Tvi3a7oBeopA2glIYNV6OPfmUJ34a8JehoAhvdeEuKN11BaFXRupEdRmoZ7IVKBCG8P+4OScGtic6/ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542548; c=relaxed/simple; bh=OOSc7LXvSX0VabJEFNwZWDP0RMhq6XkmejWzDYjnE+o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=QuZLwsQM5sLLKmjQKfHTvYOW6Av2Qb+zbSDzSy3YI9yVEECcokyuTu/D/Hv3GP9QGR+P3IT7LTxRN3f0kdL5WrQRE9oVX/dsP+qFzlMA+RkhDCEfMzPe8B5eM7lLVNF/HwhTvrly56Tc/i1c26Kup9P+d91up8aWsg+gFYzqyxM= 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 39HBHnMV007564; Tue, 17 Oct 2023 11:35:46 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbatkp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:35:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjUN028995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMJ001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:44 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 06/30] libstdc++: Optimize std::is_volatile compilation performance Date: Tue, 17 Oct 2023 04:27:37 -0700 Message-ID: <20231017113242.664523-7-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: RudhjOe8oPixJi-K_PQDKVM9tE4HWLnI X-Proofpoint-ORIG-GUID: RudhjOe8oPixJi-K_PQDKVM9tE4HWLnI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=812 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002988961806506 X-GMAIL-MSGID: 1780002988961806506 This patch optimizes the compilation performance of std::is_volatile by dispatching to the new __is_volatile built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_volatile): Use __is_volatile built-in trait. (is_volatile_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 686e38e47c3..c01f65df22b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -800,6 +800,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif /// is_volatile +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) + template + struct is_volatile + : public __bool_constant<__is_volatile(_Tp)> + { }; +#else template struct is_volatile : public false_type { }; @@ -807,6 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_volatile<_Tp volatile> : public true_type { }; +#endif /// is_trivial template @@ -3236,10 +3243,15 @@ template inline constexpr bool is_const_v = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_volatile) +template + inline constexpr bool is_volatile_v = __is_volatile(_Tp); +#else template inline constexpr bool is_volatile_v = false; template inline constexpr bool is_volatile_v = true; +#endif template inline constexpr bool is_trivial_v = __is_trivial(_Tp); From patchwork Tue Oct 17 11:27:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072044vqb; Tue, 17 Oct 2023 04:44:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/kmXAeXNbx87u1ORzUeMY//wotmWlYtg2Fmuw/3G8GxzlRMVWZYBkcF+z5DurcjqbVxYc X-Received: by 2002:a05:622a:14f:b0:418:1f52:1421 with SMTP id v15-20020a05622a014f00b004181f521421mr2427485qtw.9.1697543085912; Tue, 17 Oct 2023 04:44:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543085; cv=pass; d=google.com; s=arc-20160816; b=fGXxSPp4Snggv4/9Qto4DkDjZbpKR38HvVjeXLnjySFOImZ4UUSXtu+nwgcbqN1ASC Y0iNDoOcNZI1GKh87slXtclzNOpQwEZWUXwpOy2xVu5QPHWPxW6MIFjisLQBzc+V/x67 UncKPnFhh6V8O37YzjLY7qU6GwXPmN+GgY1iv12B2soNbxvRJz0yb0PsiAlQpJWKUj2g iLjVZpSqj3Ct2TJwqPKeD1DvaOGq2F/NNLxT3d+b8okKp2uXROFdPpAP0InqwFAQDB6m tImhY7WjjcDfC5d0JgPCBRhkD9Sp0NGUMMSF4AmrZtC60Ww2IHf14oRQ5ohUt98hz0xb gh2Q== 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=7ixTjS3X9HBoxNnpE1L4uHNyKTZaXvNaPjj8X4w0bAQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=jYYlxDupL2Mcl2txPuN09N+EnjcFHXFUN6MeZyJwIHl6GrcEJZXERtTgknSRnTfWEe LAfupPjrPkp6NmvHBm4IIxaHhWgUsevAPTOiRguZm5T7hssXO2L/BTObrpd8oq71Uccy 8VEiwrcreQZElsWkhB3k6eHEENuzcvwKUxD9anO/oIfls6vJ7KeATY+sz2DI/gn9swdw QVl5WuJf6ZUU6B6xuJ62v/VPNHADvKfKvMCzcsWqx+aUfK2qlwyjVyt+OCyihA9qKaMy 3bz+j00aj+T44eV43sgPBP7fYeATRIDgrhbowU/zeBQi8PS4PyE8NtYpG7SzxzK0DgJp V3+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z5oNOt01; 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 v22-20020ac85796000000b00410a3b28d66si981796qta.538.2023.10.17.04.44.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:44:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z5oNOt01; 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 3713C3882AF9 for ; Tue, 17 Oct 2023 11:43:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3713C3882AF9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543005; bh=7ixTjS3X9HBoxNnpE1L4uHNyKTZaXvNaPjj8X4w0bAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Z5oNOt01v99GK8L4h+E89QOfnYQKji3SR5+WFVaZEMmgDp8O7b8SfiQT6Is3y5+RU 7VupzJmIAzdJUgyK1NkuiN6D6uLztGxEsvRaMi3gIovckVKXj/vUUW/FdpJF8RsZH3 /sZB4miCpwTaUpqrbDzPrQZdSzNwtK02V9C1Yr4w= 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 532EC385700B; Tue, 17 Oct 2023 11:35:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 532EC385700B 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 532EC385700B 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=1697542548; cv=none; b=gXvbQEuAohahB4Ec3OjxUG7ag8GKqUga7iqkUgYgcob7mvaB7iErncs6/C2xTehwph7jmAUUIDDT2OAzA8WbED0Zh2rEkyvmotKSVxY/N5FyGU8hvk4Mc6wByyggLTjsJr9c4+vxCgtYhglLBi0FsC/5Z2L3+zvDW87VrtQfUCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542548; c=relaxed/simple; bh=8TftqluSpQljNHIfpPcj3uNIi87MZCtc8a0jE8Eje+k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VvJwRgR1tLpN/8s8f80Fha3T47Q9Z/P7unZufykzXX3fXz4yfoZLxVLjemARxRO4cxb+qYlce3iIgaZy5/0U60BsqXX5j1MT2lrk8+vFlnenpQ7CTuLckMf2oHrdjv2jso2Bglia9MHqd/2/DclZ9fPehIMRIJNPOPLSkENyOlY= 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 39HBXiM3016773; Tue, 17 Oct 2023 11:35:47 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw4gy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:35:46 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjR9028996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMK001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 07/30] c++: Implement __is_array built-in trait Date: Tue, 17 Oct 2023 04:27:38 -0700 Message-ID: <20231017113242.664523-8-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ltvCwhpp_VlTRjsWyP02JJecEzTki4W2 X-Proofpoint-ORIG-GUID: ltvCwhpp_VlTRjsWyP02JJecEzTki4W2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=837 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997331947317165 X-GMAIL-MSGID: 1780002938783812668 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 54782a167dd..b9f89fe178c 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3715,6 +3715,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; + case CPTK_IS_ARRAY: + inform (loc, " %qT is not an array", t1); + break; case CPTK_IS_ASSIGNABLE: inform (loc, " %qT is not assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index d786f47e60c..99bc05360b9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) +DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 7726fa99711..8d5874d6ab0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_AGGREGATE: return CP_AGGREGATE_TYPE_P (type1); + case CPTK_IS_ARRAY: + return type_code1 == ARRAY_TYPE; + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12376,6 +12379,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; + case CPTK_IS_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index fb03dd20e84..645cabe088e 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -56,6 +56,9 @@ #if !__has_builtin (__is_aggregate) # error "__has_builtin (__is_aggregate) failed" #endif +#if !__has_builtin (__is_array) +# error "__has_builtin (__is_array) failed" +#endif #if !__has_builtin (__is_assignable) # error "__has_builtin (__is_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_array.C b/gcc/testsuite/g++.dg/ext/is_array.C new file mode 100644 index 00000000000..facfed5c7cb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_array.C @@ -0,0 +1,28 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_array, int[2], true); +SA_TEST_CATEGORY(__is_array, int[], true); +SA_TEST_CATEGORY(__is_array, int[2][3], true); +SA_TEST_CATEGORY(__is_array, int[][3], true); +SA_TEST_CATEGORY(__is_array, float*[2], true); +SA_TEST_CATEGORY(__is_array, float*[], true); +SA_TEST_CATEGORY(__is_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_array, float*[][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_array, ClassType[], true); +SA_TEST_CATEGORY(__is_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_array, ClassType[][3], true); + +// Sanity check. +SA_TEST_CATEGORY(__is_array, ClassType, false); From patchwork Tue Oct 17 11:27:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4070842vqb; Tue, 17 Oct 2023 04:41:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkh59BkK9R6QnfThHJKHgSmMwLjdIWf3j73ahTFNz+Co/rSb3c1BFj+mI6sa21Y9CYfPXu X-Received: by 2002:a05:620a:390d:b0:76f:14fc:6d2f with SMTP id qr13-20020a05620a390d00b0076f14fc6d2fmr2388375qkn.1.1697542897812; Tue, 17 Oct 2023 04:41:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542897; cv=pass; d=google.com; s=arc-20160816; b=bcLgvAt0acyysKbEgz1vBhEetuG94ejBJRIPp7Yp5xTV21q0UKw6EfDl/GCCYYtQGZ dE7B9kXLuCCb3q5p0vh5986+HaZv36se1KYlNr+uybsZqgj/tfF8ZRmlYZjo58OdPs50 9eqLnozSD68pcrtGZYibQY7Xd3J9sqYzetGOAnOnZigmCrKnCJPxcteHrZEwma5sya5n ruVP0lNJNn983hperr3LpBCtjHtkpBPUmA7H3ILVGLn96jMdi5gtEbOcpMxYydkYp6sj OxwwzNgKOCzgdzyatKQ5lOVaTG6YT1/XUbenTaBxpuhh1Oja3LawVMd78N051qA9C1d1 Bsdw== 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=RZTNDHIWtB0xt/LyEoTYMcdMTJkRnyWcUjKmKws8okg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=xRheLqlYNnlRN6onNQjkdixeTK+94+UEiIQTpXdKWWYtPo8PglswFlfPw31DQtUAKf TZrnSvHcHu0pxutn3p61HHxoEqipMKhCI49SK6BDn6jAm+lkeeSMyt+0dLk3o8uSpUXx ZPK+7T2ErAjuD5SEvXHndcO7WlLmzmnx/fPiWWnESFf1HhHB05Aq6LsbcW5SxASbNGEk Sf/MGJlDz7HUMf9LFJ0yxkZAzJ24l8LtWABfTqOZtSsnCIzpGXciLzabIYZOVUZnAfBc wywm/nqUfBZiHGcT7ZJYZB2JNWDJVKpeWKz4XzPk4IRvq606fI5MttM+TvJhbvTysYEX JmPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cihenpuT; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b27-20020a05620a089b00b0075cb23ee1fesi896173qka.602.2023.10.17.04.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cihenpuT; 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 D57443857033 for ; Tue, 17 Oct 2023 11:40:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D57443857033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542844; bh=RZTNDHIWtB0xt/LyEoTYMcdMTJkRnyWcUjKmKws8okg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cihenpuTy/LIDPvVAlDWJHoKikjIF+B2K+SHut/Ut5tegkDpMzb1xpwwR1B57NR6h XKCfCyzD/+5yTJLuTybHcLHAgHJaUVvIq8Hfi8czE5qiTludGb0VOxOPFzPN9X+KJM 8MR98W4T5DSwFID7YwfVkH7aAKYriBqTvcH0uWbE= 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 C41FF3857703; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C41FF3857703 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 C41FF3857703 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=1697542563; cv=none; b=HRdy5aPr/8cBK4txxgnz/GUlIXpDjnkYKtder8D+OlHO9/ISrSLgqkpSOiWxvk2aG4LW6hcLC7fVe/NKqOxL8dKDtGCmVf46RTG4GNxcG40gZncBwtqdWEffCkEDj0/Eh+TBxOkfGnG6aUqv+JsmXkTFvDf0QhorpLFWES9FTF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542563; c=relaxed/simple; bh=LWlpKAqSPh2SZMP3ObLq+s/FTCguucm8HDdrx5fwRp8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Zz3AVKWWCHk3iTkdp2pVHOwkv4PWx8oIGxoHSCTf4XzLL5wDUFIIcs18IMNKPwHn35bE/tm+nB4Btb0mMbNOPIBMZyDZxNFVkwd3WL7KpG9a7r543ZTizF6GbxgZpGMm2QIy+OUm5jqn4m2kA/Vyp6kykPKzbzgKo7ZaqqWGQH8= 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 39HB9rtY008635; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40afva-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjHr006891 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiML001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 08/30] libstdc++: Optimize std::is_array compilation performance Date: Tue, 17 Oct 2023 04:27:39 -0700 Message-ID: <20231017113242.664523-9-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: cBSnWX08ZVb70m3ZoOWDSEGOJcX8zACA X-Proofpoint-ORIG-GUID: cBSnWX08ZVb70m3ZoOWDSEGOJcX8zACA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=526 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002741723435689 X-GMAIL-MSGID: 1780002741723435689 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 c01f65df22b..4e8165e5af5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -523,6 +523,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_array +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) + template + struct is_array + : public __bool_constant<__is_array(_Tp)> + { }; +#else template struct is_array : public false_type { }; @@ -534,6 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_array<_Tp[]> : public true_type { }; +#endif template struct __is_pointer_helper @@ -3183,12 +3190,17 @@ template template inline constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_array) +template + inline constexpr bool is_array_v = __is_array(_Tp); +#else template inline constexpr bool is_array_v = false; template inline constexpr bool is_array_v<_Tp[]> = true; template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#endif template inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; From patchwork Tue Oct 17 11:27:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072807vqb; Tue, 17 Oct 2023 04:46:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGON6Hn82luHkKWepqLBrHSBU12RZKus9I2z66mMDC892KxJirE26+nApUHoJRemAEqlU+v X-Received: by 2002:a67:c893:0:b0:457:dac4:2af8 with SMTP id v19-20020a67c893000000b00457dac42af8mr2352320vsk.2.1697543177015; Tue, 17 Oct 2023 04:46:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543176; cv=pass; d=google.com; s=arc-20160816; b=sCY902W22YXxrwh5X64Ih2ubexm2rLoHAWZyfzf2MA6+A8Fe6bnwVJchM34Bt/bkFn zWuUk08mA2xtQ61jbfrO90BhVoImQZzx1SZz58l6ySjT5FtzpSOQybi7Naqm76HnWr+C D6TVpvQYHnT0Z+7zoWj1wkdP/H/1NGWTpt9oqHTruhN69Apg+z4BLafGLCETf42yI6aY o/nIhOMLC4wi3WRe+0KwJ3qbyjGD30btRurTQvmszIWwy64tBxmEL0OoSb4ldStWbfcA BrDMka92HBJubHDv3MWPeCI/XKCs1sjS5isYEGoPr8WY7CXIBJa/KKE9gMkVnW9holgK VJ6w== 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=4fUvy3gQlMpAwr3jsAjiFhB2miwazGVk99LPxCPeIwE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=lb0u3GZwqxtTM7MU9koa6Qw4tAp+hk57rzq7FpOtLqc6GPY7Dt4IdIO3Ut/78DT61u HvFsKApEIbeOJkMGOqgstqbpqW5OuRjwgwr2amDjOl6i+MKRZ19d4u5Cy0wIhwElOSOU CMJIW21BW8aqEUOTrGxW7ckWseVMGhrvtSs+HqklJijy/POB4wvbq98dwXajj1xDxcXC 6kHvFFdsOjWyS6hAZN9LtqwyMR4P3oO0/oPjmefr1WOEuQl3N91oRTphKaByjiNVD3sI 0cloqJ08Yuqie1T5Armj2cl9xgJF/bqYWSUPw7BQhaqjdoPO/riIOSt+SVA9PblMgWvj gKYg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LIh431q5; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p6-20020a05622a00c600b00417fe762ebasi940851qtw.501.2023.10.17.04.46.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:46:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LIh431q5; 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 6B90A3858288 for ; Tue, 17 Oct 2023 11:44:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B90A3858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543099; bh=4fUvy3gQlMpAwr3jsAjiFhB2miwazGVk99LPxCPeIwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LIh431q5FRzXJKucwf0wrlvRqrensYYlKZ3xVxboibCovm9jSA6u+fzEjjkFftZOg 2NkVYN4sPjlkeMwJ1B+wNOY8knDUmne+bDRHEdsrMNPBPK9eBOPguqCXHDjPLyqtIi yBj5JQP2sE7NklKaqVNkFUXz+v0Bekz4EBVemKBA= 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 A270F3856951; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A270F3856951 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 A270F3856951 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=1697542571; cv=none; b=fxF/eDK7EgY6beSH6O6OPAIRia5PWlLQg5n/u78p9v2Tn+f49fTdDKn10bWnMy/S9Rwh+UDj1ekv2WNfY54S4wKDSInUkiz6tpmfa4ChcDZ6hZ5sn+IMUK/MnSN/Tmdb47YYriP3zGhRSi+7y0o5CzwnHwUsce30HfKK8D/Biwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542571; c=relaxed/simple; bh=NhasjZWVUqUpZZmXqS8d6jkCFZVEX8IRPI+dI1G5T3g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=gZ8Ce2LK71pFyQeK06GZrDi6xb6a8Zt+RT8Yu0TmC4Tuqca/I8TiSri8a8kV38mtnjksnjYq7mPXYRnwr8pGSpVZyqa6XYtVCA3S4Zwx22qatLPxOjJBvTbpp2GtCEqttUOdMbN87Ff2ydVoFvBNm4WuH8XZhMjcVotc2+4/WxA= 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 39HBN3bd032326; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw4hw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjBk017738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMM001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 09/30] c++: Implement __is_unbounded_array built-in trait Date: Tue, 17 Oct 2023 04:27:40 -0700 Message-ID: <20231017113242.664523-10-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: -fV0CyVZlI8VMqZyVfC9JE4nCPE9cGpW X-Proofpoint-ORIG-GUID: -fV0CyVZlI8VMqZyVfC9JE4nCPE9cGpW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=725 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997094718165190 X-GMAIL-MSGID: 1780003034397310271 This patch implements built-in trait for std::is_unbounded_array. gcc/cp/ChangeLog: * cp-trait.def: Define __is_unbounded_array. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_UNBOUNDED_ARRAY. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_unbounded_array. * g++.dg/ext/is_unbounded_array.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_unbounded_array.C | 37 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_unbounded_array.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index b9f89fe178c..292b941e6a0 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3797,6 +3797,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_COPYABLE: inform (loc, " %qT is not trivially copyable", t1); break; + case CPTK_IS_UNBOUNDED_ARRAY: + inform (loc, " %qT is not an unbounded array", t1); + break; case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 99bc05360b9..4e02f68e4a9 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,7 @@ DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) +DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VOLATILE, "__is_volatile", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8d5874d6ab0..bd73323e6db 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12217,6 +12217,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_COPYABLE: return trivially_copyable_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: + return array_of_unknown_bound_p (type1); + case CPTK_IS_UNION: return type_code1 == UNION_TYPE; @@ -12384,6 +12387,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 645cabe088e..90997210c12 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -131,6 +131,9 @@ #if !__has_builtin (__is_trivially_copyable) # error "__has_builtin (__is_trivially_copyable) failed" #endif +#if !__has_builtin (__is_unbounded_array) +# error "__has_builtin (__is_unbounded_array) failed" +#endif #if !__has_builtin (__is_union) # error "__has_builtin (__is_union) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_unbounded_array.C b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C new file mode 100644 index 00000000000..1307d24f5a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_unbounded_array.C @@ -0,0 +1,37 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_unbounded_array, int[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[], true); +SA_TEST_CATEGORY(__is_unbounded_array, int[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, int[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[], true); +SA_TEST_CATEGORY(__is_unbounded_array, float*[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, float*[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[], true); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, ClassType[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[2][3], false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass[][3], true); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[2], false); +SA_TEST_CATEGORY(__is_unbounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_unbounded_array, ClassType, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteClass, false); +SA_TEST_CATEGORY(__is_unbounded_array, IncompleteUnion, false); From patchwork Tue Oct 17 11:27:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072253vqb; Tue, 17 Oct 2023 04:45:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWixQBGx8DovrPPk0NrhmTaGljk8OIYs5cgnXeIox33J9g8hKbC7s/U0QGI9Pr4TPn8cGI X-Received: by 2002:a05:620a:135b:b0:777:ac06:ed91 with SMTP id c27-20020a05620a135b00b00777ac06ed91mr1264341qkl.23.1697543112959; Tue, 17 Oct 2023 04:45:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543112; cv=pass; d=google.com; s=arc-20160816; b=rW2s+3SPirLfqKou0DeBfWiUNNJQ606vH12LC/hN+dK5lWihj3S+llHElKXJBmaIyZ sIEnamOyuisBAHQ17RINwoG2n/ONpeEk3owSu7Ow61nqe6GuQAtpIsmXhmd6UWu2UUxF 6E/pm3vPPinvjcKxHV7Zy2g0yyQKfOPN7JHcH2rdMH1O5CP5AtrzXAvne+u7cBvpli1b UzDNZCl3n0OJgLZ15321wSmJA1jNWrn1VHy0mTg4Pxji0kyWHNrreI2YlEb5BGYsiPil ff8pFx6B7BHLaPGa31JTl9LxpcouEIpnBcz2bQKKIYvveswZYnF+6oE3/+fB57LNuv67 hSJw== 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=RLQZZRfxaCHMdqX3Q4VuRHCYUQ7HTy37ML2Zz4GJKzE=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=bxnayjIPCjmkR/s5PkBEbRf4ih9lxZ+NxuAVlDiMW8AdDwB3XHzHJg8ftauxB7JpSY qOVllsF9uqGYI/ShAJxvdwVQ9wyiDHd7YLDOLuj5NV8yIc1GOz0wrOhMa03lk4JYKN4D 98OgE3iGoEIgnJwr++EeXoLaEBQDBKfX0sTTJCTVFB3OtDsTy7fO6Ujpu03rFAh5vlqF aSn0CsOdzb1BON6PiMQ9gRmRJUh7EsJPbiuUpkcB0hdNZCIGYFZPgvnpXTCJxZfpgkQH qW1ibK/FM5iuGhu5Hpt3DUdCrQ57LbhKFyST0JLs+V6MV2UXFd/gQVOfZSD33e8NZDBR T0Mw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=C4xudysl; 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 n3-20020a05620a294300b00773c9d788f2si941520qkp.351.2023.10.17.04.45.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=C4xudysl; 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 CEDCC3887F69 for ; Tue, 17 Oct 2023 11:43:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEDCC3887F69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543028; bh=RLQZZRfxaCHMdqX3Q4VuRHCYUQ7HTy37ML2Zz4GJKzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=C4xudyslLnveTv7qK8qoFmis5Kx4Spy+cXPpKcXL8h3l3XZcxib+xFBBqFcU1EL/n 0dbeNIhSu0WB9tLtdPBygoX+vpWyXlbVEzWeaiKG6HMEbobhjtmrbqkt6Ft/X6gb2D YF31gbLaC5iWm8nv8vafS0CbjURncqQD0awfY+ls= 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 9BA153856DFB; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BA153856DFB 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 9BA153856DFB 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=1697542570; cv=none; b=sqde8r8SM78y3soYrFFHFHwh9gvqTFexDqLNfk/8uYCyybGjO5javNWgRXurkP8CoGqpSuvQ2b2xzUJiLIv6zv7+T5I+BfMEc8LDQYliyuczJtuM+9E5q6bShIlbxPd5Gudl7CRARJtJqBPNDIV4kJJx3Y+omhTLQWGbDLHDGoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542570; c=relaxed/simple; bh=K00IDF5zEbYHxaGvNxA8OxHa/yILcGh6RlZf6vWDaAo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=egqHl112KOty0yjp65oq86dcvDvfB15cc0RzCBV6ORQTm3uA11RrqR2Abmn7HAYA5LDvbifo6aNfCSkflByv7Bcihvf8ihvlvkWWSbLXm4pn9ox3LWrwxB8927VHQw0KvVwO5sJKkp3WdxFXMn650do36Yna4PpVF5ai5qZW+Vg= 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 39HBX14L015407; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw4hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjas012235 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMN001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 10/30] libstdc++: Optimize std::is_unbounded_array compilation performance Date: Tue, 17 Oct 2023 04:27:41 -0700 Message-ID: <20231017113242.664523-11-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Ysee1G3iYiePXBrFlpph5rPeWcSTKWkL X-Proofpoint-ORIG-GUID: Ysee1G3iYiePXBrFlpph5rPeWcSTKWkL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=556 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002967013735782 X-GMAIL-MSGID: 1780002967013735782 This patch optimizes the compilation performance of std::is_unbounded_array by dispatching to the new __is_unbounded_array built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_unbounded_array_v): Use __is_unbounded_array built-in trait. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 4e8165e5af5..cb3d9e238fa 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3541,11 +3541,16 @@ template /// True for a type that is an array of unknown bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_unbounded_array) + template + inline constexpr bool is_unbounded_array_v = __is_unbounded_array(_Tp); +# else template inline constexpr bool is_unbounded_array_v = false; template inline constexpr bool is_unbounded_array_v<_Tp[]> = true; +# endif /// True for a type that is an array of known bound. /// @since C++20 From patchwork Tue Oct 17 11:27:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073680vqb; Tue, 17 Oct 2023 04:48:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVNJOLwoeSI3TFGcCGVh1XQ7hGbYwF7+o0ND1yFT16lirfa5/pSOTs7GF4Oj3A3weSBJyN X-Received: by 2002:a05:690c:fd6:b0:5a7:cc02:68b0 with SMTP id dg22-20020a05690c0fd600b005a7cc0268b0mr2465514ywb.23.1697543282756; Tue, 17 Oct 2023 04:48:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543282; cv=pass; d=google.com; s=arc-20160816; b=Lmle2vwWgcLvzcGiM5yybpVjTSw6y5UQNLo1DY9KgBv8kPYh4+cXhJ/ZLu6TfYffGk cfjpIUC0HEqeo/YbW8ApJyBOz29nsetiXAqvldWxc7L0muzdP3tsFnA3onbAn4HoTz8C 0kV3TFWvJyVsMnvdhiVNGZcghZT02YQp9cvTYxIbvULOIyuH+tvP60SzyYsZkoIi6FyA XHQEAs1mHV7I5rX9iSaESpLtQdk8bqe9wsMGCUcAyLF/0EndtdiiG0ID9VmxuENWvcUm m3K/LISqylb6j6rnzS/NLoCl3RkPKFYh3d+CFpqiLwZTprcAvFt+2qBtuCRTylRGBzfM HxqA== 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=FsMuUrDQIKOQmencLbexsoY8bJoop2ZORDdDp0rKtxg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MgAXgN99PiHVm7rOObsk9BWjRmgsjiOZ9YjDkpgGUTRl0k66U0vFsRPgTXmOreDS7X lnht9FyZaF1bGQWvo/Jj6wdwrLUVwazBtMl0BrtspBhS1torei576DCFqduPeRtlMQvM QwWx9DVUfVlgdjUfRpqCSy14shcqamzIFIPUsmx+1es83tbFV31E3v7wPBlxFE/h0o0G bIpwVHZg39pONia90MLYVTCJGFM/Y5U3IsHjlxI2gG9mCpCuF8GE8T5GKv6bRPQ1FmNE wPp/8CcHnF6E/flqwfevmBLdQwzrBBUhlxVx2fdkbCdD9o/MH0mPHrcrY87ic7h8rCOa wFGA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YpS6OMfc; 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 v19-20020ad448d3000000b006585ee0fcfesi827134qvx.74.2023.10.17.04.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YpS6OMfc; 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 5119C3882052 for ; Tue, 17 Oct 2023 11:46:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5119C3882052 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543199; bh=FsMuUrDQIKOQmencLbexsoY8bJoop2ZORDdDp0rKtxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YpS6OMfcZMw2vQkEd+lKa1Iyw/YIEtw66Q8VIlzoOA2gmJNshhF2omjsQrkhAFRT5 2rR2IdzQlWPQgqq2qAf5MQRGRNI72v2HkC5rjubKA+vJUmK5S0zM+G0XEEVzzw4BLO SgcBUJjx5RIYiCY4LX7+358r+A6O3VRmQvwhACHE= 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 2B4603858039; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B4603858039 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 2B4603858039 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=1697542566; cv=none; b=gN8rExgk9gm87PXPhljVm20NOqhRKGWVucTs53Qi9ngEuI7bdH8t/lfknZwFILKeXXT7ou1xQJOaCYNSe6po842FQQiRiX5pjefEIc5ve7GUrDDHJaRWPW+NiUwt0NFO8RxVGCrjlbdltoRHiBl+QLdP+Pu/yoztkXgAnGJgOyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542566; c=relaxed/simple; bh=nZ/pEsqPL8Mwkgwx3MhbngeLpQUO9kpyZb6eSrDGXGc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ezUXQKFExQely3WcBPXoKbc8vgfmM5azNVW7XmuBu3xmvOWmxjj/CucP6LvuYHJdKCjP6hr9V5QCaXBLhWd24TIKAFID9V/xR8KWZGwClEamkpQPDX79BvVHv+UhScWcNYmnDBEHoouK39kCSosqoWIPt7v80PACmnyGFePUjrc= 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 39HBVxMO015894; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rmru5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjXk004222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMO001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 11/30] c++: Implement __is_bounded_array built-in trait Date: Tue, 17 Oct 2023 04:27:42 -0700 Message-ID: <20231017113242.664523-12-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lJw2udGOCV5L8l-CdStHPp1LlIezLKUN X-Proofpoint-GUID: lJw2udGOCV5L8l-CdStHPp1LlIezLKUN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=527 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996279060207258 X-GMAIL-MSGID: 1780003145249027622 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 292b941e6a0..71a40558881 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3724,6 +3724,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_BASE_OF: inform (loc, " %qT is not a base of %qT", t1, t2); break; + case CPTK_IS_BOUNDED_ARRAY: + inform (loc, " %qT is not a bounded array", t1); + break; case CPTK_IS_CLASS: inform (loc, " %qT is not a class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 4e02f68e4a9..6d6dff7a4c3 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -62,6 +62,7 @@ DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) +DEFTRAIT_EXPR (IS_BOUNDED_ARRAY, "__is_bounded_array", 1) DEFTRAIT_EXPR (IS_CLASS, "__is_class", 1) DEFTRAIT_EXPR (IS_CONST, "__is_const", 1) DEFTRAIT_EXPR (IS_CONSTRUCTIBLE, "__is_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index bd73323e6db..aab35c9e5ba 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12154,6 +12154,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) && (same_type_ignoring_top_level_qualifiers_p (type1, type2) || DERIVED_FROM_P (type1, type2))); + case CPTK_IS_BOUNDED_ARRAY: + return type_code1 == ARRAY_TYPE && TYPE_DOMAIN (type1); + case CPTK_IS_CLASS: return NON_UNION_CLASS_TYPE_P (type1); @@ -12383,6 +12386,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) break; case CPTK_IS_ARRAY: + case CPTK_IS_BOUNDED_ARRAY: case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 90997210c12..4142da518b1 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -65,6 +65,9 @@ #if !__has_builtin (__is_base_of) # error "__has_builtin (__is_base_of) failed" #endif +#if !__has_builtin (__is_bounded_array) +# error "__has_builtin (__is_bounded_array) failed" +#endif #if !__has_builtin (__is_class) # error "__has_builtin (__is_class) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_bounded_array.C b/gcc/testsuite/g++.dg/ext/is_bounded_array.C new file mode 100644 index 00000000000..346790eba12 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_bounded_array.C @@ -0,0 +1,38 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_CONST(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_bounded_array, int[2], true); +SA_TEST_CATEGORY(__is_bounded_array, int[], false); +SA_TEST_CATEGORY(__is_bounded_array, int[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, int[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[], false); +SA_TEST_CATEGORY(__is_bounded_array, float*[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, float*[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[], false); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[2][3], true); +SA_TEST_CATEGORY(__is_bounded_array, ClassType[][3], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[2], false); +SA_TEST_CATEGORY(__is_bounded_array, int(*)[], false); +SA_TEST_CATEGORY(__is_bounded_array, int(&)[2], false); +SA_TEST_CONST(__is_bounded_array, int(&)[], false); + +// Sanity check. +SA_TEST_CATEGORY(__is_bounded_array, ClassType, false); +SA_TEST_CONST(__is_bounded_array, void(), false); From patchwork Tue Oct 17 11:27:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074146vqb; Tue, 17 Oct 2023 04:49:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+3Awto8I6kHkm8sqDQSiYRz0GA6Pi1itBU6mcOynPB/15ozLhRDHDgbr/AAIUHdEwJ2uV X-Received: by 2002:a05:620a:200f:b0:76f:1f05:e994 with SMTP id c15-20020a05620a200f00b0076f1f05e994mr1906529qka.64.1697543343105; Tue, 17 Oct 2023 04:49:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543343; cv=pass; d=google.com; s=arc-20160816; b=Pz2dX2O7r1ejAo9FCGFUCidTgr1y/Wy5EN2Akb4rOB+fDDveyfeD8T12XC4yUPV0tB e0AgcwOvBx4tm/f2kw2bm9KbHFTtZ/KwxONynRh1FPdVdDHbVBWVL3tUqaqHvY/cRx8d dP/vsWS8W+l6CO5WHfDcDvGtkCpW13VZJVOMyPkknli9p92m6BbXKPMAqj9zwZ6erQuN /oJXcX2M9XQp3CEagWXDaknMZoXBuQmfjovkAoETdso+fH7d3MYboJxn25QAtRlqPYcv FqMfn3QnOACERI238HzmuMTix9fgINx/eHJagjmWe17nI1jwhzv7p5oA3sRG/17OSenZ 892Q== 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=PzsL6dsGswgTk344Px8h/e8d2SHNDgTIaBh2FsS3aXA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=H4ivKFdp+8+x5MpMdcYMebVXA4CIEnuZuAxZY7jBpSPboa7PcoklHDsY3oqlCtbz3l VAv79azWnl+pBGfFr9TaJOlcZ09gjgSH1eqRZiLtA3BLQ7jlNDOBRivV+Q2DCuEYoDKV wnra3y5BZpOLJbzHuU0LHIbLJt9GomtSY5jaI1Wl754DJjm5jDpflMMl+il6SWAhVbgl tAW1O47IpOdJnPJ3h8hSkgU7a7uTm1fMM6XiAj+3qOmg+vOL5vOzqr47Mcc0u6uikMaB U6575ihoN4HdqztSthcX4FY6pPa66VepZlu2E9tO/3R3JBT/m05AqHegR5DuNTEFR8WY 9AZw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gq2llyUS; 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 g8-20020ae9e108000000b007765135d96asi854078qkm.390.2023.10.17.04.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gq2llyUS; 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 2498D385352E for ; Tue, 17 Oct 2023 11:47:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2498D385352E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543257; bh=PzsL6dsGswgTk344Px8h/e8d2SHNDgTIaBh2FsS3aXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Gq2llyUS0Hy0KwmpJDJbecgGZREu2iKse+x9lUyHTU8scazuQRC8hs18LMTbeoGMq GLAAgfr1HoQMjVpP96Yona7XZJaW8Sgm4KfDrbBliuPQ/f+ua/r0AjM2kReHK/CENB sO7FyX/eaRTdoOXPhR/b4HTVUNizsDnTZluGySWg= 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 51B9D385842A; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51B9D385842A 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 51B9D385842A 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=1697542567; cv=none; b=OXZIS4hoNXe59KEhH1Rp0DjzvlrbxPjTT7g5sJsqa1e3QUuxKLdeLNCbGCzyJ/adTwiOkaI3OKrwv067PnwCzcs5l9msou3hhGu3/0iSwcxepjtIt6F8iYLXP3pBss1tCCrtBKuFqCAPtf4WkCMrl5QbIMeP9g7Trp13qj14jTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542567; c=relaxed/simple; bh=Gwln+6kReoTjeSwMaRkvh0PM3wCmQoJc6szbsyWoD70=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PiZ2jGE9Rf0IINLv7gpdb2WoNzMGAKncW6C3PTrmNKc/6O7nGMhGRpRcUKrCQQ5pJpaKd9t47tnHyB+yXJNE8c/iQnDHDj2c0FTx571a9PUmNtMAr1C6zc3orMJJmsVAUrgWUsxfDJCuqUgqZHf1OTcijIZccLAjK5LsfV2NleQ= 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 39HBSpDF005987; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rmru6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjaW004606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMP001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 12/30] libstdc++: Optimize std::is_bounded_array compilation performance Date: Tue, 17 Oct 2023 04:27:43 -0700 Message-ID: <20231017113242.664523-13-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: POqvY-904AmdtNjSrXPX389t346xnXS4 X-Proofpoint-GUID: POqvY-904AmdtNjSrXPX389t346xnXS4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=467 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003208222706603 X-GMAIL-MSGID: 1780003208222706603 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 cb3d9e238fa..d306073a797 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3532,11 +3532,16 @@ template /// True for a type that is an array of known bound. /// @ingroup variable_templates /// @since C++20 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_bounded_array) + template + inline constexpr bool is_bounded_array_v = __is_bounded_array(_Tp); +# else template inline constexpr bool is_bounded_array_v = false; template inline constexpr bool is_bounded_array_v<_Tp[_Size]> = true; +# endif /// True for a type that is an array of unknown bound. /// @ingroup variable_templates From patchwork Tue Oct 17 11:27:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4071776vqb; Tue, 17 Oct 2023 04:44:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/A4jkGVPBigRE+jdFZ4BO5ZSwjeXfVedD/g/shZcBcUo9Q1+bAIzdc071ovydYMgRxLWg X-Received: by 2002:a05:6214:c83:b0:66d:248a:2dee with SMTP id r3-20020a0562140c8300b0066d248a2deemr2046327qvr.0.1697543047493; Tue, 17 Oct 2023 04:44:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543047; cv=pass; d=google.com; s=arc-20160816; b=wu1yMaZUKWVV4pE9ri+M7VlooOZuiKG0tiF2FE86OGGi4g67Iu3pkV7lTB0xdQ+PbX qeRZ3Vm9ZipDdafiCLJsYP0NaoclTOuLOY9GPuhJ6hduvkpWXE97q2Teakl0O3ffadXA uqwwm0+rgqTVyGjR5ZLw0hN9VQDO111AknSz6zbaYATgwuD/CaXejEKIckpF2c2LelGq ULdeUl4lahgB2NpxMgXFlLKr5RBnYewxN0ll1vVUvV7bOqxHPlvc1NkTZr+UrPCkWU1U Vr0/voBUOu9hGVxf3hFrmkN4IqxE7fa98p0skXv+HoTHxWVWewcChH6QYaHxxlaYvZuD hmEA== 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=DRg/DNgFrI0TZpzvE9Ejgu2stthUWDVZ9VzyaTaKmUg=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Y/n1CjBhzHRkQtQNrrInDRGCm0QeDNWaDmAbC8ff5gc3edimZAI+Lwn0qWyswZy+IZ oq0nb9wtDuZ7LCNKfm1GHtoVmP68xUjmHA+KoBvqnTDJI1sM7jfEiRSUw14KGxxNatn8 TYo+rZC5Tb1/Ae9TK2ZjcJX9Oxd5RR2M4z2byHiUH2is4VejnialfcOYdskbYLdh0RgT Yc5IN0Fxi29w28SeFknAPiiDngaqZwoZlKlPmBGtU+4YpEkf8k2Ke21GEnFi9HZZI42V 6QNffNzVtpF1xZDbQ5P3VwuArNrW4pEXvRjgnFuFmFW0hfMD3BbBmh4eCcgKnOJxCBi/ 33PQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LUtSswps; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y17-20020a05620a44d100b007758e5dba52si929233qkp.307.2023.10.17.04.44.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LUtSswps; 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 7D15038245B0 for ; Tue, 17 Oct 2023 11:42:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D15038245B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542970; bh=DRg/DNgFrI0TZpzvE9Ejgu2stthUWDVZ9VzyaTaKmUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LUtSswpslRk0Br6DBjCpYyH2LjIrcqNGhqhbQcTAVZkDh78oGxv239fjQabihfs2V 0z2ymzSVcPgga37WwG4kJQWZbPzXxL6vXULW4+gp1WZPgrdmygg3zngCktIuXWZ4Cr oiTTIOpS/Hf1wQUwP4prm5nZCG7NuSk+OwnC+bcM= 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 770643856275; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 770643856275 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 770643856275 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=1697542569; cv=none; b=cpDA8BXA9qT1bKQXliPyPv7B1/wzksUttoCWaO3zdRtgD/ubpcLr8YoqwGctZRhQAWOQtGFvj0UQHFnUG5CUvxiDvGbJojiBEmYXdxNCdljF9z8J5LHZtD1T27GtgAb0lTs8Xywh/Xc+B1ddb9A7FDN2uEhXayHCqtJ8vGYSwk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542569; c=relaxed/simple; bh=fkQruCseJD3dB1E16vhUv/gGSDDVp/cL6/48GiYilPI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JU5g+ZeV7w+yLMPHyiHV51ZQwOnUGAQemzgB7wxRS6JZQQLzo88DMIoS17YEr5SKWoIUhIn7oqN834CUqMZ4lba/ptQSVhR5T3hb12z4+tF9H9H36VxtkvvnxC/S8/D45uQVXHkSOwkAfJQvpAkZPUQPox/oKi0SBddNwWG3cr0= 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 39HBa3qC029335; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb4rmru7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjhp012236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:45 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMQ001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 13/30] c++: Implement __is_scoped_enum built-in trait Date: Tue, 17 Oct 2023 04:27:44 -0700 Message-ID: <20231017113242.664523-14-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OQrMnnd7n08_Ic0R48me1fwl6nWSOqSq X-Proofpoint-GUID: OQrMnnd7n08_Ic0R48me1fwl6nWSOqSq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=707 adultscore=0 mlxscore=0 malwarescore=0 clxscore=1034 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997580847515671 X-GMAIL-MSGID: 1780002898696256710 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 71a40558881..2b46e3afa97 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_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; + case CPTK_IS_SCOPED_ENUM: + inform (loc, " %qT is not a scoped enum", t1); + break; case CPTK_IS_STD_LAYOUT: inform (loc, " %qT is not an standard layout type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 6d6dff7a4c3..e0e3fe1d23f 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,7 @@ DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertib DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) +DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) DEFTRAIT_EXPR (IS_TRIVIAL, "__is_trivial", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index aab35c9e5ba..9f0e468f489 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_SAME: return same_type_p (type1, type2); + case CPTK_IS_SCOPED_ENUM: + return SCOPED_ENUM_P (type1); + case CPTK_IS_STD_LAYOUT: return std_layout_type_p (type1); @@ -12391,6 +12394,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_SAME: + case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: case CPTK_IS_UNION: case CPTK_IS_VOLATILE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 4142da518b1..ba97beea3c3 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -119,6 +119,9 @@ #if !__has_builtin (__is_same_as) # error "__has_builtin (__is_same_as) failed" #endif +#if !__has_builtin (__is_scoped_enum) +# error "__has_builtin (__is_scoped_enum) failed" +#endif #if !__has_builtin (__is_standard_layout) # error "__has_builtin (__is_standard_layout) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_scoped_enum.C b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C new file mode 100644 index 00000000000..a563b6ee67d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scoped_enum.C @@ -0,0 +1,67 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +enum class E { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, E, true); +enum class Ec : char { e1, e2 }; +SA_TEST_CATEGORY(__is_scoped_enum, Ec, true); + +// negative tests +enum U { u1, u2 }; +SA_TEST_CATEGORY(__is_scoped_enum, U, false); +enum F : int { f1, f2 }; +SA_TEST_CATEGORY(__is_scoped_enum, F, false); +struct S; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); +struct S { }; +SA_TEST_CATEGORY(__is_scoped_enum, S, false); + +SA_TEST_CATEGORY(__is_scoped_enum, int, false); +SA_TEST_CATEGORY(__is_scoped_enum, int[], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[][2], false); +SA_TEST_CATEGORY(__is_scoped_enum, int[2][3], false); +SA_TEST_CATEGORY(__is_scoped_enum, int*, false); +SA_TEST_CATEGORY(__is_scoped_enum, int&, false); +SA_TEST_CATEGORY(__is_scoped_enum, int*&, false); +SA_TEST_FN(__is_scoped_enum, int(), false); +SA_TEST_FN(__is_scoped_enum, int(*)(), false); +SA_TEST_FN(__is_scoped_enum, int(&)(), false); + +enum opaque_unscoped : short; +enum class opaque_scoped; +enum class opaque_scoped_with_base : long; + +SA_TEST_CATEGORY(__is_scoped_enum, opaque_unscoped, false); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped, true); +SA_TEST_CATEGORY(__is_scoped_enum, opaque_scoped_with_base, true); + +enum unscoped { + u_is_scoped = __is_scoped_enum(unscoped), +}; +SA( ! unscoped::u_is_scoped ); + +enum unscoped_fixed : char { + uf_is_scoped = __is_scoped_enum(unscoped_fixed), +}; +SA( ! unscoped_fixed::uf_is_scoped ); + +enum class scoped { + is_scoped = __is_scoped_enum(scoped), +}; +SA( (bool) scoped::is_scoped ); From patchwork Tue Oct 17 11:27:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073465vqb; Tue, 17 Oct 2023 04:47:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhGK/5lmE82gxfnHBAhic+DGDw3NCtTB+meMOzoGY5d28Zn1X+nBG0NHP8+r5OAh/H/egj X-Received: by 2002:a05:622a:1189:b0:412:2911:7e16 with SMTP id m9-20020a05622a118900b0041229117e16mr2616939qtk.24.1697543253357; Tue, 17 Oct 2023 04:47:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543253; cv=pass; d=google.com; s=arc-20160816; b=rN87S6ZOHMmmrVDX/hbTX9xoQfMMHhG38S0nsK9SmWdxpSxmJ9lWkyrS2b4p/rSRz8 iGU1LaTlUXaDuf09RtqwL7VxWX/PhgtufS7ehqFx6dGS/6Y1eVX8YJ1gc6vphWmP/Pha RDBdDlqlkpuESjCZe1EA9kCSRhtowAN++9bDeG1JXFwAOL936qxtvlZJiMXCSzotiP2G tx6P1f0H7W78DbS3OuJMchNW5crdXLKuvKKJEm7rhk96N1rrRNxJVYB8GshHVYQ/Ag28 l1YjtrBZ5u/dPRwXLAaDbopdBJanxQOWzbSvxbY9C4BNV5sX91931lnP+/7KeN311sB/ B0OQ== 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=6w8/pu2bvouwsnUid4AK0QIURuqMXsP8R0XkmMz9DaQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CbMpky7QIwliYC0KnV96Aqp3U1ArVV4FkegfaNTqlsHxKeiFBLoS7L5qpJAkEXu1et JWYNsCREArNU1bM+Mmo0MVmx5ZhJLGTGZm1CjBFWFp8MntUGxIZaifAGCLF18MdAlHTW FirCainle5I5kLu32mAcVt4u5nl8bEmczlheGSYTO3K6X2mTfXRuc0N12rzIJLXptsm0 OL1X5fpjsSci/AvYnHQleAuG4/mFFWcJC0/9DEqvSdVPbpSHzl5rKWZGgwqKaVVM6cLC mNTTBB9kEb3HY57SURLH6eby9c/60VnG66J6v/fIxPxpp6bS39bZhOFpvPgGaZ5V36mb zkkA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vkeOEIR6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t20-20020a05622a01d400b003f4ecb4085bsi981385qtw.289.2023.10.17.04.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vkeOEIR6; 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 369FD38279AA for ; Tue, 17 Oct 2023 11:46:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 369FD38279AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543174; bh=6w8/pu2bvouwsnUid4AK0QIURuqMXsP8R0XkmMz9DaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vkeOEIR6d6weE9HJpZeOJQsyw3RxbqFumo0hFrucoEeauhvJ7Dv0aJgzr8gCLfKSa BTXO6PvtG5+LuJv1xQwcAOSvvm+JrZPcEHu0UGbGYdAKEvL/DzDXOJJ3V0iIydE12d xvldHDmu5f1TQpkO8f8swFMi2DV8O/VSX4RtousA= 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 88496385B531; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88496385B531 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 88496385B531 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=1697542563; cv=none; b=MUFozLY3FG27wHrx2S+ipZYxItfooqfpIUhrVKZY65IE/0Rnd2uIj5O8nPom+zWed5NcdaVxDq4BUiPNuB8XCksbFGGULvhBKppEiLqdnbVoOmaU3BeBF0eneDwBdKO7fpZQkdAouZ5F0N3dAI2/cP/9yX58TGOJ4YPZojHidzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542563; c=relaxed/simple; bh=0fJjGclj4XvwKH8AmhnNT3eHruG+WCMpFlf3cIH+UjI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vHxsYl7Lg0YXnFBxZxYu3QlTEFqgJ6Lm99J2pnv+yJoAf3aZQeGWcmSf/pgN7Sp9xr4OIsUAtrsrdbRgbRVnda/voEAwvZ5Ft18JlQ0pWtqa+ERlJJJjZRX4QMYIjPfva/MH/eJjJWPZ9yKzyuZvTSql3e3n2k5ujIb44oHOyjU= 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 39HBUCwf029695; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbatmp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZjDu029032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMR001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 14/30] libstdc++: Optimize std::is_scoped_enum compilation performance Date: Tue, 17 Oct 2023 04:27:45 -0700 Message-ID: <20231017113242.664523-15-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: OPwbnMkAfO0Fq9qSoAu_53gSLRyuEMwi X-Proofpoint-ORIG-GUID: OPwbnMkAfO0Fq9qSoAu_53gSLRyuEMwi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=818 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003114363271989 X-GMAIL-MSGID: 1780003114363271989 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 d306073a797..7fd29d8d9f2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3633,6 +3633,12 @@ template /// True if the type is a scoped enumeration type. /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + struct is_scoped_enum + : bool_constant<__is_scoped_enum(_Tp)> + { }; +# else template struct is_scoped_enum : false_type @@ -3644,11 +3650,17 @@ template struct is_scoped_enum<_Tp> : bool_constant { }; +# endif /// @ingroup variable_templates /// @since C++23 +# if _GLIBCXX_USE_BUILTIN_TRAIT(__is_scoped_enum) + template + inline constexpr bool is_scoped_enum_v = __is_scoped_enum(_Tp); +# else template inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value; +# endif #endif #ifdef __cpp_lib_reference_from_temporary // C++ >= 23 && ref_{converts,constructs}_from_temp From patchwork Tue Oct 17 11:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4071358vqb; Tue, 17 Oct 2023 04:42:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJPPLg2LDHasIzMOonHk1w1PK+ILKajOzV94wA0uKPDM7VB/i5vLNm1na4/ORVWVmiMQae X-Received: by 2002:a05:6214:d62:b0:66d:690d:42b8 with SMTP id 2-20020a0562140d6200b0066d690d42b8mr2149118qvs.22.1697542972165; Tue, 17 Oct 2023 04:42:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542972; cv=pass; d=google.com; s=arc-20160816; b=h39Sg9beJaVFwnQgUbVhr03QdYTSQ/EwxAc08DYfvOXDB3ESU8508Wem4dkYezDi4X 5+3Wf9kb/6w0rp7fWte8bLzPJVaLUZf1eYG4wiojNxuXwCkkvNaaT/S5goFlO9xn2w21 kDjvfnqwXI5W0Wv1GgDEFo7p4Lz467s6JhyOSOpSSH5J/ozLiK/DgYCQJfjBvmz9HWUg KITHQXNkAqvPhHEgwY5v65AV3OuisTzeE7tTjrPOd8sR6mTPyIqX1sucdnUE10tALE7v pAEquLX4YsXdKDijGhoeIDXlAKYkgc+Rp6XCM4OnFjxx99igLXlfAR/CjNM5MR2uV7Gn eMkA== 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=s0GI8LVbPVkNcH40twl4oGn8nFP7xw344PFmeuRO4tQ=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=pdcApGXdFp0d6qvP6hoWc/kxNjkdY5czl89OQu95/3zUUsv+Vi2yVXJC7kC9oY+Vk0 zQmQrh17epieCY3AULjAbDJIZ4fvQc01FPN8/whhh6kIuZaI3EPehXPdxuNUtf7qqZDo 1VlhdHIuJIIy4vbYhL9e3M9V9yZL0PM0PCdvLXW7Ev0vDQX+2/vnnCTwjkoT8PC+Vdz7 O8IPVLKFpatlFEQHHuT+zmC5PzNcjYbnIfl6UH7HFG8dlJ5TwTtIdyTdz7Aa/t7uGVwI nSgtDK4Z8/tiv5Y0WIcDZk6JmbYTsubuSN+ICSOfHgyrt6d/SKbzN1OPM0DGGsypvjnj Fksg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="tUy/0srD"; 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 ph14-20020a0562144a4e00b0066d16ed048asi828671qvb.29.2023.10.17.04.42.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="tUy/0srD"; 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 24E53388882A for ; Tue, 17 Oct 2023 11:41:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24E53388882A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542904; bh=s0GI8LVbPVkNcH40twl4oGn8nFP7xw344PFmeuRO4tQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tUy/0srDbGm64V8HW8r1I3fx/PrK2cMcR+x1BDZhi1I6xeY30IgqCNKvmc5Y+MR15 6XjrR39pomfrWY/ngxlChCP990ezljsPXmiyagD+XIY02q6YzztuKh97L678YQ3kZK /ZqvZ9QoLnZP51+rOCEhvSKJ27Q4gxV9TDr4TMS8= 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 861C1385B515; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 861C1385B515 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 861C1385B515 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=1697542564; cv=none; b=SMYQCnUjPDRMUhl+YywXgjbfoOnoXkRhwsPeeys8eNcwV/fha9SoPOpaB3UWKMFqKelb5fLx5u3wIDkQwFYtCAtaCQshTJMdYQtjumYsJJosTm19idrzAH8bFVyNZhaTev2miT1+yL0ysAlzMqMlvlPwsygYg+D+VMPscCK9m2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542564; c=relaxed/simple; bh=tTsXR07ddbRuc8GHnZgjHVGOldxUmME9x4Iwp7/K0aM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=S2TbyRRtOcJ8uaRev0ICzYQFctHB01VjPPFTfTh+67ITzzk35jqsyIObWUgOJq5V5CtMOsmEiWMDM7SHItvAUGrlYXK9IlbnzrVTwdaBBkUGYZoBs7siyVfvcbhxRB97xmv9irxNDg6Qm3d5XKuIcPXvpAmRRJJFmBJVa5seCiA= 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 39HBN3IP032320; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw4hs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkxL029033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMS001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:45 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 15/30] c++: Implement __is_member_pointer built-in trait Date: Tue, 17 Oct 2023 04:27:46 -0700 Message-ID: <20231017113242.664523-16-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: vTHPqD7TH_YSSwCZgCQdLxJxC_Gn3NfA X-Proofpoint-ORIG-GUID: vTHPqD7TH_YSSwCZgCQdLxJxC_Gn3NfA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=856 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997441180277793 X-GMAIL-MSGID: 1780002819505112713 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 2b46e3afa97..a969a069db4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3757,6 +3757,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_POINTER: + inform (loc, " %qT is not a member pointer", t1); + break; case CPTK_IS_NOTHROW_ASSIGNABLE: inform (loc, " %qT is not nothrow assignable from %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e0e3fe1d23f..26087da3bdf 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9f0e468f489..5ca05dde75d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_POINTER: + return TYPE_PTRMEM_P (type1); + case CPTK_IS_NOTHROW_ASSIGNABLE: return is_nothrow_xible (MODIFY_EXPR, type1, type2); @@ -12393,6 +12396,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index ba97beea3c3..994873f14e9 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_pointer) +# error "__has_builtin (__is_member_pointer) failed" +#endif #if !__has_builtin (__is_nothrow_assignable) # error "__has_builtin (__is_nothrow_assignable) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_pointer.C new file mode 100644 index 00000000000..7ee2e3ab90c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +SA_TEST_CATEGORY(__is_member_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_pointer, ClassType (ClassType::*), true); + +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(int) const, true); +SA_TEST_NON_VOLATILE(__is_member_pointer, int (ClassType::*)(float, ...), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, ClassType (ClassType::*)(ClassType), true); +SA_TEST_NON_VOLATILE(__is_member_pointer, + float (ClassType::*)(int, float, int[], int&), true); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_pointer, ClassType, false); From patchwork Tue Oct 17 11:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076446vqb; Tue, 17 Oct 2023 04:54:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH91K4nYPYEpxsmtck6JVhub6YMolGHwwwdRuK3jpskiu6ANndvWRANTq/1q90Lmxo57QT X-Received: by 2002:a05:620a:47d4:b0:76f:19f9:82a6 with SMTP id du20-20020a05620a47d400b0076f19f982a6mr1923124qkb.21.1697543685167; Tue, 17 Oct 2023 04:54:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543685; cv=pass; d=google.com; s=arc-20160816; b=Wcal3C6DVBQqkSENMTyXHoLy0HW+Ll4HZ+ba6JYRmRh8w55p7ZmSvmLXUnOLtBhSvY qLzNJ7JnEGEUVJ4YHlhcoaduAoUjBuC6LGLiJXN4kACYaMu/+DiHrJ3k6Ekmrho0+eZF NRTInC+hWPRHtjDEV56xV9jEsCMP6yu2hC+frZlndq0Al9SJ1CWdaOwmCkKhO0fy/WcK GpDhfoy/Afw+KW3uRZFaw6beehE/vAjpG+8rETbP20Sm/3985tJEG0iAz3+p5vKgTsiW E3FyPKe9FgrmzvXNCYzzo/gsFYahhfmoWvqZdj63TQMQlEBKnREy6GDky3EsJ6o+xq8C sJLQ== 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=5BCqGLNSCmRaXPYuqqLubmxriN2Rx4QdNVL9gnlY2CU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=GNcxjHR5ditJDSzox6ruSm9ckil1eDpvO29AiUXfM7V3Nvo6Z/AYKvSub0oOB2t5W+ k+vWfFSlmjMeq3sI+FxEWmuVcYJXAgKgGrEF3wUAEiN/OCh/kqNj+CkSIwfWbXkn4r2O cQS+NUsMX5P0PoamPmDk3JoxLjgb2S4QHVbILsHChERkzztvWffX+GHXhGxjtC+gC8oJ 8qlrWmPAw6C3hxL9oSGph+rjOvDJS8QNd8jJaEItGui1ipd8czd8p+n7Hyu5Vk1tOiyB 3OL5Bo23heGf9jYx/Omi+7h6/85GmDNlSXXLTzMm4NzY9siEbI9PyGoxSM56r0LZrlJj GWTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MFV2vZsk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d3-20020a05620a240300b00774d385db69si944320qkn.184.2023.10.17.04.54.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:54:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MFV2vZsk; 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 8F9B83948A6F for ; Tue, 17 Oct 2023 11:52:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F9B83948A6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543573; bh=5BCqGLNSCmRaXPYuqqLubmxriN2Rx4QdNVL9gnlY2CU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MFV2vZskCNwjuOORY1k6KUiav5K1T7aD1AIUg0mVzqbPx7V7PscX2D/2XY11ki+Ij mD3E7GUUfJH5VeSVHMhV+E3KT8ZQYuvw866cBC/jPo/BkQMUxDL5hVs7doM6hqPtrF FA08OTw2ey0Jxn/6MuAuQ4Jdfv+i1YufflBjRAXQ= 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 7791C3856DE6; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7791C3856DE6 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 7791C3856DE6 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=1697542569; cv=none; b=JdvEIMBvBrZd2hBGYMdfhdpGPn7WqTarBiIiYaVlQFq14aGGXipYtDChwTzEZmfWjWA4PDia9mE/2OKuilajhtAUSw1WNPGQKGR9+iZeQfWuR8tu0rsCyjbGp2u5gNU6ifaebvQrRxG0kJiWyB2hbW82YiEKnNrFWEnYDRA0C0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542569; c=relaxed/simple; bh=f8Yn4ts+8fO+dAvSx3E1hRc02AnbIXSjgLj2daX9YKc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KD8Ob7RvkmkeZzJGIb5ZhyXGSPKl58inqA7wGe7htS4b+YqfdW+OhLzw+2npRldnFR6gdIuNemHiVzLz4FRWeF4vneuNst7Aub8Y31ykuwVFLrErq+bH2F6ytLLy9Hk0b5z3cHjjxpXUB2KYIsZOxOjEFHjAgrt5+6qsWkE3Wfg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBNprB027707; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruvec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkE7012237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMT001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 16/30] libstdc++: Optimize std::is_member_pointer compilation performance Date: Tue, 17 Oct 2023 04:27:47 -0700 Message-ID: <20231017113242.664523-17-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: L-EbYjwmr4P9XntGIveXRJzw1NJ_qcYr X-Proofpoint-GUID: L-EbYjwmr4P9XntGIveXRJzw1NJ_qcYr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=508 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003567680885453 X-GMAIL-MSGID: 1780003567680885453 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7fd29d8d9f2..d7f89cf7c06 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -716,6 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_compound : public __not_>::type { }; + /// is_member_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) + template + struct is_member_pointer + : public __bool_constant<__is_member_pointer(_Tp)> + { }; +#else /// @cond undocumented template struct __is_member_pointer_helper @@ -726,11 +733,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; /// @endcond - /// is_member_pointer template struct is_member_pointer : public __is_member_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif template struct is_same; @@ -3242,8 +3249,14 @@ template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template inline constexpr bool is_compound_v = is_compound<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_pointer) +template + inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp); +#else template inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_const) template From patchwork Tue Oct 17 11:27:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076024vqb; Tue, 17 Oct 2023 04:53:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoIaZ4RsHLZTsTYFGn/IhqWApXukq7dKybQdjPAsGuv50za+Psx6M8BFGLVaAgbPFIGXxW X-Received: by 2002:a05:622a:130a:b0:417:b700:b13e with SMTP id v10-20020a05622a130a00b00417b700b13emr2934379qtk.28.1697543617546; Tue, 17 Oct 2023 04:53:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543617; cv=pass; d=google.com; s=arc-20160816; b=t415mtu2ZWz9kVqDRIIz1x7GbvWMs0MwBajivr5+QEc/qAQc8DlVSx7hoe+ln06LNR DFdmz4EECP/OSGu1WmKQW787GMg9O4yBUTjtp/lSFTdUyDbTwa8G3SbjQxxXaMeQod4r VfB206ICVsdV3OsmH7JZW/SN+FswSZSLCn3sfyT42DdwogzN04kTKQJuIkXF3cGBst1u y0MGOgPVO3XDmrBN7HgDqLi0tKOGjBwnBR90+VtVYswghBu8BDgznNX4THN58KJjBdG2 x02+R1VUSYVqXsYYva80YEe0MGa16+1Sga+N+re0HGt2cdmj6noUGhATTYlZasrITshG ricg== 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=bvd65+XKCvGzi4qTtRK6nRAEJc68Wgj0GRC0JgEHuPU=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=CKwLRsIhqEsTWgYeo1ED9iOOKYgfGCuCAL9ha3/fBg4d1qSBAMthUeOc5WeRQvnpJp 38flqcV5sZlTRV9i5G8ABBgEoLi0WdWT3NSllNp56QFeba70WWEAp5Y8DXZIsTdEAVBu rOf8qrJmJW3UosEu9suf7a5B0xecfLhYd9fvKK4mFwa8u2vjXFTNao9RW8KNFjMumbhH UBeeyvWxtnKcsb/gRSHQCBH4P5WVNlMnPf+ef7ZUO7nVXxOOcVgs27DYf4LvoP+e8JjP KfIElzFCR7nB3dCYna1G/qaXXrgcZ80X7QXSHyxC3aF51rJvGgXCUZobWbk0ROFXxxb+ ggbA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Mw2fB0Hb; 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 p8-20020a05622a00c800b0041981d1c65dsi929404qtw.718.2023.10.17.04.53.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:53:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Mw2fB0Hb; 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 302AE3AA903B for ; Tue, 17 Oct 2023 11:51:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 302AE3AA903B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543514; bh=bvd65+XKCvGzi4qTtRK6nRAEJc68Wgj0GRC0JgEHuPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Mw2fB0HbOG7uSYVYtoncElSyeWCa6E5BVHsoOWda+Y6XYqnnA7DpyoZDmtX5ZS0kb Ku4HmfRKzE6h2dHlfvYw9PhkiRvC5z6awvbT4hh+VJcpzfHNqQae7XHfM8jgdttHWw Fa2e3/EczW5CDsrLpb/nWOYDASABv51VvxYGtQFY= 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 5FCC43856254; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FCC43856254 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 5FCC43856254 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=1697542569; cv=none; b=ZNXNnnTPR0t2MtRHLd0jLbne+iAsOiKvY4+1GpafsgFP/kpYKUyJ0ykp5M+VQxVloKi/IUu3838TDPk/5daZFZTJEPMXg4tI5RGRDzhseac3Wz6e//TRek81IE8BxkdWn40pH9uxoejJOM/tu5CENqMjWZIQBTg7G1uvrNnDkT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542569; c=relaxed/simple; bh=Wu6uxEsGT7DwvMgeZmQ/CUhdHfQIMcBEaar3J3BUDrE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dHvZIOq0IbA60YR4kmCErq/SLzbXXzKa06lPPTSDl5OI3zFaBVNWifuT5E3SaZnFUmetcekj+1bWhkgbCJ8bmBdq2PQQYLlA63EgIlE4GozTylz9CsVK2gn4DLX11nvGFCrdHcy52pC7DxT5fA/U8+KbUmREiq95rXHeMfxfmQ0= 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 39HBQEAx005795; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsa9e5pmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkL1006892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMU001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 17/30] c++: Implement __is_member_function_pointer built-in trait Date: Tue, 17 Oct 2023 04:27:48 -0700 Message-ID: <20231017113242.664523-18-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: JFQcf2FAmnA3BzBtzFDeMBCqqUnIykrn X-Proofpoint-GUID: JFQcf2FAmnA3BzBtzFDeMBCqqUnIykrn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=911 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776995491422845008 X-GMAIL-MSGID: 1780003496188911885 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 a969a069db4..dde83533382 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3757,6 +3757,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_LITERAL_TYPE: inform (loc, " %qT is not a literal type", t1); break; + case CPTK_IS_MEMBER_FUNCTION_POINTER: + inform (loc, " %qT is not a member function pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 26087da3bdf..897b96630f2 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -72,6 +72,7 @@ DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) +DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5ca05dde75d..59aaa256232 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12184,6 +12184,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: return literal_type_p (type1); + case CPTK_IS_MEMBER_FUNCTION_POINTER: + return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12396,6 +12399,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 994873f14e9..0dfe957474b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -95,6 +95,9 @@ #if !__has_builtin (__is_literal_type) # error "__has_builtin (__is_literal_type) failed" #endif +#if !__has_builtin (__is_member_function_pointer) +# error "__has_builtin (__is_member_function_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C new file mode 100644 index 00000000000..555123e8f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_function_pointer.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_FN(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int), true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (int) const, true); +SA_TEST_FN(__is_member_function_pointer, int (ClassType::*) (float, ...), true); +SA_TEST_FN(__is_member_function_pointer, ClassType (ClassType::*) (ClassType), true); +SA_TEST_FN(__is_member_function_pointer, float (ClassType::*) (int, float, int[], int&), true); + +// Negative tests. +SA_TEST_CATEGORY(__is_member_function_pointer, int (ClassType::*), false); +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType (ClassType::*), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_function_pointer, ClassType, false); From patchwork Tue Oct 17 11:27:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4077331vqb; Tue, 17 Oct 2023 04:56:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoMJf4XflwalxQfRcgJWPCjB/GETeyiEYU943X4T6he7L0jVEkwShKD6CuXiace8xTlcZA X-Received: by 2002:a05:620a:3d85:b0:76f:1f8c:cc1b with SMTP id ts5-20020a05620a3d8500b0076f1f8ccc1bmr1559361qkn.78.1697543804750; Tue, 17 Oct 2023 04:56:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543804; cv=pass; d=google.com; s=arc-20160816; b=JV4PZ6tQM/RPZPPybXakLXer9Ymr2cX1xHtsdo9eUEHoLjyj5Tj9QI9WUdBwOQ24Hl KzoOmt//jRM5eL4J8r+mhIiMd3OPpxkyh83V8f9mHeRIks/vZYKmHGwZq4car+ZMG1YW 42FGlW+43RQ07KPbkoT23YIGcloTexltSXhV0ZZMpcWRXGDYi7OCCks6al1MdXAHhqnX SJp0Ve6IYovXagi0Vk5nb8sukHxrh7/zfFbPCc4LlbtYOzLZruR9zK1gNoSKNrc5Sr/k Fh1wI6XEmFOrto+5yXSBLfo0usbstd835lrVdbY4kuDxP0YSR7rH3rgfBo05F+ZfbO/n TYdQ== 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=N17T7aCitw2LumMHTmS+gL4bmQewOjA5Ej2IDLIDQ+w=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=PD8Uq3jCmDjiug1MK0jiM+S+xlNXUQu/MfI0Zo6AYZEfCq47kuFCB63irRvlfp29yn 3Lxqllz0OAM5CulfdwCCGYrBnTXu7bowAytQ9nRvyBxn3ak0AKeVU9oEcKQ9Go/AE7bO pSbo73CF+JhinhcJ9YJZksR7aWXRZkaxhwzLNvrBgvljNgc9CIGkswoiaCPWMasru2t4 yXElZMZyKTWT/eNIE5AQNX3xfgKMHfs+R0abdxyfKglQrHZyiH4etibu/arEDM383Fge tmr1btiS9/OjLeH40fTBnkqEwasMNE7v+j903bmd4Gu++eaZ8A2rVlJrXRuy/jZRefts 3VTA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mHnvgptj; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 9-20020a05620a04c900b007742a7ffa0csi905364qks.155.2023.10.17.04.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mHnvgptj; 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 A419C3948805 for ; Tue, 17 Oct 2023 11:54:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A419C3948805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543690; bh=N17T7aCitw2LumMHTmS+gL4bmQewOjA5Ej2IDLIDQ+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mHnvgptj44v1SIg8CzCw9fVQeC6EcqRMNxV2bcCFG6qJXn3cAbg6guVLbfW0ecaBa 8HVUFnR1Ab2LE9GUlQCuVkBPAEQOeeC43Msh3bANBhE2pleB/weEi9fKrTXIiBjorx z7Cz1Cqdth9rl3Lf9puW2esQZOcho8MJ3sCMVlX0= 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 B291A38560B6; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B291A38560B6 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 B291A38560B6 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=1697542570; cv=none; b=nGIzl0BOWWCyzFVtATfEs8fs2HgW75RkHVfhcOe/UmUZE8z+QXer1j5iecUYEk7VQ4R/sGDhZzY2QnRA2VBvZere70SQJaZOp89Uj2t32Nos4LTuj0Q1ADix2LSeofD0SpbLovVeunLPi0OHxj6lQ34eEoFtpzlo3ZYksGvyHQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542570; c=relaxed/simple; bh=BeAwYIzK7d5/iToyc1oLwLq2kGHJhlp/l7AS5fX4HMw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PdETpuqNln9jd/tCz8hUL6TFRYXP3Ae9p1d9yiJlViLNhbp7g1mtmBCE4kTw2QikZT2w9ZLWVu8WdRNjFX2FW3kZi43BSHxHiRkqkvekZkpg1FJdiUiKIybBkOvYvjPGMMa+InTlgbibpTCju27hNJ4L3Dl4s+8kNC14TCSc7/w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HB9ntj002709; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruvee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkY9017739 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMV001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 18/30] libstdc++: Optimize std::is_member_function_pointer compilation performance Date: Tue, 17 Oct 2023 04:27:49 -0700 Message-ID: <20231017113242.664523-19-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: bfBPixh2yw1xxQ8Knjzw2sIPct5rekhp X-Proofpoint-GUID: bfBPixh2yw1xxQ8Knjzw2sIPct5rekhp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=594 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003547168618314 X-GMAIL-MSGID: 1780003692457751537 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 d7f89cf7c06..e1b10240dc2 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -588,6 +588,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) + /// is_member_function_pointer + template + struct is_member_function_pointer + : public __bool_constant<__is_member_function_pointer(_Tp)> + { }; +#else template struct __is_member_function_pointer_helper : public false_type { }; @@ -601,6 +608,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_function_pointer : public __is_member_function_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif /// is_enum template @@ -3222,9 +3230,17 @@ template template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) +template + inline constexpr bool is_member_function_pointer_v = + __is_member_function_pointer(_Tp); +#else template inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value; +#endif + template inline constexpr bool is_enum_v = __is_enum(_Tp); template From patchwork Tue Oct 17 11:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073151vqb; Tue, 17 Oct 2023 04:46:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzMMaqTuIo55HzlMVF5h9N5/zHQLhQXEt+LCx0pxzDN3rOkSpqeDB+KQN7WVrm/qC6v6U2 X-Received: by 2002:a05:6214:d8a:b0:66d:13b5:ca16 with SMTP id e10-20020a0562140d8a00b0066d13b5ca16mr2601925qve.27.1697543219124; Tue, 17 Oct 2023 04:46:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543219; cv=pass; d=google.com; s=arc-20160816; b=dX6xtJGmVbD5KXYYE2oGPe4eLuIxrggjm80Vzf9StGl0Z7+KYzLByvW7Q0HM9iGSFX 1jmuruxMcZqcXehJn4AyWAsCmEnvFmilAv62Z6/vsGKAT4W2qLtCToGOwrc/QyuCI/u7 tCLv+t22eIsLRYXyutNiESGEAaF3zYbyn6/gCkj48G27Gjn1J/XQ4DZI95wp4RaEb2Vb tao+ZhTVmPmZ48+OU5bniJQxj0V64Q69rZGmEVL3cJXv1lwq25VbDtnInIN/9VenqIZV THsw57e2Ny4vgiOAaUY7pIurTTc33h+emRNgpT5R5YFJCVt2OOPqCsVATsEZGUIrAIe8 tqHg== 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=gGBdcQ+YEc4rY8cO7yuYgGoal2BBq3pAmBVeJ2+PDSI=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=MvzWFN1EJS2egw0Y4QguWX4a7fAvmAxZpgshZBl8gBczZwZ9GAAdTtFeqWt8siuflx mpvG/u19atrm19G8LzVw+TvhYdS5KSbN+iXJbWGP1WqaZDrSC2/czp7oj5kSJNPm4TLh fPnG81V0JL3okEhiJDPA9ioiJreiFHimM8v5RFKyqLVd0az3QMvNmJbqIBYi1hxGgda5 jSBXk2Y/VnrRNy/04eSNIakSI0qpNXZboM/Vdw9AAkibAoqxymg3Je38mA8DfvSLvGMa Dh9q9A5eZyP2AzF9uu9Vk96sHQqfmS6Dtdz1SU//zFxYvd04JX4YR/hljKVYq+n0FPiu qx5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lli0aUO3; 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 do20-20020a056214097400b0065af80f546asi830972qvb.2.2023.10.17.04.46.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:46:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lli0aUO3; 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 974CA385353E for ; Tue, 17 Oct 2023 11:45:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 974CA385353E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543139; bh=gGBdcQ+YEc4rY8cO7yuYgGoal2BBq3pAmBVeJ2+PDSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lli0aUO3qDIdyO1ksiMElPjAhXx8hBo00NePkfCPGuED9Bdmgq/T0HCnb0W9K+UWp U8zBwPI3CCviAqEAEXXnb276sGPYmwJdKIvbIRP8ieX47N6s6jRruS0hR1Tzg+IPpH 8rmzHG44QqoPG6dwkVPNN48tx+DiAb72hv0z9phM= 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 EC11A385735E; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC11A385735E 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 EC11A385735E 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=1697542566; cv=none; b=cdqUI2e+162iCRKDjhscySgChe8xmkaNb2UEafes5PDTqBm5N3KJ7ShIe1zABIGaA5kZdo90M5E9g6551IEJTxoKzuhcgck8bHkrZYWfRWXc6Dk78n2OcCel5lmgOzu4XN6zsD0cKluBrpKhXnhfC/JB5OJcMlMsuz7h4Dt7RFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542566; c=relaxed/simple; bh=UVqQ3VYH2YZi75SlDBCPNmo7P0UtuVGM7vsj+lXPHGU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qI4AQ6+fvX/oitizslc0bQvHX9aN/7jt0MKMnxz0pdWlzpbFlegf0wZbLKND3oWHfWPxv0wH0UV8wOVwUGGoPXOvMuiBtPd2xsbzPMyUyez50NhhRKmDCg5PeWrjX4w1Zsnf060sopJhHNLIcDTT9d6+539euxRa4xuZyUi6QQU= 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 39HBZEEB002974; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb6cmx7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkGS004223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMW001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 19/30] c++: Implement __is_member_object_pointer built-in trait Date: Tue, 17 Oct 2023 04:27:50 -0700 Message-ID: <20231017113242.664523-20-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QlU5dt_lz5yNlge8eTsAjris7I1g0A7R X-Proofpoint-GUID: QlU5dt_lz5yNlge8eTsAjris7I1g0A7R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 spamscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=936 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997539192739394 X-GMAIL-MSGID: 1780003078145599942 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 dde83533382..9db3a60943e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3760,6 +3760,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_MEMBER_FUNCTION_POINTER: inform (loc, " %qT is not a member function pointer", t1); break; + case CPTK_IS_MEMBER_OBJECT_POINTER: + inform (loc, " %qT is not a member object pointer", t1); + break; case CPTK_IS_MEMBER_POINTER: inform (loc, " %qT is not a member pointer", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 897b96630f2..11fd70b3964 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -73,6 +73,7 @@ DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) +DEFTRAIT_EXPR (IS_MEMBER_OBJECT_POINTER, "__is_member_object_pointer", 1) DEFTRAIT_EXPR (IS_MEMBER_POINTER, "__is_member_pointer", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 59aaa256232..c7e6396370d 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12187,6 +12187,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: return TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_OBJECT_POINTER: + return TYPE_PTRMEM_P (type1) && !TYPE_PTRMEMFUNC_P (type1); + case CPTK_IS_MEMBER_POINTER: return TYPE_PTRMEM_P (type1); @@ -12400,6 +12403,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONST: case CPTK_IS_ENUM: case CPTK_IS_MEMBER_FUNCTION_POINTER: + case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 0dfe957474b..8d9cdc528cd 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -98,6 +98,9 @@ #if !__has_builtin (__is_member_function_pointer) # error "__has_builtin (__is_member_function_pointer) failed" #endif +#if !__has_builtin (__is_member_object_pointer) +# error "__has_builtin (__is_member_object_pointer) failed" +#endif #if !__has_builtin (__is_member_pointer) # error "__has_builtin (__is_member_pointer) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C new file mode 100644 index 00000000000..835e48c8f8e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_member_object_pointer.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) + +#define SA_TEST_NON_VOLATILE(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT) + +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_member_object_pointer, int (ClassType::*), true); +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType (ClassType::*), true); + +// Negative tests. +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (int), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, int (ClassType::*) (float, ...), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, ClassType (ClassType::*) (ClassType), false); +SA_TEST_NON_VOLATILE(__is_member_object_pointer, float (ClassType::*) (int, float, int[], int&), false); + +// Sanity check. +SA_TEST_CATEGORY(__is_member_object_pointer, ClassType, false); From patchwork Tue Oct 17 11:27:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154108 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4071723vqb; Tue, 17 Oct 2023 04:43:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzXhkumWsETEbeIYDISNFZYFxcehlwFURSC8DcME75q+7j6621Y/XBK7XuGix7dhtmA+xM X-Received: by 2002:ad4:5b8d:0:b0:66d:1b4c:e85e with SMTP id 13-20020ad45b8d000000b0066d1b4ce85emr2577854qvp.4.1697543036222; Tue, 17 Oct 2023 04:43:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543036; cv=pass; d=google.com; s=arc-20160816; b=WT6TraGnyoxoJ99LCSr6Y3N/xBgimJzJHyJSqmjqsO8pUf/8pJDafuDAf1vmx/jD1E lFtdaoxmhJkvNEn2UBYemlAwTjx1cWZN0uFZk6oXxQR8KrXuXJYf0S7rvQfOIqqqNk6S iYaI8DR1RpYWd+ubWKZ2OnVudH54qw08TMnYKjSssZuCIND8J+JUJ+0qAib+5HZncR5D OpPZwoSmC5kMRUczOLd1ozkA/gt7PnO6hBYBGaobuOyJ77rq4nalaswAErcV2iRdc6oP KbUpaEaMeKgc7sXOaAg2gke+waBW3G9xNacAp57IRvo7td3oh6mldhHZ+nW8C8usjY6X udGQ== 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=QyCvgHiTzY1jFYQtDMBYvJCe9IRXOXlXmEJ8y1zP6vk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=RQIyk41P7euwb+0I1FOZim68CpcN9cM+pDbxDhZ3z+qCwBbONRzaSPSKeTja5jglmL r3rsfbb2NmSDMoFGDn8kvRsCM0xk8CJMbhgLKnZ92UHu8oxUb7YSHYOYYP3BOZlUJeB4 LvjXIbd7k7po97ktBsf6oiu2sCSIyJ7lfvo0Zs+vy93tDMD40hkmbsUXTPNQwfHB/tIr h/nNprE1+GsM+ZzHQ+boAIjdcToaigN2velgsrtgU2G+Z+IZoPLDbFcHtM7XkAqY20W8 9/OZXS1q1C1Rx+yWJaSKRzNlaAmKETuM2WssMaTzrKu/gQfSESQvDwAVkPImlCiltXv2 Ku4w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EKG0eyQu; 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 k16-20020a0cd690000000b0065d0d62e13csi854084qvi.600.2023.10.17.04.43.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=EKG0eyQu; 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 32DD23882674 for ; Tue, 17 Oct 2023 11:42:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32DD23882674 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542959; bh=QyCvgHiTzY1jFYQtDMBYvJCe9IRXOXlXmEJ8y1zP6vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EKG0eyQuQ/24ny1qvhqT29UZAaGMpkecgojtd1cU1VAUeYS4vswaxOQWEqR/9W+hp X0iAeBuRCxGForHL/ZTcoDmBujRYFCklkX8Dc3uCPH2yi/mq6Mc8gpGZCGOJZ1Fp/4 39jxU1qe3lBeamC+LxJNW2WKeJcL6hFwL+Gfm8pg= 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 D22383856DDC; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D22383856DDC 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 D22383856DDC 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=1697542565; cv=none; b=vwQuRN8Knp5pCW0Jnx0SixOA0Q97t/6fiMVxrHZhPX7JWbQ9KZ1CISDrZVoHVvuyDCa49xjPKgmS8nxAEn872u8nODdQwlSR9H6zn1YcPCs61334E30V0Q+7GxaH91IXeYdIQ+Rjd9zUmnVyN3vMAWH1Gq+WYFHEIGoy2OUjuOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542565; c=relaxed/simple; bh=xgV0HhbeIOEZQRGv6DisRL5pSBe9b6hh3c7MgByCqhs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sfhdE1n8sftJbJXHN0LC6T0veul3FLnNDbGe+4G8UQEgEccgTtM3mgjwBvE2014lTEbCnt72MxHOG3XCW10f8HqW+QrMz1kdmRZE1Dmc7XivBu4oNVCBXXcbngL32hHcpydj+ftqujq00sqqVXmJDQg7Z9QHUlggvBk6WlW5X34= 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 39HBUCwg029695; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsegbatmq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkXk004246 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMX001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 20/30] libstdc++: Optimize std::is_member_object_pointer compilation performance Date: Tue, 17 Oct 2023 04:27:51 -0700 Message-ID: <20231017113242.664523-21-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: bfPTNgt85QFeP7MB5JSgeCUIm2WMsQ0d X-Proofpoint-ORIG-GUID: bfPTNgt85QFeP7MB5JSgeCUIm2WMsQ0d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 mlxlogscore=524 malwarescore=0 clxscore=1034 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002886817829020 X-GMAIL-MSGID: 1780002886817829020 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 e1b10240dc2..792213ebfe8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -574,6 +574,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_rvalue_reference<_Tp&&> : public true_type { }; + /// is_member_object_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) + template + struct is_member_object_pointer + : public __bool_constant<__is_member_object_pointer(_Tp)> + { }; +#else template struct __is_member_object_pointer_helper : public false_type { }; @@ -582,11 +589,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_member_object_pointer_helper<_Tp _Cp::*> : public __not_>::type { }; - /// is_member_object_pointer + template struct is_member_object_pointer : public __is_member_object_pointer_helper<__remove_cv_t<_Tp>>::type { }; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) /// is_member_function_pointer @@ -3227,9 +3235,16 @@ template inline constexpr bool is_rvalue_reference_v = false; template inline constexpr bool is_rvalue_reference_v<_Tp&&> = true; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_object_pointer) +template + inline constexpr bool is_member_object_pointer_v = + __is_member_object_pointer(_Tp); +#else template inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_member_function_pointer) template From patchwork Tue Oct 17 11:27:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075056vqb; Tue, 17 Oct 2023 04:51:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvAdVy8kTIrI603caGQacEJ/VgRet2TB2IKv3REp/vj3ps4vxhOqaO+hBy4lvPV6qkVXVx X-Received: by 2002:a05:620a:3a42:b0:774:2afe:97c1 with SMTP id sk2-20020a05620a3a4200b007742afe97c1mr1868101qkn.27.1697543477980; Tue, 17 Oct 2023 04:51:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543477; cv=pass; d=google.com; s=arc-20160816; b=SqkM8XnWCoyaVDZxQ5mxDPiWZqfBW+q5Tupxae9KwLddf7GfPQ0mizZUsqzsh4PFJ1 rVq3S35K4RmCv4A2z9KvYiHRSsxeBtD1Dykav8Uti6Hc0dHs2J6K0T5e3aiO6zatEZ5C sEhHyFiLRbfLmOJasZrCstdaXYSVSi680ktiuR+Af8ui5yUabSuFHtma0e1IJ9cDVLAi 9PqutlXVBHbsOk72qhqyNBEImaclCdN8AAjlqCfKGbgp+3AYONmcgJN8+F/InJMgW/A2 GllmmerD+1XIARy9IaW1pjGk1uLKvZxHJoYfgb8OdWRcluW3Jq9voNZFq2sH08QtUEss 45oA== 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=e62m0jOUnR7I7vTRzZ7uRVcwuOT6H45wBZ0/PmMVg/k=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=snkXNZ5i1zMDHnyMB/tArh1mxqvz4y/8QAtYAwncwsW6WlwOA/80yFvGE8dt/dYV8v 6NBXTlWuKk0gs+uS9yf3eQiTccgpPpgu5/ZxQu3655PS/iTFcaUU6KMZwHwgpA0ICMOL 2jimDKNbx2LkCT8It+ja4ELJw6SaVZqMXODF8VZ3NZqCu0xJKK5PbY2kKPhsw6wN2+vm DFwA/M9c8Z3XG61CL7vCvtDSOnOSbuvWfO2iUWFXXMI7L27ThdYjnfthsp75kBvnUSiJ YTi3tNHFeFw6vlPb4V/LeCRLh5uwMqzMNElEYmg7ua13wGcwpEhGT8QUiCknvkDIiwfq EaQg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QnzgFwZR; 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 b26-20020a05620a119a00b007743448d7ddsi941904qkk.212.2023.10.17.04.51.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:51:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QnzgFwZR; 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 4F1703856975 for ; Tue, 17 Oct 2023 11:49:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F1703856975 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543378; bh=e62m0jOUnR7I7vTRzZ7uRVcwuOT6H45wBZ0/PmMVg/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QnzgFwZRdJZhVrF9VZiTwg6ZooCZcuaOFXgnBDqT54o3PsCBJYijZ6DGB3mWQnP7d v3MjTphQA3q3IFVHuQyHbCjAVE6ynmB3Cf/068gWkBz5VnTHeetJHVvhewVJiz2SfR mtKo6TZ1baNYKcSBWa6bgbXZfY/kng8P+5TP04Yc= 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 05A093857736; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05A093857736 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 05A093857736 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=1697542566; cv=none; b=BxSd5e+Pde3AuJqTL6rv42QnBuKFqAkmcGdGSaWQ6xCCZ9n+YPbKniii6n97uWoLk0taqBbyHaLj8XwvXTmSw8ZwDEPUnWOJnKdkD+iaSzC4n5hcMW54T3EXlYol7x5w0MSgg3lHIf5LKOnM8yhY72lR1SeFEseho0Boo3O4k3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542566; c=relaxed/simple; bh=44mnHb56z+5WE1rdQYxHO5/55BkAITix9zVSDG7Bbdg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=MZqyypiAGjetgf+2D7aqA/NLOZCEr4uyTU0fBg9jWL7bf5srVMLKiWuSCVmIdY2Nrtm+rh/qJ5pBcM/dQ1rPHC96nY2wdceiyphtQZmAeSNEetAwpMPZ6n1igtMnYCkHGB8Eq1eT36eMJnPAM4xF2BOvysbU3N82u401751QvQU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBRXHX001961; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruvea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkMU029034 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMY001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 21/30] c++: Implement __is_reference built-in trait Date: Tue, 17 Oct 2023 04:27:52 -0700 Message-ID: <20231017113242.664523-22-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: QMffvVUvRzpLD4lXvJyhA8ORjPricye6 X-Proofpoint-GUID: QMffvVUvRzpLD4lXvJyhA8ORjPricye6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=743 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776996081559193793 X-GMAIL-MSGID: 1780003350213834624 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 9db3a60943e..e05d4fa4d20 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3788,6 +3788,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 11fd70b3964..e867d9c4c47 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -81,6 +81,7 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index c7e6396370d..cd17cd176cb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12211,6 +12211,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: + case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: case CPTK_IS_UNBOUNDED_ARRAY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 8d9cdc528cd..e112d317657 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -122,6 +122,9 @@ #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif +#if !__has_builtin (__is_reference) +# error "__has_builtin (__is_reference) failed" +#endif #if !__has_builtin (__is_same) # error "__has_builtin (__is_same) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Tue Oct 17 11:27:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4075559vqb; Tue, 17 Oct 2023 04:52:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpR9bFCVURxK7N9gpMw25GYXTm7SHvLRG5kYXaTdF12ciN8M+oTgJUizg1TQpeRi22XVqD X-Received: by 2002:a05:6102:2006:b0:452:85eb:e36d with SMTP id p6-20020a056102200600b0045285ebe36dmr2071316vsr.20.1697543547480; Tue, 17 Oct 2023 04:52:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543547; cv=pass; d=google.com; s=arc-20160816; b=UT2uzRRuDKpm07hg+1tvR+87RaTne7ejjZEVsSi2BvA8uLX4BnmnGcx4H1pzHExvSD jUPhwgvG3uo8wmzH6+z2eMpG+BbL+26cc+cTxE4xxQmOq7uY0mAvQ+QgyRfZnqZUWPou Px5k8NZoLt7kBWlwmcJDSx/v/zNY0wiBkBiPgzOxQBIrRH159+rY8fbefCenVZz1tp2T YAfsjJOx6IgUw8843lkPymvY/uxJCE62QB1Ur4XTEnCccRl7ZTAlTbDoDQGKfjcBi1wK 1c9BKWDpojf9UCm4mj+xyiPMAujo4IiJlxICNN8q6pg9qhPxjJlFloG9bcWUeUELJUsg efmA== 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=rD9Ixo1azXYHHHB/BRXQ4O0ZhyFrXng+m93wtWrxPGk=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=ED1sT+td962AjFTrnu0cewMuGjBlynwCwJet8hVXp6J+akHg5FJ0DzMEPRuS+Azam3 0MhJbEGPJeBRz5aD3CPZqu+ZCUj0f/0+lMBURE3kWhU0tgQuwaEr+j/RmEkE9Z3TJFPg qeWlANgs2wVNLtMIaQfbUWeSyiM6U7d1YZxyAa2TYfwgRVmdvnq8CtJbEeEAcIHs9TdX 4j8A/xm/h+JENL4ypxMZll3X35oj00+CsdP3fnozyFjFAhDZSy2A7RfenlqgEFWdZHpS zPy1LNmZFZOJByEzWpZmC9UYDQdlsDi9xXY6mpoE0Ocyc2c1z0OX4iPO9iFEsjBiUk/X sfZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gsW7rJnR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d8-20020ac85ac8000000b004198562004csi992757qtd.521.2023.10.17.04.52.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:52:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gsW7rJnR; 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 7B3EB396D825 for ; Tue, 17 Oct 2023 11:50:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B3EB396D825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543448; bh=rD9Ixo1azXYHHHB/BRXQ4O0ZhyFrXng+m93wtWrxPGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gsW7rJnRln1KBrM6/M75lg355tv7ShO0f+JRK5WuLjfI+qAipTq0m+G377hMv3xRf jsEe8kcV1VHwbIS3ves6jt2YP+Shb8TZW+aGVeA685+P18nwEPaHviPsQSLxtViULE 4jICIgjHtlJCkxHGlDt3B2osV9oxI2Yp4xIxY0XY= 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 5CD98385624F; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CD98385624F 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 5CD98385624F 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=1697542568; cv=none; b=lvbZPlWoyFu0XBkciq1byST/ntPsJgnK9FIoyCGR0TU9DAxghGP3wK/NEpV5whlYGC82rDbMFlR+oJSPRztQiUxoCZl9N6cxgdG88cOn5SvjqgBQFrbuds5/7FuVeI3NgsyeU+xG6+OaFEB83z7oXbE94LFGnUqpykOegD7seJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542568; c=relaxed/simple; bh=XDazgY1fylMM2iWndx0Ss7j6lazHiqJTozl1aJbBepM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fcItpLJuyzGs52+SwjL484wLi/zdG04zTS2MS/ElBD4xk5alqLEgdyCEgeoUZ6dq06y35Oj2CGqmwle4zxQV/lOZOnL0of36OVbkCkCyjT7pOH04hbqL15Xw/Ho9+av3gCTPFTLnsB7xox6rLYHpbm4EENrCIxewJswKwfoTmS4= 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 39HBK2Bf026445; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40afvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZkkA012238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:46 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMZ001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 22/30] libstdc++: Optimize std::is_reference compilation performance Date: Tue, 17 Oct 2023 04:27:53 -0700 Message-ID: <20231017113242.664523-23-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: ejgq3rwyEVLB6f5FsKsuuFsHPMOGBFGy X-Proofpoint-ORIG-GUID: ejgq3rwyEVLB6f5FsKsuuFsHPMOGBFGy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=711 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003423168701575 X-GMAIL-MSGID: 1780003423168701575 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 792213ebfe8..36ad9814047 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,6 +682,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -696,6 +702,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template @@ -3264,12 +3271,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Tue Oct 17 11:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4076855vqb; Tue, 17 Oct 2023 04:55:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVosaXhd8XViDYdacH/vBseTNNaHKpDT7OpA/Pi0c71qdPp3z0FHiXWMJpF4XOGaClWXml X-Received: by 2002:a67:c314:0:b0:457:d479:574d with SMTP id r20-20020a67c314000000b00457d479574dmr2000869vsj.12.1697543748817; Tue, 17 Oct 2023 04:55:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543748; cv=pass; d=google.com; s=arc-20160816; b=GS1PK1isXaTrQfDqVB3m65Ugy8aKcNV+dhcTxOowOdio7wHuwWbKGQ3CkWXh+ByMT3 CBWsJrYBPXJDEh/cjuRgHPB8S2ry9c+tCNHr9WLjMcP6DwoqgP0sXnagxiDorFcXVDw7 79Ajqo1lao6WiTNBraOH8DCrWMDDpkS5lp5S556Eh3cUYVZS4jtbdR+DLQ8OymVjhTC9 NHqrg5jxNh1Sd0o8JDRtbh9ZjBxvB2tYBIL7HK8DbGHA6kCwD5dIhtofzAs35R/buAwW xGB7I03F/rbN8QjuQAE1H8RnC7+BtDw2KDPQNrm/txMHSVw9kfHdP+aY3wY0ZcQZuXro 6Gfg== 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=QA/mFJW2yu6aBP542WV9rcrx+4HcUjO8qWSjUVnLld8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=n/OGod9hxjbFLUFTZTB15se8WOigLyu8IKR3h4Lf2b7/rM34xDjmW0jE0JKXZZD9ip 3aLeK+GGX7R7/AjAurMDT5Cj0VvZKI5cTWDsEKZaFIUdgKlx5rO+5pWEln8h0wS9rGCz OAy/ALHyXQMCn/Q9r4Z8fBUzz9BYbtpk/uZUPRKNuMf4dOJYNT+Q0YBHFgm8mVygp5bW rmmPLRyHml2cWCwHadKVjjfe2L9GQJTLnVqvyogcxOldwxgojORJAPKP2wLwGe+F50PQ /kc65jFkw23Zr2baek2IGOvEum1TUHBSgeBvFkCNr8SoId3rKE2/Vqi/rY7zJLRWQLjn +zVg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FvE8FuAM; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f39-20020a05622a1a2700b00410a29261efsi993231qtb.287.2023.10.17.04.55.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FvE8FuAM; 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 E000A38754BF for ; Tue, 17 Oct 2023 11:53:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E000A38754BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543631; bh=QA/mFJW2yu6aBP542WV9rcrx+4HcUjO8qWSjUVnLld8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FvE8FuAM6Wv2wI1vz3NUTGhuw8v/wvnOFeQN6W5fegJuy87H1DOV5FuDBGG0Ua1E6 XsNr0A4f68Ecqje3ACM31gkMcQOdjFK1q3wU6BgCBuZU0U6rYoLIg3hL2Kj1UZKNtM 7oo9rp5XEbfvrtimWQMnPdWbmovoL9xLfMDdRepM= 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 7AB7F3856967; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AB7F3856967 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 7AB7F3856967 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=1697542569; cv=none; b=oc0ZypjPKTQwAEJqGMwCcRBiPHIU9tDwFMnynLKxo43SvVXs4NA9PsYhgBtFPsf6yw/X3ypwaK4oRQh4cmSjbTV2x23vjAdB+56AMLQJRdyExQ4Q4AcgiLE14WLE2ctprh8mksF57J5Gkl+u+7sbjre0xg20XvX98X1OwMDp14o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542569; c=relaxed/simple; bh=mJ/BPkZ4Q1g1t1lvGmGKWZc/pKhsmt8XDUgZwN2ajRk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DrKkQ5udPRoG+jR5Wz3KEuOVeDmblXTG1z6SUFlHiFeFPpArHqW2DsnJ0nQiYiLGvEelw1A9HgGOHsEAIGfClEBGW+QVUIAncKhtXTt3iTDnE5+OEiRjj/aeCRX9hj+48Is/mhvjN4DupxtPsIB0eGPuB9s3ZYNCc0xq0Yis2MQ= 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 39HBZEgj002970; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb6cmx7v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlHp012239 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMa001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:46 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 23/30] c++: Implement __is_function built-in trait Date: Tue, 17 Oct 2023 04:27:54 -0700 Message-ID: <20231017113242.664523-24-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: X_CcGzmLqmrito_q_7qM36pAaizXSy3c X-Proofpoint-GUID: X_CcGzmLqmrito_q_7qM36pAaizXSy3c X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 spamscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003586802560888 X-GMAIL-MSGID: 1780003633792356600 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 e05d4fa4d20..c394657d6b9 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_FINAL: inform (loc, " %qT is not a final class", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", t1); + break; case CPTK_IS_LAYOUT_COMPATIBLE: inform (loc, " %qT is not layout compatible with %qT", t1, t2); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e867d9c4c47..fa79bc0c68c 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -70,6 +70,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_FUNCTION, "__is_function", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_MEMBER_FUNCTION_POINTER, "__is_member_function_pointer", 1) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cd17cd176cb..8118d3104c7 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12178,6 +12178,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12405,6 +12408,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_CONST: case CPTK_IS_ENUM: + case CPTK_IS_FUNCTION: case CPTK_IS_MEMBER_FUNCTION_POINTER: case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index e112d317657..4d3947572a4 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -89,6 +89,9 @@ #if !__has_builtin (__is_final) # error "__has_builtin (__is_final) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif #if !__has_builtin (__is_layout_compatible) # error "__has_builtin (__is_layout_compatible) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Tue Oct 17 11:27:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 154097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4069983vqb; Tue, 17 Oct 2023 04:39:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExjFvnbd60y80l+tUwFbvc17hVCHLW87JaFA6aWDDKyyQZALe1CsJ5V6w3dPaHM5FCSqnE X-Received: by 2002:a67:b048:0:b0:457:c9ae:6c6e with SMTP id q8-20020a67b048000000b00457c9ae6c6emr2191307vsh.12.1697542780234; Tue, 17 Oct 2023 04:39:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542780; cv=pass; d=google.com; s=arc-20160816; b=lPmtI7HLhc9V0dUiQe6XmyotaYDB77dPjrZQCL8BT3m8ebTxUVf2JyOcIHI/JISzQD sY4CavMNGqm53eMsl5FETOcole+cm5fSC4WS7SwFvI1/mkwqdjN2qxvSiGXpEEUrcCli F7YDU/PeA8tmg/tFsTgwFnoRwhvw1L4JiLGM2h8I6pvFScMH54u2yH9+1YeuZ6mHRY/o aOJTQQbozelFrQ4hcVMEybclFVUBvnJbKKgdGmG9qzQRNn6R4oWJszxzFUJ0E90pnC1L 0Zp5M7N1NIWWmu3pHw7So5yNdWaD4E4NuAo7NQdUd7V5Dp6IXs5One/ov6Xc3O0KLVQ6 ofXg== 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=MoFGZrXYWQnuxLLXozlmHXoHbLqNuKGteZmjnUBj1G4=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=VbNXg4zTrmi6of/oqCnZ4n3VkOpasMeZGgxvyToFKBbKo9JAZcICGsiujJ4OYokqeh P9plJcxn8L4/1n2KWGE4DrHTtMRVAckUgh3sk3Mbz4HT+A5CCluorhqrgi4CF4yiXnyU aEEKuThedmidTD1sgGNUrr2/+NzYdIhQfEY4L72/RhkI/28MuQRQhVV9c3QE/n6IF9LM xy4nKYyiwEHiPl6gtPVYbffcSjoYhxLKYaZq9taQkGWkoWuchBoVna28tFRK51v06WBt dZ9yLiBmOlatdHswXq6XGLP4yytT6Od7vOXmei0qT5i9/+rLixEnSSpEumCjxBp/ElO8 bEmQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sZnrwSZ+; 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 t5-20020a05622a148500b004199dd362ffsi959832qtx.402.2023.10.17.04.39.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:39:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sZnrwSZ+; 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 84DF23861858 for ; Tue, 17 Oct 2023 11:39:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84DF23861858 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542742; bh=MoFGZrXYWQnuxLLXozlmHXoHbLqNuKGteZmjnUBj1G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=sZnrwSZ+Z+shyeh/pXF+9lsKG47L/9QsiSwbLI7RuCWTZgTSw8IZhwZMvh+FxWEPf QbG22fd61e3G2C8N9w3RUvMxCyCZ63evQrBdbuL2njQ5fn6rPLYnRe1qQGQwYdv+se uDrLNLE7D8uSsCmbRAtLr2Cy3Zwzcjtsf+20MCIk= 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 1C296385B53E; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C296385B53E 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 1C296385B53E 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=1697542566; cv=none; b=EYCNKpoOm5pWmUkSfVj9VjSmYoZZfLOIeW4gwqXk2dHzGZs1qSGBalyqozBciEnGy06BC8bpz74GvGnBReBty/heLz/F+B/TpZyes+/8HbJaiaKpfpvmMWhj8u+t0t4J37Innp3YomoKFsFo9xX6BVdIJI9yUjaJKbj2wImxoog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542566; c=relaxed/simple; bh=Gm1sCosWhoGfMkhnlmEt/iwf6ndEw3EeBrJJMskswyo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NWPMRFAgRCsBZn7s8UB01Ha22UV00hqX/a1uT3aJaRk7i1DtYuj6GbxnLEWWc8Hh6VKhH2c6ykYO0nZuW6weCLwLEAMF3J6MXLzH5LMgETCuX2RSphsbfkR4k9xjsWn4Kuq8/UqrjxJ3/voW1t2N4NjWJQnZjC4XNeB3rAmjqrc= 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 39HBOQc4002951; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsa9e5pms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZltm004608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMb001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 24/30] libstdc++: Optimize std::is_function compilation performance Date: Tue, 17 Oct 2023 04:27:55 -0700 Message-ID: <20231017113242.664523-25-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: yTSdIWVY_FP1yN7SK1fsh0Gg_vSMMHEE X-Proofpoint-GUID: yTSdIWVY_FP1yN7SK1fsh0Gg_vSMMHEE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=386 malwarescore=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 clxscore=1034 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002618169089074 X-GMAIL-MSGID: 1780002618169089074 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. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 36ad9814047..bd57488824b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -637,6 +637,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -648,6 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #ifdef __cpp_lib_is_null_pointer // C++ >= 11 /// is_null_pointer (LWG 2247). @@ -3269,8 +3276,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_reference) template From patchwork Tue Oct 17 11:27: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: 154132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074606vqb; Tue, 17 Oct 2023 04:50:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgBtoYx8D/kncHx6lPWdu/E693y/fY116pqVXJwbSzSDaVxNHkvUeh+syOKgPMScyrumyy X-Received: by 2002:ac8:5d8e:0:b0:418:cec:5e64 with SMTP id d14-20020ac85d8e000000b004180cec5e64mr1840642qtx.19.1697543411930; Tue, 17 Oct 2023 04:50:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543411; cv=pass; d=google.com; s=arc-20160816; b=gSccaooXHMXTE/dDe5a1UjpcVUTaLL1OQ0wKO0kI3NaFic5nANNauaxo+CQf9NU85n G8O2fEvUdIgDzb44F9nzFoMCfJ9ifQe9cNJQrs7oRoGSnbZi/oKpD8PSMS3VkEqlFBpp lh6ghVeQJutW1Jpd+FIOW+8AuqGgPE7fr61G1Qzz5cRwb/nsgLXQUOXvUtyhje8KxZwo 7VbFf4VtxK8km1LbG9OdgSsJve5jMVECKeoYTmPh0OcHfX3Ixdho30ag1najS4HNcH/y vC5+YYv5v1EOrc8bw4JITT86bEgoFcsyy0T1xeuAOv3c8tD7ueJTbInvzzzWX09ZPy32 rZaw== 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=I7u3r5aPxOApyfVQgjLcLQECiaN1qIF1VQi6GNB/wx8=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=0hWxphVShvCh4eUbbHgju/8+za7SYzd326v3+80MsX9Pn4lkYfXkfMawx3OtG6tvFL T0kjEM+iys7OgyEH/E8YRy386K1udDP68JJ71otUqeWIg7ZMDRXXejtIl2svd3VnRkLA osuaSqk8a/RjxXpnMZ0U5CdkwXenXDeTb4axYYKGtnAJgRKA2OopDESQFk5nGU8SIGbz NMfQCPrvvRtePNIM7ezPNMf1xJ+QWuhpYo7I4k1A+qwdS3zY2/OAkLo6lIaKgQvoYato f8rEgfRBGn61tpuDSOWidjd216+YizGSDis8vRJnBXzg7pAeCwai1eTzxPWv6KcMQIlk AHwQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fojZ6kya; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i9-20020ac85e49000000b0041b505bcef5si979573qtx.415.2023.10.17.04.50.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fojZ6kya; 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 1B7B3385773F for ; Tue, 17 Oct 2023 11:48:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B7B3385773F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543320; bh=I7u3r5aPxOApyfVQgjLcLQECiaN1qIF1VQi6GNB/wx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=fojZ6kyaGWUrRMfmnT1xDh25KlOgd251nNaelSfDdN4dmpjv9gpMTdlM5vOGzixnF J61N4ML8C7YuYSzW51vyokekK20zhE7ocL9I4vLKDF/ytf0GSu5qEA9kNIDc+79x3w qi3KIAmwnE+mjJOKfvztQWkLwYB+OueqS74GJJsg= 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 CEF663856DC7; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEF663856DC7 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 CEF663856DC7 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=1697542565; cv=none; b=Wj/VwhNL34dihKB2A3Qd4YaLQYV214rXpQY3yrnF3AnEeZbUhkPeQeyJUVwxcyUuUKqirit9AFZbrdV/8JcQ/33bsDnW7fNNQtf1Tq+GBoCWFhW59ju73U+dyI/zA9dTPlRTaagmvEqrT9fP4+0HlvUXGGC5xffRXtrYuEkWN7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542565; c=relaxed/simple; bh=ESB1diD1iUYt/kFPVJWJ9UAIk7o3wFY2Qiy0kMZFkcU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=iiBwwsq3x0AJfvrR4qIQugdYiMd6oGrG/yL2S0sV2X4Qm2+1tVA1rK1JgRu0syylLOy0udyeAU0m9yZSn2vUR2lSjh93r/RY8o23bxfv0LLnLg+P2IHtHxfPfCgECpL5UkHTv5S7oJq6BtsUnVIVApHGYA98QeP1AxkCtXjNknQ= 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 39HBZjOu020435; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40afv9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlEZ004257 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMc001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 25/30] c++: Implement __is_object built-in trait Date: Tue, 17 Oct 2023 04:27:56 -0700 Message-ID: <20231017113242.664523-26-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: 2h_iGzjdnJczlLHH4ZgE-VWOqrnEwc1b X-Proofpoint-ORIG-GUID: 2h_iGzjdnJczlLHH4ZgE-VWOqrnEwc1b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=796 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003280955820114 X-GMAIL-MSGID: 1780003280955820114 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 c394657d6b9..444dbaacd78 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3781,6 +3781,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_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 fa79bc0c68c..191a86307fc 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -79,6 +79,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 8118d3104c7..e3f71ff5902 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12205,6 +12205,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); @@ -12412,6 +12417,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 4d3947572a4..163be1d710b 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_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 Tue Oct 17 11:27: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: 154120 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073278vqb; Tue, 17 Oct 2023 04:47:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuAdEqWp5FaFU58ECQGBzUh/3ER6eUhc4u1EZ8X0KFNtwaWH3jBQLjtzgWXnoicScS9Cdm X-Received: by 2002:a25:d68d:0:b0:d9b:e8bf:4703 with SMTP id n135-20020a25d68d000000b00d9be8bf4703mr1773861ybg.10.1697543232791; Tue, 17 Oct 2023 04:47:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543232; cv=pass; d=google.com; s=arc-20160816; b=XrKUtcMO+9eAIbfAqQjcUYGoOE1UGdlAXG9OA8CHeTQIkNMgs9yaKNv0dajJKZFWbT QPFNh7AhgLtV/f45t3S02/njW6twtCyuiaNo8oC8xf1sVLrYkXeYo3v9ipY2hOfvo07Y voqqIBoHq3DJNwdYT+Z6b7f7EDIWob3AMhwM9ixZLTKGLJD7LTTaq2FpZM39flGiwPze Q3iDfTcwQvwzT2GN22EZXBtQfb2uYH+OK8vQDH8uDSN8XC+JTSrkNiZFbbVs+QH8iUT5 cuYE2KxfZ/QwM2TqXRgWqdnQw0Ur83jg4X22fkybi3h97kf9sSlhlB/PRxs8LKtSiEdR EWXA== 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=GwJIozGDWJxGiKlP2wlIRXfHovWX2PngOvElR6IxpnA=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=vB51n9NurJYtbF9glv5lPhXsLd4H1qyp9ILfNCGX+mhpD1tDCCJxCMgIW8wJSHQbyL kqkQ1BY+XYPp42h9okb/fav2didruWJ7s8kUOSnWUQ8Dyh6BEz54kF7WXlsJIwGpy+8i c+z9Jg/6lV7b2/EVYPJzRpHh4HhMhNdd3aaxcYjrAqRZE5/MBr/gGpddIsSaSSht2PKm CTO2xfKMkvdm+I33he3x6oVYA47xTCq+QJvfEbsymtEhdzAhRaZvOlJeUig7C5+VGn2R dCWg0bUe2dh/yhxaKjSKt4TZrztW4XaaNRSfaKU6yBratykvw/fLV1RF9WfZuYHYaUqX iwOw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="af/GzaUG"; 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 15-20020a0562140d6f00b0066cefcfe53dsi845384qvs.524.2023.10.17.04.47.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:47:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="af/GzaUG"; 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 8DA8D386D61A for ; Tue, 17 Oct 2023 11:45:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DA8D386D61A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543153; bh=GwJIozGDWJxGiKlP2wlIRXfHovWX2PngOvElR6IxpnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=af/GzaUGc7jCAY1GfucAo/2NmfpvHKD4DJq5AHseCzr+MIWbTIYXkkRxrzYMrjUjg pURXCd5xdNCMCH2yp/DWvjopDpQZoYTCtxF1/xOD8dIRTUcWZ9H9mChOGoqJsivBOf IRYXXqa0L6hyFttmGOrHMRSzlFZYs1kO/1y5+bRk= 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 B5D94385C017; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5D94385C017 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 B5D94385C017 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=1697542570; cv=none; b=tgdGAJzP52/zLUdljXl1Fgyaaibe3+YxxxMEZpvCbnQbcqbrM1NrGwsR/86T+K+i7K5mnX932TrnKFFw/hi2Dd6pDJuYH4Y+8vAGfE4BOlRd8RUQtRkwlJ1UXOPZLOgzCXCXNgz4UhutG45IXvgLgknR+iXkbb2OcyLwkxdMnUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542570; c=relaxed/simple; bh=ppZ1J2R3vTzF4ae7XE/TG2BmfxX7b8+cpy1Nkg343tU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZLK39IE1I+ywiB0xV4xB0RgH/XK3d8jL8UTeRyKx2U00/1RDOKd7S+ib7PbCOSk9ce1vg2wQH5JB2UXzUC8lsSCCHCr05fqIuvEl8YWB1K4wiybIRJVTdoIxMucyPucWyizwrggRq9Bd+hiE+OKWsmB76mZhRHLRNbDcvyvdrVo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HBKShS020655; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tscpruvef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:03 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlom017740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMd001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 26/30] libstdc++: Optimize std::is_object compilation performance Date: Tue, 17 Oct 2023 04:27:57 -0700 Message-ID: <20231017113242.664523-27-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: _FkgMXTdbCKuYCVL8BJ9svveUNR-hfrY X-Proofpoint-GUID: _FkgMXTdbCKuYCVL8BJ9svveUNR-hfrY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 mlxlogscore=715 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003092679074239 X-GMAIL-MSGID: 1780003092679074239 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 bd57488824b..a12a35c209b 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; @@ -3305,8 +3312,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 Tue Oct 17 11:27: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: 154125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4073952vqb; Tue, 17 Oct 2023 04:48:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0fQQtDDTLToQ6qRZhoaCorlO/R8c7zHq83QzC2IgDwIi4rKQ19ZjWZsUCI1S8Yuo72pVv X-Received: by 2002:a05:620a:2911:b0:773:e380:b364 with SMTP id m17-20020a05620a291100b00773e380b364mr2366268qkp.69.1697543316614; Tue, 17 Oct 2023 04:48:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543316; cv=pass; d=google.com; s=arc-20160816; b=Q3KsTFGxKT+Owm+0BhhNRA9yKsijtsQZ1Yqp29RMX+ldukioZMUUXogThLfvfOzNOH tSPWkEKD9/anwusmoAr/+0NwyZpFaUh3me6ZcoBvTfyFOF+7qohWw4Ix+pVDSg6FuCOH Ip1SIadMii34CO0ZRtCu7U9hUijCFTnnR8aZmwnTpPiPKT8PCrwLsmU4Ne/GTB9HpgsW bpnp06Qp4ETnLk4Glwa9ZUZnQ14asaw0yrKM3TaBcaLZSm8N33FlQwkCjwE4ImjfmCjl cfJBuFFWBqDSqSlvTYvWjMka8kcnSNO9qkKxm93kaLJjFpB4oG/MY4U5QzsTv3AhN/hm 5f7w== 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=5c03BG+ACUU26yDpXw013AaVrGf0ODAIozIbkRY2mw0=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=uosh8hrGyaI7nLxhDYS6eK+1XFRNrBg/cDu/GZ9djZU7o9ZEFcOGZzgyWQLZL9gkIl lky+nhs2DmIQAXbFTuKe+qC31cknW17I07BNuSi9DhMfEZ4XGUnkPEG4RVkd1Vvh18wv eebKT5aW2lcRUI2AFKXQVu216SvdGBf+Gc/YquS2ezBl6McqzjZpHGpxa1CVgB4obsMm Uxpk5kct/tm2wRW+DLub9VQexMeuqvDQjuKbxjzXdBAdROLqEXe4PkVr1QF01t/Sj0XJ b21PT3DU/fNIYS8AZn/XWVhz5W9zOfle6dXJMbd+G+LZo4uG9+eLgJ2m0Nam/PyuEaRB he7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uAYke12l; 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 ts12-20020a05620a3d8c00b0076f03e58b62si883381qkn.147.2023.10.17.04.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uAYke12l; 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 C9BC5394D8F8 for ; Tue, 17 Oct 2023 11:47:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9BC5394D8F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543231; bh=5c03BG+ACUU26yDpXw013AaVrGf0ODAIozIbkRY2mw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uAYke12lY1Z2ipZcPfjmG3AJ6oA92oi4ebCbQDEF+yN6nTRTqLXjVVo50+B4k4FQl oFEQ6ej6f84ifovmjAYmrk6Ph+WzNRGzULdx441oOsYPP92EP0Pg9P9xUGABGrqjZf 4WB3ilkvaWvsBJ7kgwBmeM94elRx5D+3Aov+ZVDg= 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 CB79C3857352; Tue, 17 Oct 2023 11:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB79C3857352 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 CB79C3857352 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=1697542564; cv=none; b=sq7p5MNCS5/BiUzzFkpHjrbKiCvz2Q9x5rLTQDKJaBlhmzY2nv/Dn4+nJXwTQfcbzL1/XXDqxucAACqibdWM1O6rtxDo3CUKC0oXpdk1/XcfxV91YJaThqGcYeQ+ktof/yJx4CdSgzFC+/9YGrfSOpTEohKxcM1GY6nruL9r7aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542564; c=relaxed/simple; bh=C0qcTRTV/TeuNZg0DDmxzdyb6y2iW6hZf2AYLVPf/ps=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ScLV0oGg6SWjMa+6MZP8BtwDF2AQ4XSsShUkH6ISh9Kge8g60BMY0p73t/TYBpB1znGqccRepftbNYlMV17KlSnHzvprTeoiLFOvf4amHQw4+J2wKtvmWh420jqCH3ZIUlyYIicwPnCQoVIe+qGK3HNSPcDbnIGPZ3eEdXtCEMs= 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 39HBZ3c1019493; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsausw4ht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZljb006894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMe001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 27/30] c++: Implement __remove_pointer built-in trait Date: Tue, 17 Oct 2023 04:27:58 -0700 Message-ID: <20231017113242.664523-28-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: yDj5FasffzcgSUhGHJaYUP0L-otoUTGA X-Proofpoint-ORIG-GUID: yDj5FasffzcgSUhGHJaYUP0L-otoUTGA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=620 priorityscore=1501 clxscore=1034 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776997148879891783 X-GMAIL-MSGID: 1780003180735024652 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 191a86307fc..1f405f61861 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -98,6 +98,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 e3f71ff5902..45584e9045f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12494,6 +12494,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 163be1d710b..719902d3f1a 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -176,6 +176,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 Tue Oct 17 11:27: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: 154131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074562vqb; Tue, 17 Oct 2023 04:50:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8f7ze79WDOF2uhQmFO5URq0tuu4/1C9AFHqFaTVaZec/3jzoqW2YOhYw+CSskg7JKgpok X-Received: by 2002:a05:6214:e6d:b0:656:2696:9947 with SMTP id jz13-20020a0562140e6d00b0065626969947mr2547750qvb.18.1697543405612; Tue, 17 Oct 2023 04:50:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543405; cv=pass; d=google.com; s=arc-20160816; b=x1HGJxqf4VB4P5Btoa/bRa7VPS0WgQuwSWgG29+z8In32ZE4AyNESpWUymhZSxgDYo UWO5NuQp6pTJQRYJaLbf6m/NjiDBoS3R1bJ/BdZw9sphMGBfpvZnxUrf3/M8db9Z5Qmr Vt/ldShtLE1narnI3vDo6WKTfQ++Vbynw7Bfiv2aBR2IR9CB6R7HMnHEy2uYP7nsrDXE 1QnrsKx9i4wrxop3u1HbBO/5ilsUcl7acZG84aBwWKNkrXLsWvSHLz1jrdZDHJjgmPdV 48FXuNvLluw+05BKTqkIDpJ0fW+4/dlqT9Dz/rAnwyBfSNlKTFCLYPsNfYMZeRIo4w/4 Co9A== 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=6hXFlPbvzC+1W4D7nwkYmF0u+9usn1LBxG/spQD4Org=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=yIk7AlVKK0eAAHB73wgufO5lVQotWgoGMDztpl8BUz4pjN0arjaHUuN2t4rAptVLer q4nF1Fu7bFDZ+m8RozNBKfhE1YxWpll7uRi30b8YejJxu5yq1/U/h/TLr4enA6cUn45S yIdv44X1BftWJJV/ko9RObI7o2o9qfNRB/RSRahNm5IaVq1mRE0xRJ+FP6KS5WMccYxI gWlJq4WOHk/NACW4dILVMcZ0UvjA41V82Z9PDoZ2KFVuYYFd+1SmhY0G3gT75AskdrF5 E7cbCgu0LkBvrJraILc1XGWuv/kb0+IYi1wTG6EVkolFBaO4LeMEcNOwFc6xZjmfvSg+ MmFg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cwOmYqbo; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n10-20020ae9c30a000000b0077567358e2esi873298qkg.561.2023.10.17.04.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cwOmYqbo; 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 3733D3952511 for ; Tue, 17 Oct 2023 11:48:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3733D3952511 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543314; bh=6hXFlPbvzC+1W4D7nwkYmF0u+9usn1LBxG/spQD4Org=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=cwOmYqbotcf6uRqXoIKWq2OWvDqbu7OsJ3duIcWmKrPXmqWUSRdyavMbZSqX+Oiy7 LDFTghxwX5lTFPVb9ymfwhzxsC/8h6RnLl5gHPFnO2C5JAhI9g1mH7GNQxqwb3YZtg qG/qnNnrCMVd0eobGtTDYSUWHIsQua1mA6/X/s7k= 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 246DF385B800; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 246DF385B800 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 246DF385B800 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=1697542568; cv=none; b=OQTVbEgj40VkLRuId2Mo14rSkDVBFDR3yGTmTf4YpAIHoBFBK1h13txvlHcKHRiL+ulf9eaLZTkit2r6q+wmp/iNl0gcx7fumvatkRegok/1PkxUAPWgxP4VzcreJ7iwMBV9EdPcOuHZ8VSdutbQNv+0tU5lzm+9k5O7Oxs4x0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542568; c=relaxed/simple; bh=Oz6GB4/nklZZg/Ua12A1aUDpcPcwACJS/UiICCBC9a8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TRPK5wWY7dRMYJGG/jh2USexAu4H40TaAvfzl+BeCgp8JLSwrYXazPtjVGjgIkEAk/t8GyGRfE5fC7WOaqN0AXOhAInGEOypVCQQektu2mojgmv35P45H2x+AcUhn0SKUStecK5SwXPVTXELFq/wDq9JWDhOT+XwW0xbOqHp4e0= 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 39HBK6AD015172; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsgyr1npy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:01 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlho006895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMf001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 28/30] libstdc++: Optimize std::remove_pointer compilation performance Date: Tue, 17 Oct 2023 04:27:59 -0700 Message-ID: <20231017113242.664523-29-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: nZVrfcqfvHssMxGI_gH3agxuoQj5DdfH X-Proofpoint-GUID: nZVrfcqfvHssMxGI_gH3agxuoQj5DdfH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 adultscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1034 mlxlogscore=593 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780003274130707210 X-GMAIL-MSGID: 1780003274130707210 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 a12a35c209b..50210297121 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2103,6 +2103,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; }; @@ -2111,11 +2117,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __remove_pointer_helper<_Tp, _Up*> { using type = _Up; }; - /// remove_pointer template struct remove_pointer : public __remove_pointer_helper<_Tp, __remove_cv_t<_Tp>> { }; +#endif template struct __add_pointer_helper From patchwork Tue Oct 17 11:28: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: 154115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4072702vqb; Tue, 17 Oct 2023 04:46:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHgcVpJTlUZNlGlOrHD7jDtbs4i8yMK8tJpgpw9sUbJj9ZjyqQ7ti0SLGvOk/Pdv0uNdlS X-Received: by 2002:ad4:5949:0:b0:65b:22cf:101e with SMTP id eo9-20020ad45949000000b0065b22cf101emr1914138qvb.54.1697543163113; Tue, 17 Oct 2023 04:46:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543163; cv=pass; d=google.com; s=arc-20160816; b=a45GfLgtAJOQiN6tyJ78NVYndgCpWA05imZszMwn1QfC61ZXrKu1Yg7gmSPi26gQXG xEgScyH1DQZrJq2s5TLTWNyiSQ6YzQ5okcIxKJsNXEtAJS5bin3As6e1fRQxcacx7yS7 IMAvsnoVIV3OZc2EY9rzoO0ilqyIWMdurLaL3QJVKokumrw86ccc7Pj6sxdhmFAuXybx csWlZ+jlqHPq0DfDuNbyfqbmZNHZ04xOw4kU6SMpIkq9FCCSIYq+gBdAqoaOmYcIQ7Tr WrPIoZZbzYNfK3FQ0zGmrLoDbkZ93x29EwxzBfvoInx837b8sq8BHPn/IzEVr64RFXSV DHPQ== 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=Smh/Y+kB+0wpjHL2qeQS+IxoTryiXigFIt43HCPbyWo=; fh=kSSy/oyUXqQD15FLeKdymIgDBFPFITPA1Gj52CNOxRQ=; b=Qe2jnXCFyMQCLzo3MX27t5fPRxxIubo1jhcEGC6iHimzgOeMH/GqA7DwJy2QsOno+k Mxx9Y+H2yzfs1RAEcvirsNPShkMM+ck17Fw+98YbO1EnKFCzH3rdi++B1yAlIenoJgBY XAi/yMiBs432gbPp6JyX2rh/hkZZAPZlRogJB99jOYGlM5ZITTzdpiC6c0+TedecAl92 chnQbCJCG3/IqgtJDKBMrg8bIYwxu8ZmqHgf66Gz3Ls8qE/04fIqpXmCbDkNnPu3d/Fo KSuj9uOkYByPaYZljRwowynBj+vdIKucZVPkWGtbmL1jeBXxwQOnbMLkRr0rfP4KC+w3 26wA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YY6SdTl4; 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 l17-20020a0cc211000000b0065af5e98ed5si838238qvh.290.2023.10.17.04.46.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:46:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YY6SdTl4; 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 C82A73882640 for ; Tue, 17 Oct 2023 11:44:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C82A73882640 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697543083; bh=Smh/Y+kB+0wpjHL2qeQS+IxoTryiXigFIt43HCPbyWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YY6SdTl4YuVXpW9GXbtxpkpmV8U6CrRhn9Js/wjDBJhuDFFHsLKBkKqVDJ3p8TsEj RD3/mAJDOeJkeSm1VAa9vSAfukk0mHm5Rh1GjPK1MepUXJ7KFAqOGK+jqbaICSZY39 7KSvwpQ0yWs6RpNDrhxk6ECbwCb1ZYzh/6eq3Tqs= 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 5C6B83857030; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C6B83857030 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 5C6B83857030 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=1697542568; cv=none; b=SCL1pt9jW+N0cYInsNkwgoV/zG3VVQC6WxM/dlP99F5bMLRo4+4a8/ssheMRMyaVQ1QkINRMBCbdKCKFh6bGqCj3NwL/mATpn8YLIzwJIsVx7/V7PWFuBwldD2Ubmt/irS8+JVIqSjmPctWmImU3+35E17vn66RgKNNPI+Nxa6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542568; c=relaxed/simple; bh=nUzdWNlhWch0UgIpHjoLMy3laHHmMznmZ+d5mPW7o04=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KuOKPu6qEkD1HQkCnIjKSqJLCkCfkVMgCqh3Fo09SITis7a/AOtGllB+9Vx2ijg+6rHWbXeUozOmXzMVQ8JuDPm5NLv0xLSMZMfBAfTxAlTYCtYYSLEQqpyFDQkedsFs02GH2lNmwSva2aALMfEmleIce+XInS64Gu+CL7zPS38= 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 39HBa3XN020928; Tue, 17 Oct 2023 11:36:03 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsf40afvf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlu0012240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:47 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMg001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v21 29/30] c++: Implement __is_pointer built-in trait Date: Tue, 17 Oct 2023 04:28:00 -0700 Message-ID: <20231017113242.664523-30-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: maPWxShO7FrSptPrL41_FFxcS8wA_ecu X-Proofpoint-ORIG-GUID: maPWxShO7FrSptPrL41_FFxcS8wA_ecu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=728 malwarescore=0 bulkscore=0 clxscore=1034 adultscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779677497968726301 X-GMAIL-MSGID: 1780003019876560188 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 444dbaacd78..9fce36e12d1 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3791,6 +3791,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_POD: inform (loc, " %qT is not a POD type", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_POLYMORPHIC: inform (loc, " %qT is not a polymorphic type", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 1f405f61861..05514a51c21 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ 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_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 45584e9045f..7cccbae5287 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12216,6 +12216,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_POD: return pod_type_p (type1); + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_POLYMORPHIC: return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1); @@ -12418,6 +12421,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_MEMBER_OBJECT_POINTER: case CPTK_IS_MEMBER_POINTER: case CPTK_IS_OBJECT: + case CPTK_IS_POINTER: case CPTK_IS_REFERENCE: case CPTK_IS_SAME: case CPTK_IS_SCOPED_ENUM: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index 719902d3f1a..b1430e9bd8b 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -125,6 +125,9 @@ #if !__has_builtin (__is_pod) # error "__has_builtin (__is_pod) failed" #endif +#if !__has_builtin (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif #if !__has_builtin (__is_polymorphic) # error "__has_builtin (__is_polymorphic) failed" #endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); From patchwork Tue Oct 17 11:28: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: 154099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4070507vqb; Tue, 17 Oct 2023 04:40:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAwEAm18jqQOd71i9KvPGhl3DPWVE3WnrOrcTqvCykbBCEkXyhwv2Fxy55eo5jnAthnbuO X-Received: by 2002:ae9:e519:0:b0:76e:f496:1928 with SMTP id w25-20020ae9e519000000b0076ef4961928mr1615554qkf.72.1697542848832; Tue, 17 Oct 2023 04:40:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697542848; cv=pass; d=google.com; s=arc-20160816; b=N+z3tyNy3vVrSGfc1hY8HocT/gINre2oTFCsr6B6vJKNMwpRxOwkpm1/vB06YPB9XJ PCYuakuFosN0KcfzKt6Nk1eTdMDRYjiZKuhcKGw4HRQeagl5HodJN1i8oxGNHuZkzcy4 6BcPRz19JmVp70yiasUEbjcgxpLVpsHauFPtN5E7J3fhBNi0Sy0o+WJ1egSVTd8c/ROA kBZjzQD/QIYaJDy0uZEuUDxBpvJBGfiJdkAgBjzIXWeXoC7fYkkqiiyrTf4mQkdDnS+n 3ZyItW8E7HJSAT1pd/kngvqDSTHc3321ymVB/0sJicqv3viKi7qy4uCQnAqkTe7pQhnI GDvg== 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=9Dn0VEr7nsHP6cfPUJmE0z3cJehdHxR4FVAFVcStTPE=; fh=2MU6VW487KDeEvI5/nTaFmO/pzM6rabW6FcP4yf4iBE=; b=0StfexwPBjmx2Y9PRWxPysnGxeW0ZaG3YwhNZaAfsiXDsEggBL/Tymx94MkfqJy55z lYErSjGgljlpouArv7v0nHcj99BgjYwIzMpoM9/9frCdWJZilEB1Xh2Oy1ydqTnP/Ygs /RECwLKyzGEcW6rjd1oQbtwFD7RJEOF0/oPhA/d/5hmg7jwymW7LGe3FfvkG1ee+TrNE jWl2tuRG7nuxCWBaA+jHKZ8KR5REl9sJShCC1HqJFtGCbvpN21lBYIGA9n0k4Z0tK/z3 9qJtHl6GSxSsoKbB1wLHau4ljK9WmiSRq54sV0EEdMuOIZpBm9MWjppBhykJhuivd9ay EV7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=N937EHkz; 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 w2-20020a05620a148200b00773a83f4736si859249qkj.585.2023.10.17.04.40.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=N937EHkz; 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 482D2386188E for ; Tue, 17 Oct 2023 11:40:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 482D2386188E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697542800; bh=9Dn0VEr7nsHP6cfPUJmE0z3cJehdHxR4FVAFVcStTPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=N937EHkzUkWnV9hnUws9YCerY7t8RFK4iSOy8IjN0OHv0keXndJUvdVOlS9IIrtNo /An9aqb9A5tqNzpyn3L5IT5RVs4iE0eACuPc+4gA3+5rVFL9+nGBEime9XhGjotNng EsCgKfKIBl/iBMcUfR2rSgDktx+Z7fuOO9igcOhs= 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 18ED3385B537; Tue, 17 Oct 2023 11:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18ED3385B537 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 18ED3385B537 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=1697542567; cv=none; b=X0ZyPQLw5pioJXOXvETEm4X4FB8PT6x4mpv8U5WPvgDPEWYQmgp6x45i/sM2nvdmaqsi9juvZm23WkCmmLlXF/cEgPvoGvjcLDCWjZN/fW7r/rBs3wDo6r7fOQ//g7bqDCsJKUrvKiWWvx85upt23qNS76hKuEnDLkRwh+Ywzks= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542567; c=relaxed/simple; bh=CwlGtBzZLdvGgMqqHMFspW66aANcOfbkJYM5resMAc4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=STAqpAz1NMyjaVlq4AeZ7h80Zg50Ke4seyCn//ZbF9KNkVy6dCJ0SQcYLaj70Yz6zyhvoEMkb4lmd/jFiRAK6BTHpgusfhONHcoHHoup42FtRvyS9r/Nxf+FuVwDCbkM5IcxQBC0arjaBOO9xJx8cVExylA0hoIOhDUmdyy1LEc= 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 39HBNd6H016434; Tue, 17 Oct 2023 11:36:02 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3tsb6cmx7u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 11:36:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.234.157]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 39HBZlIW004609 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Oct 2023 04:35:48 -0700 X-Auth-Received: from kmatsui-ThinkPad-X1-Carbon-Gen-9.dhcp4.washington.edu ([10.19.18.191]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 39HBWiMh001840 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 04:35:47 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu From: Ken Matsui To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui , Jonathan Wakely Subject: [PATCH v21 30/30] libstdc++: Optimize std::is_pointer compilation performance Date: Tue, 17 Oct 2023 04:28:01 -0700 Message-ID: <20231017113242.664523-31-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017113242.664523-1-kmatsui@gcc.gnu.org> References: <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231017113242.664523-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: SJObuyzujV1guMWBM51WYIcHHiPVqI5P X-Proofpoint-GUID: SJObuyzujV1guMWBM51WYIcHHiPVqI5P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-16_13,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1034 spamscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=294 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170097 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780002690195991879 X-GMAIL-MSGID: 1780002690195991879 This patch optimizes the compilation performance of std::is_pointer by dispatching to the new __is_pointer built-in trait. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Co-authored-by: Jonathan Wakely Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 44 +++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..246f2cc0b17 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct __is_pointer : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_pointer { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 50210297121..acd117cfa73 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -542,19 +542,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif - template - struct __is_pointer_helper + /// is_pointer +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3252,8 +3266,22 @@ template inline constexpr bool is_array_v<_Tp[_Num]> = true; #endif +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; +template + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template