public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: jason merrill <jason@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [debug-early] equate new DIE with DW_AT_specificationto a previous declaration
Date: Tue, 17 Mar 2015 19:58:00 -0000	[thread overview]
Message-ID: <5508874D.70008@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2593 bytes --]

Hi Jason.

I merged mainline into the debug-early branch and I ran into a problem 
compiling a libstdc++ file with -fno-implicit-templates.  The attached 
patch is what I used to solve the problem but I wanted to run it by you, 
to make sure I'm not overlooking something silly, or worse...something 
much more complicated.

The reduced testcase is the following, compiled with 
-fno-implicit-templates -g -O2 -std=gnu++11:

class Object
{
public:
   void Method();
};

void funky()
{
   Object<int> foobar;
   foobar.Method();
}

template<typename SomeType>
void
Object<SomeType>::Method()
{
}

In mainline, we call gen_subprogram_die() twice for 
Object<int>::Method(): once, while generating class members, and once 
while inlining (outlining_inline_function hook).  The debug-early path 
is somewhat different, and we end up calling gen_subprogram_die() three 
times, the last of which ICEs.  What happens is the following...

We call gen_subprogram_die() as usual while generating class members, 
but then we call it again by virtue of it being a reachable function. 
This extra call will follow the DW_AT_specification code path because we 
have a previously cached die:

	  subr_die = new_die (DW_TAG_subprogram, context_die, decl);
	  add_AT_specification (subr_die, old_die);
           add_pubname (decl, subr_die);

The problem is that, for -fno-implicit-templates, the decl is now 
DECL_EXTERNAL, which means we never equate this new "DIE with 
DW_AT_specification" to the DECL.  That is, we never fall through here:

   else if (!DECL_EXTERNAL (decl))
     {
       HOST_WIDE_INT cfa_fb_offset;

       struct function *fun = DECL_STRUCT_FUNCTION (decl);

       if (!old_die || !get_AT (old_die, DW_AT_inline))
	equate_decl_number_to_die (decl, subr_die);

However, when we call gen_subprogram_die() the third time through the 
outlining_inline_function hook (late debug), we again try to add a 
DW_AT_specification to the DIE cached from the first time around, but 
this time we ICE because we're not supposed to have multiple 
DW_AT_specification's pointing to the same DIE (the old original DIE).

My solution is just to call equate_decl_number_to_die() as soon as we 
create the DW_AT_specification marked DIE the second time around.  The 
third time we will just pick up this last cached DIE with 
DW_AT_specification, mark it as DW_AT_inline, and voila, everything 
works.  The dwarf generation is as mainline, and we can build libstdc++ 
with no regressions to the guality testsuite.

Does this sound reasonable, or is this something a lot more complicated?

Thanks.
Aldy

[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 670 bytes --]

commit 0a49042b9151e0387efc5f87c32cb24968896ae4
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Mar 17 12:29:27 2015 -0700

    Equate new DIE containing a DW_AT_specification, to the original
    declaration.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 86815be..c7345d9 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18809,6 +18809,8 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 		add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
 				    TYPE_UNQUALIFIED, context_die);
 	    }
+	  if (early_dwarf_dumping)
+	    equate_decl_number_to_die (decl, subr_die);
 	}
     }
   /* Anything else... create a brand new DIE.  */

             reply	other threads:[~2015-03-17 19:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 19:58 Aldy Hernandez [this message]
2015-03-18  2:12 ` Jason Merrill
2015-03-18 15:51   ` Aldy Hernandez
2015-04-03 14:41     ` Jason Merrill
2015-04-10 21:10       ` Aldy Hernandez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5508874D.70008@redhat.com \
    --to=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).