From patchwork Tue Sep 29 14:46:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1373486 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=h85vQ6DG; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C12KJ6cbzz9ryj for ; Wed, 30 Sep 2020 00:47:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C1E13955C09; Tue, 29 Sep 2020 14:46:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id F0EF139540D8 for ; Tue, 29 Sep 2020 14:46:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F0EF139540D8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf31.google.com with SMTP id q10so2385012qvs.1 for ; Tue, 29 Sep 2020 07:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=kcHRxCERKlOuZY1IZnW5jAcKJJEKiWDT6684ozPpumY=; b=h85vQ6DGbatpz04JsCMwHiQK8YDiG7Zfg4/IPxAzir5OXXoZdQqnOSzIdW02jnB84M tLbA2Yu5AXgmi75aITaW2tlYsKPlDO3jfVjqPpXlD7pzVEwOnGvW3shNanb7zCmlDS3N VmnQXwQNgjqOjHlvyxNUyWP9pIFDRwq4rA5KX0smqHdVS9c6NX5/CAt5rn1LxObf+YmP gS0I45RZd2ROC2ShGDJbnDsJCG4nb7o6vjjJ8i37Hc9ybRNuOX2Tm4KgxM43XA0+31Os 4RUOP6UAtnxehVkkPLbqBnfMeG1IEQ2sa45apsiLs7IIJoC/nxrhPfIIUIUbWcrEkFaO bL1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=kcHRxCERKlOuZY1IZnW5jAcKJJEKiWDT6684ozPpumY=; b=E+vf8cPFQ7+91Kh1MVQTrCIkEljOBgaYH/PC0q3QKorCgcHLuwAy9WPnabxXQm1iou JG8R/NznlVwLpSohULzhDl4503js4sF+BzsSU8Uz7qLHGd4PYtJfkTjJ0s9jrB7ZSW0d SHyd9Ui+jF+ghKgjjYwtLqVGQ52u0ps14z9NVF/UiKngkJ+/opxwuULcx+0vmuya34UN +Tew7+DrXvfGA/JY0ZA/y5P5qnPXSsndr+QEd+Q5YTl0khYFd+UTClw5M2rqAmH8Qgr+ Vw+PC+2WGpaXZsAbo71MIMT8ZPN2ILBDHfoSd2EBmGRnUKWwcZ/5VdDFKS9o+HSi3d/Z zMgg== X-Gm-Message-State: AOAM533cInJve2hftjsKAAlXb9rqUy8Wn/X1QFoDgNLI1Q3wdcQdn9NT q/FG/hTb8ZChmzJURJPxkxM= X-Google-Smtp-Source: ABdhPJytxOYC//Zwt44+WvHE515eiwpbn5vi/XnnqyyIOA2EJJi9SROHxu4CIEHGy/TlypGy0F9mCg== X-Received: by 2002:a05:6214:292:: with SMTP id l18mr4631337qvv.3.1601390814027; Tue, 29 Sep 2020 07:46:54 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:c814:6aa5:2b54:3fc? ([2620:10d:c091:480::1:6b36]) by smtp.googlemail.com with ESMTPSA id m18sm4908022qkg.77.2020.09.29.07.46.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Sep 2020 07:46:51 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Identifier type value should not update binding Message-ID: Date: Tue, 29 Sep 2020 10:46:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This simplification removes some unneeded behaviour in set_identifier_type_value_with_scope, which was updating the namespace binding. And causing update_binding to have to deal with meeting two implicit typedefs. But the typedef is already there, and there's no other way to have two such typedef's collide (we'll already have dealt with that in lookup_elaborated_type). So, let's kill this crufty code. gcc/cp/ * name-lookup.c (update_binding): We never meet two implicit typedefs. (do_pushdecl): Adjust set_identifier_type_value_with_scope calls. (set_identifier_type_value_with_scope): Do not update binding in the namespace-case. Assert it is already there. pushing to trunk nathan diff --git i/gcc/cp/name-lookup.c w/gcc/cp/name-lookup.c index 184e9c873e7..f195e81280a 100644 --- i/gcc/cp/name-lookup.c +++ w/gcc/cp/name-lookup.c @@ -2365,33 +2365,24 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, if (old == error_mark_node) old = NULL_TREE; - if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl)) + if (DECL_IMPLICIT_TYPEDEF_P (decl)) { - tree other = to_type; - - if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) - other = old; - - /* Pushing an artificial typedef. See if this matches either - the type slot or the old value slot. */ - if (!other) - ; - else if (same_type_p (TREE_TYPE (other), TREE_TYPE (decl))) - /* Two artificial decls to same type. Do nothing. */ - return other; - else - goto conflict; + /* Pushing an artificial decl. We should not find another + artificial decl here already -- lookup_elaborated_type will + have already found it. */ + gcc_checking_assert (!to_type + && !(old && DECL_IMPLICIT_TYPEDEF_P (old))); if (old) { /* Slide decl into the type slot, keep old unaltered */ to_type = decl; to_val = old; - goto done; } + goto done; } - if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) + if (old && DECL_IMPLICIT_TYPEDEF_P (old)) { /* Slide old into the type slot. */ to_type = old; @@ -3122,7 +3113,7 @@ do_pushdecl (tree decl, bool hiding) if (TREE_CODE (decl) == NAMESPACE_DECL) /* A local namespace alias. */ - set_identifier_type_value (name, NULL_TREE); + set_identifier_type_value_with_scope (name, NULL_TREE, level); if (!binding) binding = create_local_binding (level, name); @@ -3150,10 +3141,7 @@ do_pushdecl (tree decl, bool hiding) if (TYPE_NAME (type) != decl) set_underlying_type (decl); - if (!ns) - set_identifier_type_value_with_scope (name, decl, level); - else - SET_IDENTIFIER_TYPE_VALUE (name, global_type_node); + set_identifier_type_value_with_scope (name, decl, level); } /* If this is a locally defined typedef in a function that @@ -3768,8 +3756,9 @@ identifier_type_value (tree id) } /* Push a definition of struct, union or enum tag named ID. into - binding_level B. DECL is a TYPE_DECL for the type. We assume that - the tag ID is not already defined. */ + binding_level B. DECL is a TYPE_DECL for the type. DECL has + already been pushed into its binding level. This is bookkeeping to + find it easily. */ static void set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b) @@ -3781,20 +3770,25 @@ set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b) /* Shadow the marker, not the real thing, so that the marker gets restored later. */ tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id); - b->type_shadowed - = tree_cons (id, old_type_value, b->type_shadowed); + b->type_shadowed = tree_cons (id, old_type_value, b->type_shadowed); type = decl ? TREE_TYPE (decl) : NULL_TREE; TREE_TYPE (b->type_shadowed) = type; } else { - tree *slot = find_namespace_slot (current_namespace, id, true); gcc_assert (decl); - update_binding (b, NULL, slot, MAYBE_STAT_DECL (*slot), decl); + if (CHECKING_P) + { + tree *slot = find_namespace_slot (current_namespace, id); + gcc_checking_assert (slot + && (decl == MAYBE_STAT_TYPE (*slot) + || decl == MAYBE_STAT_DECL (*slot))); + } /* Store marker instead of real type. */ type = global_type_node; } + SET_IDENTIFIER_TYPE_VALUE (id, type); }