From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29156 invoked by alias); 30 May 2017 14:46:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29106 invoked by uid 89); 30 May 2017 14:46:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=spin X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 May 2017 14:46:33 +0000 Received: by mail-yw0-f176.google.com with SMTP id b68so40952145ywe.3 for ; Tue, 30 May 2017 07:46:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=0iOg9yyy3FcasY3yII1YtN3qw8quMjWqR+gUJ7ByqKQ=; b=SKux03feJQrcd6X6qcfP5BCk64Wi290CG2kio7//7QSRtu/W8SAWg4WZIybGdngDH0 cOrelmpSpmMsfJtZEC0JiqDweAweP/eKTc0Tza9qsxJmu0GUasYeHsOygUtmRWugE5jD H26qSYcmbRUpcIvUrGRzNP5MtZsRXlOjFNvkC0x3lfIHS+2x+aF5U5hMifTAUm0fOr/g 2BduELhGf2FjG2wMODBWNHLcGwgs12ATqKm4YMK+WqNcVfdlQ8YJS3TQ0YKYi/C+Gjgo 8Hw9LWl1l9CbThUrzDhzBvHN3PFpbKorE/F1tgy/7Kla8WZWRhciDdk7JPAmx3GcmMYW 25qg== X-Gm-Message-State: AODbwcA8kk2xqnibLsS0XhHo8VeE5C21ycRLL8iw+jYJryenv4EW2loH V46KS2ukDJSKNw== X-Received: by 10.129.167.200 with SMTP id e191mr16790523ywh.230.1496155595851; Tue, 30 May 2017 07:46:35 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::3:eff1]) by smtp.googlemail.com with ESMTPSA id y71sm5962936ywy.59.2017.05.30.07.46.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 07:46:35 -0700 (PDT) To: GCC Patches Cc: Rainer Orth , David Edelsohn From: Nathan Sidwell Subject: [C++ PATCH] Fix PR 80913 Message-ID: <3517a8e0-30d6-8e34-3676-a0f2b8199ecc@acm.org> Date: Tue, 30 May 2017 15:29:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------DB4EC98085704A1B6649CF23" X-SW-Source: 2017-05/txt/msg02277.txt.bz2 This is a multi-part message in MIME format. --------------DB4EC98085704A1B6649CF23 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 277 This patch fixes the bootstrap breakage reported by Rainer and David. Thanks for giving this one a spin. We're somewhat overzealous about pushing artificial tags, and excessive cleverness in my creation of update_binding failed to cope with that. nathan -- Nathan Sidwell --------------DB4EC98085704A1B6649CF23 Content-Type: text/x-patch; name="80913.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="80913.diff" Content-length: 5054 2017-05-30 Nathan Sidwell PR c++/80913 * name-lookup.c (add_decl_to_level): Assert not making a circular chain. (update_binding): Don't prematurely slide artificial decl. * g++.dg/lookup/pr80913.C: New. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 248681) +++ cp/name-lookup.c (working copy) @@ -132,6 +132,11 @@ add_decl_to_level (cp_binding_level *b, } else { + /* Make sure we don't create a circular list. xref_tag can end + up pushing the same artificial decl more than once. We + should have already detected that in update_binding. */ + gcc_assert (b->names != decl); + /* We build up the list in reverse order, and reverse it later if necessary. */ TREE_CHAIN (decl) = b->names; @@ -1720,17 +1725,43 @@ update_binding (cp_binding_level *level, tree old, tree decl, bool is_friend) { tree to_val = decl; - tree to_type = NULL_TREE; + tree old_type = slot ? MAYBE_STAT_TYPE (*slot) : binding->type; + tree to_type = old_type; gcc_assert (level->kind == sk_namespace ? !binding : level->kind != sk_class && !slot); if (old == error_mark_node) old = NULL_TREE; + if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (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; + + if (old) + { + /* Slide decl into the type slot, keep old unaltered */ + to_type = decl; + to_val = old; + goto done; + } + } + if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) { - /* Slide the tdef out of the way. We'll undo this below, if - we're pushing a matching tdef. */ + /* Slide old into the type slot. */ to_type = old; old = NULL_TREE; } @@ -1767,39 +1798,14 @@ update_binding (cp_binding_level *level, to_val = ovl_insert (decl, old); } - else if (to_type && TREE_CODE (decl) == TYPE_DECL) - { - /* We thought we wanted to slide an artificial typedef out of - the way, to make way for another typedef. That's not always - what we want to do. */ - if (!DECL_ARTIFICIAL (decl)) - ; /* Slide. */ - else if (same_type_p (TREE_TYPE (to_type), TREE_TYPE (decl))) - /* Two artificial decls to same type. Do nothing. */ - return to_type; - else - goto conflict; - } else if (!old) ; - else if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl)) - { - /* Slide DECL into the type slot. */ - to_type = decl; - to_val = old; - } else if (TREE_CODE (old) != TREE_CODE (decl)) /* Different kinds of decls conflict. */ goto conflict; else if (TREE_CODE (old) == TYPE_DECL) { - if (DECL_ARTIFICIAL (decl)) - { - /* Slide DECL into the type slot instead. */ - to_type = decl; - to_val = old; - } - else if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) + if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) /* Two type decls to the same type. Do nothing. */ return old; else @@ -1835,6 +1841,7 @@ update_binding (cp_binding_level *level, to_val = NULL_TREE; } + done: if (to_val) { if (level->kind != sk_namespace @@ -1854,12 +1861,10 @@ update_binding (cp_binding_level *level, add_decl_to_level (level, to_add); } - if (to_type == (slot ? MAYBE_STAT_TYPE (*slot) : binding->type)) - to_type = NULL_TREE; - - if (to_type) + if (to_type != old_type) { - gcc_checking_assert (TREE_CODE (to_type) == TYPE_DECL + gcc_checking_assert (!old_type + && TREE_CODE (to_type) == TYPE_DECL && DECL_ARTIFICIAL (to_type)); tree type = TREE_TYPE (to_type); @@ -1875,8 +1880,7 @@ update_binding (cp_binding_level *level, { if (STAT_HACK_P (*slot)) { - if (to_type) - STAT_TYPE (*slot) = to_type; + STAT_TYPE (*slot) = to_type; STAT_DECL (*slot) = to_val; } else if (to_type) @@ -1886,8 +1890,7 @@ update_binding (cp_binding_level *level, } else { - if (to_type) - binding->type = to_type; + binding->type = to_type; binding->value = to_val; } } Index: testsuite/g++.dg/lookup/pr80913.C =================================================================== --- testsuite/g++.dg/lookup/pr80913.C (revision 0) +++ testsuite/g++.dg/lookup/pr80913.C (working copy) @@ -0,0 +1,11 @@ +// PR 80913 infinite look on spelling corrector caused by incorrectly +// chained decl + +extern int meminfo (); +struct meminfo {}; + +void frob () +{ + meminf (); // { dg-error "not declared" } + // { dg-message "suggested alternative" "" { target *-*-* } .-1 } +} --------------DB4EC98085704A1B6649CF23--