From patchwork Thu Oct 13 21:22:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 119638 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]) by ozlabs.org (Postfix) with SMTP id CF8B2B71CF for ; Fri, 14 Oct 2011 08:22:45 +1100 (EST) Received: (qmail 23787 invoked by alias); 13 Oct 2011 21:22:41 -0000 Received: (qmail 23468 invoked by uid 22791); 13 Oct 2011 21:22:39 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Oct 2011 21:22:24 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9DLMO3S013007 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Oct 2011 17:22:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9DLMNZ5026637 for ; Thu, 13 Oct 2011 17:22:24 -0400 Received: from [0.0.0.0] (ovpn-113-114.phx2.redhat.com [10.3.113.114]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p9DLMMi9007599 for ; Thu, 13 Oct 2011 17:22:23 -0400 Message-ID: <4E97568E.7090406@redhat.com> Date: Thu, 13 Oct 2011 17:22:22 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50614 (ICE with NSDMI and -fcompare-debug) 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 The problem here was that with -fcompare-debug, execute_cleanup_cfg_post_optimizing wants to print out all the decls used in a function, which involves printing the DECL_INITIAL, and the instantiation of a FIELD_DECL with an NSDMI had an uninstantiated DECL_INITIAL, so the dumper got confused by the C++ tree codes. Fixed by setting DECL_INITIAL of instantiated FIELD_DECLs to error_mark_node and using DECL_TEMPLATE_INFO to look up the original NSDMI instead. Tested x86_64-pc-linux-gnu, applying to trunk. commit 69647e299fba76f47d157699d80afcc2c703e408 Author: Jason Merrill Date: Thu Oct 13 16:59:42 2011 -0400 PR c++/50614 * cp-tree.h (VAR_TEMPL_TYPE_FIELD_OR_FUNCTION_DECL_CHECK): New. (DECL_TEMPLATE_INFO): Use it. * pt.c (tsubst_decl) [FIELD_DECL]: Set DECL_TEMPLATE_INFO if the decl has an NSDMI. * init.c (perform_member_init): Use it. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index e42cda1..98599f9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -201,6 +201,9 @@ c-common.h, not after. #define VAR_TEMPL_TYPE_OR_FUNCTION_DECL_CHECK(NODE) \ TREE_CHECK4(NODE,VAR_DECL,FUNCTION_DECL,TYPE_DECL,TEMPLATE_DECL) +#define VAR_TEMPL_TYPE_FIELD_OR_FUNCTION_DECL_CHECK(NODE) \ + TREE_CHECK5(NODE,VAR_DECL,FIELD_DECL,FUNCTION_DECL,TYPE_DECL,TEMPLATE_DECL) + #define BOUND_TEMPLATE_TEMPLATE_PARM_TYPE_CHECK(NODE) \ TREE_CHECK(NODE,BOUND_TEMPLATE_TEMPLATE_PARM) @@ -2556,7 +2559,7 @@ extern void decl_shadowed_for_var_insert (tree, tree); global function f. In this case, DECL_TEMPLATE_INFO for S::f will be non-NULL, but DECL_USE_TEMPLATE will be zero. */ #define DECL_TEMPLATE_INFO(NODE) \ - (DECL_LANG_SPECIFIC (VAR_TEMPL_TYPE_OR_FUNCTION_DECL_CHECK (NODE)) \ + (DECL_LANG_SPECIFIC (VAR_TEMPL_TYPE_FIELD_OR_FUNCTION_DECL_CHECK (NODE)) \ ->u.min.template_info) /* For a VAR_DECL, indicates that the variable is actually a @@ -2701,7 +2704,10 @@ extern void decl_shadowed_for_var_insert (tree, tree); template struct S { friend void f(int, double); } the DECL_TI_TEMPLATE will be an IDENTIFIER_NODE for `f' and the - DECL_TI_ARGS will be {int}. */ + DECL_TI_ARGS will be {int}. + + For a FIELD_DECL, this value is the FIELD_DECL it was instantiated + from. */ #define DECL_TI_TEMPLATE(NODE) TI_TEMPLATE (DECL_TEMPLATE_INFO (NODE)) /* The template arguments used to obtain this decl from the most diff --git a/gcc/cp/init.c b/gcc/cp/init.c index a21e566..4561979 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -497,11 +497,11 @@ perform_member_init (tree member, tree init) mem-initializer for this field. */ if (init == NULL_TREE) { - if (CLASSTYPE_TEMPLATE_INSTANTIATION (DECL_CONTEXT (member))) + if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) /* Do deferred instantiation of the NSDMI. */ init = (tsubst_copy_and_build - (DECL_INITIAL (member), - CLASSTYPE_TI_ARGS (DECL_CONTEXT (member)), + (DECL_INITIAL (DECL_TI_TEMPLATE (member)), + DECL_TI_ARGS (member), tf_warning_or_error, member, /*function_p=*/false, /*integral_constant_expression_p=*/false)); else diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 880f3d1..1632c01 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10269,6 +10269,16 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) = tsubst_expr (DECL_INITIAL (t), args, complain, in_decl, /*integral_constant_expression_p=*/true); + else if (DECL_INITIAL (t)) + { + /* Set up DECL_TEMPLATE_INFO so that we can get at the + NSDMI in perform_member_init. Still set DECL_INITIAL + to error_mark_node so that we know there is one. */ + DECL_INITIAL (r) = error_mark_node; + gcc_assert (DECL_LANG_SPECIFIC (r) == NULL); + retrofit_lang_decl (r); + DECL_TEMPLATE_INFO (r) = build_template_info (t, args); + } /* We don't have to set DECL_CONTEXT here; it is set by finish_member_declaration. */ DECL_CHAIN (r) = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template2.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template2.C new file mode 100644 index 0000000..27b0aa5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template2.C @@ -0,0 +1,14 @@ +// PR c++/50614 +// { dg-options "-std=c++0x -fcompare-debug" } + +struct A +{ + int f (); +}; + +template struct B : A +{ + int i = this->f (); +}; + +B<0> b;