From patchwork Thu Apr 11 15:50:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 235816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A5A112C013E for ; Fri, 12 Apr 2013 01:51:07 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=Y1pItFVl2JtcHwXFBjKYUJ6112hko7kfaxqXjTvJ32K QyypardCM6AGHDGRwnPjeTcfIGk6GnE4/pe5n9gZju0ts0AzM1NyXJ8KgFnnbjtP D6ZTQ5aHXIbeKxolW83zgSgSaP4EHxbGcjQEZFZ3z67EDD5kjZeteIeggOm+EiIU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=iwIbjycXBhSp/jgX5CP+v8Wjh14=; b=wHhpZ2W05OSb3BT4b kn8ht7NLgURB4dOuel7wiccPCi1iF6PiS1Cfpa9STx6CH5DxdhCf/B92r8kx67FA JOxPD2exkgLUrqsC7blgcF4A6hgvM5eso6xFS9QIQG/CEPzm1NJqFbTd1FjHf2+F eFjVJeSNbzNIX5jV2hIleZQW9E= Received: (qmail 9624 invoked by alias); 11 Apr 2013 15:51:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9608 invoked by uid 89); 11 Apr 2013 15:51:00 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 11 Apr 2013 15:50:59 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3BFowYd026728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Apr 2013 11:50:58 -0400 Received: from [10.3.113.30] (ovpn-113-30.phx2.redhat.com [10.3.113.30]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3BFovpU023755; Thu, 11 Apr 2013 11:50:57 -0400 Message-ID: <5166DBE1.4000804@redhat.com> Date: Thu, 11 Apr 2013 11:50:57 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List CC: Jakub Jelinek Subject: C++ PATCH to tsubst of var_decl X-Virus-Found: No 56901 turns out to be related to an issue that has been bugging me for a while; we would hand off instantiation of a use of a variable to tsubst_decl, which might end up producing a whole new instantiation of the variable rather than look up the one that we (presumably) already have. 56901 is an instance of failing to find an existing declaration, trying to produce a new one, and running into trouble. Rather than this, we should be more assertive about requiring that variables be declared before they are used. Indeed, when I make this change the only place in the compiler that needed to be fixed was the OpenMP for-loop, where a DECL_EXPR for the iterator ends up in OMP_FOR_PRE_BODY, so we need to be sure to instantiate that before we instantiate anything that mentions the iterator. Tested x86_64-pc-linux-gnu, applying to trunk. commit 86959b6f73148a9a09d31945d465d42f936aff39 Author: Jason Merrill Date: Thu Apr 11 09:16:51 2013 -0400 * pt.c (tsubst_copy) [VAR_DECL]: Don't call tsubst for local variables, look them up instead. (tsubst_decl) [VAR_DECL]: Remove handling for anonymous union proxies and substitution in unevaluated context. (tsubst_expr) [OMP_FOR]: Instantiate OMP_FOR_PRE_BODY before the iterators. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1c0b3ec..487a985 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10666,16 +10666,6 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) break; } - if (VAR_P (t) && DECL_ANON_UNION_VAR_P (t)) - { - /* Just use name lookup to find a member alias for an anonymous - union, but then add it to the hash table. */ - r = lookup_name (DECL_NAME (t)); - gcc_assert (DECL_ANON_UNION_VAR_P (r)); - register_local_specialization (r, t); - break; - } - /* Create a new node for the specialization we need. */ r = copy_decl (t); if (type == NULL_TREE) @@ -10780,21 +10770,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) SET_DECL_IMPLICIT_INSTANTIATION (r); } else if (cp_unevaluated_operand) - { - /* We're substituting this var in a decltype outside of its - scope, such as for a lambda return type. Don't add it to - local_specializations, do perform auto deduction. */ - tree auto_node = type_uses_auto (type); - if (auto_node) - { - tree init - = tsubst_expr (DECL_INITIAL (t), args, complain, in_decl, - /*constant_expression_p=*/false); - init = resolve_nondeduced_context (init); - TREE_TYPE (r) = type - = do_auto_deduction (type, init, auto_node); - } - } + gcc_unreachable (); else register_local_specialization (r, t); @@ -12208,11 +12184,32 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) case VAR_DECL: case FUNCTION_DECL: - if ((DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)) - || local_variable_p (t)) - t = tsubst (t, args, complain, in_decl); - mark_used (t); - return t; + if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)) + r = tsubst (t, args, complain, in_decl); + else if (local_variable_p (t)) + { + r = retrieve_local_specialization (t); + if (r == NULL_TREE) + { + if (DECL_ANON_UNION_VAR_P (t)) + { + /* Just use name lookup to find a member alias for an + anonymous union, but then add it to the hash table. */ + r = lookup_name (DECL_NAME (t)); + gcc_assert (DECL_ANON_UNION_VAR_P (r)); + register_local_specialization (r, t); + } + else + { + gcc_assert (errorcount || sorrycount); + return error_mark_node; + } + } + } + else + r = t; + mark_used (r); + return r; case NAMESPACE_DECL: return t; @@ -13251,15 +13248,15 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, stmt = begin_omp_structured_block (); + pre_body = push_stmt_list (); + RECUR (OMP_FOR_PRE_BODY (t)); + pre_body = pop_stmt_list (pre_body); + for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++) tsubst_omp_for_iterator (t, i, declv, initv, condv, incrv, &clauses, args, complain, in_decl, integral_constant_expression_p); - pre_body = push_stmt_list (); - RECUR (OMP_FOR_PRE_BODY (t)); - pre_body = pop_stmt_list (pre_body); - body = push_stmt_list (); RECUR (OMP_FOR_BODY (t)); body = pop_stmt_list (body);