public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix dwarf2out ICE with C++17 inline static data members with redundant redeclaration (PR debug/80234)
Date: Wed, 29 Mar 2017 19:51:00 -0000	[thread overview]
Message-ID: <20170329194240.GG17461@tucnak> (raw)

Hi!

When a C++17 inline static data member has a redundant out-of-class
deprecated redeclaration, we can end up with 2 DW_TAG_variable in
DW_TAG_compile_unit, one DW_AT_declaration and one with DW_AT_specification
pointing to it (the latter emitted for the redeclaration), before
gen_member_die can do its job.  In there we want to move the declaration
DIE into the class and have a CU child DW_TAG_variable that has
DW_AT_specification pointing to it.  But in this case we've put
the DIE with DW_AT_specification into the hash table and gen_member_die
ICEs in splice_child_die.  The following patch handles that case gracefully,
by moving the DW_AT_declaration DIE into the class instead of trying to
move the DW_AT_specification one, and by making sure we don't create
yet another DIE with DW_AT_specification because we already have one.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-03-29  Jakub Jelinek  <jakub@redhat.com>

	PR debug/80234
	* dwarf2out.c (gen_member_die): Handle C++17 inline static data
	members with redundant out-of-class redeclaration.

	* g++.dg/debug/dwarf2/pr80234-1.C: New test.
	* g++.dg/debug/dwarf2/pr80234-2.C: New test.

--- gcc/dwarf2out.c.jj	2017-03-24 14:17:59.000000000 +0100
+++ gcc/dwarf2out.c	2017-03-29 17:19:08.513497649 +0200
@@ -24085,6 +24085,10 @@ gen_member_die (tree type, dw_die_ref co
   for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
     {
       struct vlr_context vlr_ctx = { type, NULL_TREE };
+      bool static_inline_p
+	= (TREE_STATIC (member)
+	   && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
+	       != -1));
 
       /* If we thought we were generating minimal debug info for TYPE
 	 and then changed our minds, some of the member declarations
@@ -24096,9 +24100,33 @@ gen_member_die (tree type, dw_die_ref co
 	{
 	  /* Handle inline static data members, which only have in-class
 	     declarations.  */
+	  dw_die_ref ref = NULL; 
+	  if (child->die_tag == DW_TAG_variable
+	      && child->die_parent == comp_unit_die ())
+	    {
+	      ref = get_AT_ref (child, DW_AT_specification);
+	      /* For C++17 inline static data members followed by redundant
+		 out of class redeclaration, we might get here with
+		 child being the DIE created for the out of class
+		 redeclaration and with its DW_AT_specification being
+		 the DIE created for in-class definition.  We want to
+		 reparent the latter, and don't want to create another
+		 DIE with DW_AT_specification in that case, because
+		 we already have one.  */
+	      if (ref
+		  && static_inline_p
+		  && ref->die_tag == DW_TAG_variable
+		  && ref->die_parent == comp_unit_die ()
+		  && get_AT (ref, DW_AT_specification) == NULL)
+		{
+		  child = ref;
+		  ref = NULL;
+		  static_inline_p = false;
+		}
+	    }
 	  if (child->die_tag == DW_TAG_variable
 	      && child->die_parent == comp_unit_die ()
-	      && get_AT (child, DW_AT_specification) == NULL)
+	      && ref == NULL)
 	    {
 	      reparent_child (child, context_die);
 	      if (dwarf_version < 5)
@@ -24126,9 +24154,7 @@ gen_member_die (tree type, dw_die_ref co
       /* For C++ inline static data members emit immediately a DW_TAG_variable
 	 DIE that will refer to that DW_TAG_member/DW_TAG_variable through
 	 DW_AT_specification.  */
-      if (TREE_STATIC (member)
-	  && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
-	      != -1))
+      if (static_inline_p)
 	{
 	  int old_extern = DECL_EXTERNAL (member);
 	  DECL_EXTERNAL (member) = 0;
--- gcc/testsuite/g++.dg/debug/dwarf2/pr80234-1.C.jj	2017-03-29 17:23:43.606901317 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/pr80234-1.C	2017-03-29 17:22:51.000000000 +0200
@@ -0,0 +1,15 @@
+// PR debug/80234
+// { dg-do compile }
+// { dg-options "-gdwarf-4 -std=c++17" }
+
+struct S
+{
+  static constexpr const char n = 'S';
+  virtual ~S ();
+};
+
+constexpr const char S::n;
+
+S::~S()
+{
+}
--- gcc/testsuite/g++.dg/debug/dwarf2/pr80234-2.C.jj	2017-03-29 17:23:54.663756769 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/pr80234-2.C	2017-03-29 17:23:59.818689378 +0200
@@ -0,0 +1,15 @@
+// PR debug/80234
+// { dg-do compile }
+// { dg-options "-gdwarf-5 -std=c++17" }
+
+struct S
+{
+  static constexpr const char n = 'S';
+  virtual ~S ();
+};
+
+constexpr const char S::n;
+
+S::~S()
+{
+}

	Jakub

             reply	other threads:[~2017-03-29 19:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-29 19:51 Jakub Jelinek [this message]
2017-04-06 16:51 ` Jeff Law

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=20170329194240.GG17461@tucnak \
    --to=jakub@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).