From patchwork Thu Apr 20 13:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 68069 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5860B385735C for ; Thu, 20 Apr 2023 13:57:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5860B385735C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681999032; bh=eVNaaiafxyxjYyeA/opWva9G1T5hluTMaXTmgxJ2RWc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=BhJYAHc/9mUXyPfp1WFqAU2eoVX0H5N+OXCOJncsbvLiNwLFt+Lo61DDWmKkPLo/Y iPIwAV3AjVQ8IqSw4QANgAQG+xtLe2mArlnhTnY79wSLB6a3AGTmIEpGqPapxtcMAj 1yPe7yuHkuFqgDLgm4czFXu5HA74Ju/aN8sQSq6s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 93DF33858D37 for ; Thu, 20 Apr 2023 13:56:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93DF33858D37 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-fJ-ixpMaPsCsXUDCNrrRGg-1; Thu, 20 Apr 2023 09:56:39 -0400 X-MC-Unique: fJ-ixpMaPsCsXUDCNrrRGg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74df84a3d50so49693185a.2 for ; Thu, 20 Apr 2023 06:56:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681998998; x=1684590998; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eVNaaiafxyxjYyeA/opWva9G1T5hluTMaXTmgxJ2RWc=; b=AYHpftIjhSIBIXMPOJ/yfh6XPM5No/u9TQdbp9A0PmZM6IQk2458yuu2nYr/Ge9OLa g4grl4cCRXI+CbnGEpOOFd7YgyyFPh6jlgCANzCn/+muW1g4wZ4KoIWfNsUNUyMfggZ+ u4VYRJD6mBB06e6XkK46SMjNKhC4VDLmf8QR6sv4L3mz5BUnpCwHHhRHCnMXHd9q5Pt+ T/zs41KgjLM8g2mJ79vetbiBhWJd2mA+5s751R7UHOH1IS14hJ0gHXoJ/bGZrLViT5Am lrRU3UnGAwfCqTV90ez8QjE4GMxu4Kr0fzrzrh2p/NiVdxeiLA2pe0fHAxybY67GUFmR zWZQ== X-Gm-Message-State: AAQBX9c8/7QqOeEu3GSJB5+RutVpyZhv70Kmoyv10GVMRoXQtzRgJxJy 4o3XounZLy3USQK32BhFecj/D98ilWmMekj/H755WwVZay5z8ufZn83YfB5NIRWjuWD10A6RPig OaMjXTRNuIPdfPhyaHEbPKfRuw32iPk1fkCvH1L3o55Gp/52wEYc3gKgRNe7B3V5OBNWiulkr92 8= X-Received: by 2002:ac8:5cd1:0:b0:3e3:7ce1:e73f with SMTP id s17-20020ac85cd1000000b003e37ce1e73fmr2488226qta.53.1681998998037; Thu, 20 Apr 2023 06:56:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bX4VQzbGY2Zj8VzaKtzL4FBDz5bCHYFnPz1g0N5emLuj8qufsElQ7HNCFIklAePas6wzMdUg== X-Received: by 2002:ac8:5cd1:0:b0:3e3:7ce1:e73f with SMTP id s17-20020ac85cd1000000b003e37ce1e73fmr2488178qta.53.1681998997660; Thu, 20 Apr 2023 06:56:37 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id y8-20020a05622a004800b003e64d076256sm506471qtw.51.2023.04.20.06.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 06:56:37 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: make strip_typedefs generalize strip_typedefs_expr Date: Thu, 20 Apr 2023 09:56:32 -0400 Message-ID: <20230420135633.2447631-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0.352.g667fcf4e15 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" If we have a TREE_VEC of types that we want to strip of typedefs, we unintuitively need to call strip_typedefs_expr instead of strip_typedefs since only strip_typedefs_expr handles TREE_VEC, and it also dispatches to strip_typedefs when given a type. But this seems backwards: arguably strip_typedefs_expr should be the more specialized function, which strip_typedefs dispatches to (and thus generalizes). This patch makes strip_typedefs generalize strip_typedefs_expr, which allows for some simplifications. gcc/cp/ChangeLog: * tree.cc (strip_typedefs): Move TREE_LIST handling to strip_typedefs_expr. Dispatch to strip_typedefs_expr for a non-type 't'. : Remove manual dispatching to strip_typedefs_expr. : Likewise. (strip_typedefs_expr): Replaces calls to strip_typedefs_expr with strip_typedefs throughout. Don't dispatch to strip_typedefs for a type 't'. : Replace this with the better version from strip_typedefs. --- gcc/cp/tree.cc | 83 +++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 59 deletions(-) diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 2c22fac17ee..f0fb78fe69d 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -1562,7 +1562,8 @@ apply_identity_attributes (tree result, tree attribs, bool *remove_attributes) /* Builds a qualified variant of T that is either not a typedef variant (the default behavior) or not a typedef variant of a user-facing type - (if FLAGS contains STF_USER_FACING). + (if FLAGS contains STF_USER_FACING). If T is not a type, then this + just calls strip_typedefs_expr. E.g. consider the following declarations: typedef const int ConstInt; @@ -1596,25 +1597,8 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */, if (!t || t == error_mark_node) return t; - if (TREE_CODE (t) == TREE_LIST) - { - bool changed = false; - releasing_vec vec; - tree r = t; - for (; t; t = TREE_CHAIN (t)) - { - gcc_assert (!TREE_PURPOSE (t)); - tree elt = strip_typedefs (TREE_VALUE (t), remove_attributes, flags); - if (elt != TREE_VALUE (t)) - changed = true; - vec_safe_push (vec, elt); - } - if (changed) - r = build_tree_list_vec (vec); - return r; - } - - gcc_assert (TYPE_P (t)); + if (!TYPE_P (t)) + return strip_typedefs_expr (t, remove_attributes, flags); if (t == TYPE_CANONICAL (t)) return t; @@ -1747,12 +1731,7 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */, for (int i = 0; i < TREE_VEC_LENGTH (args); ++i) { tree arg = TREE_VEC_ELT (args, i); - tree strip_arg; - if (TYPE_P (arg)) - strip_arg = strip_typedefs (arg, remove_attributes, flags); - else - strip_arg = strip_typedefs_expr (arg, remove_attributes, - flags); + tree strip_arg = strip_typedefs (arg, remove_attributes, flags); TREE_VEC_ELT (new_args, i) = strip_arg; if (strip_arg != arg) changed = true; @@ -1792,11 +1771,8 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */, break; case TRAIT_TYPE: { - tree type1 = TRAIT_TYPE_TYPE1 (t); - if (TYPE_P (type1)) - type1 = strip_typedefs (type1, remove_attributes, flags); - else - type1 = strip_typedefs_expr (type1, remove_attributes, flags); + tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t), + remove_attributes, flags); tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t), remove_attributes, flags); if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t)) @@ -1883,7 +1859,8 @@ strip_typedefs (tree t, bool *remove_attributes /* = NULL */, return cp_build_qualified_type (result, cp_type_quals (t)); } -/* Like strip_typedefs above, but works on expressions, so that in +/* Like strip_typedefs above, but works on expressions (and other non-types + such as TREE_VEC), so that in template struct A { @@ -1908,11 +1885,6 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) if (DECL_P (t) || CONSTANT_CLASS_P (t)) return t; - /* Some expressions have type operands, so let's handle types here rather - than check TYPE_P in multiple places below. */ - if (TYPE_P (t)) - return strip_typedefs (t, remove_attributes, flags); - code = TREE_CODE (t); switch (code) { @@ -1940,26 +1912,19 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) case TREE_LIST: { - releasing_vec vec; bool changed = false; - tree it; - for (it = t; it; it = TREE_CHAIN (it)) + releasing_vec vec; + r = t; + for (; t; t = TREE_CHAIN (t)) { - tree val = strip_typedefs_expr (TREE_VALUE (it), - remove_attributes, flags); - vec_safe_push (vec, val); - if (val != TREE_VALUE (it)) + gcc_assert (!TREE_PURPOSE (t)); + tree elt = strip_typedefs (TREE_VALUE (t), remove_attributes, flags); + if (elt != TREE_VALUE (t)) changed = true; - gcc_assert (TREE_PURPOSE (it) == NULL_TREE); + vec_safe_push (vec, elt); } if (changed) - { - r = NULL_TREE; - FOR_EACH_VEC_ELT_REVERSE (*vec, i, it) - r = tree_cons (NULL_TREE, it, r); - } - else - r = t; + r = build_tree_list_vec (vec); return r; } @@ -1971,8 +1936,8 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) vec_safe_reserve (vec, n); for (i = 0; i < n; ++i) { - tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i), - remove_attributes, flags); + tree op = strip_typedefs (TREE_VEC_ELT (t, i), + remove_attributes, flags); vec->quick_push (op); if (op != TREE_VEC_ELT (t, i)) changed = true; @@ -2000,15 +1965,15 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) for (i = 0; i < n; ++i) { constructor_elt *e = &(*vec)[i]; - tree op = strip_typedefs_expr (e->value, remove_attributes, flags); + tree op = strip_typedefs (e->value, remove_attributes, flags); if (op != e->value) { changed = true; e->value = op; } gcc_checking_assert - (e->index == strip_typedefs_expr (e->index, remove_attributes, - flags)); + (e->index == strip_typedefs (e->index, remove_attributes, + flags)); } if (!changed && type == TREE_TYPE (t)) @@ -2057,8 +2022,8 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) default: for (i = 0; i < n; ++i) - ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i), - remove_attributes, flags); + ops[i] = strip_typedefs (TREE_OPERAND (t, i), + remove_attributes, flags); break; }