From f78f5d239203d0da6638bc5e20080971d61d09d9 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
Date: Mon, 13 May 2019 11:56:57 +0000
Subject: [PATCH] [DWARF] dwarf2out cleanups

https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00485.html
	* dwarf2out.c (breakout_comdat_types): Move comment to correct
	piece of code.
	(const_ok_for_output_1): Balance parens around #if/#else/#endif
	(gen_member_die): Move abstract origin check earlier.  Only VARs
	can be static_inline_p.  Simplify splicing control flow.

From-SVN: r271127
---
 gcc/ChangeLog   |  8 ++++++++
 gcc/dwarf2out.c | 44 ++++++++++++++++++++++++--------------------
 2 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3057c620e533..6e8d81801588 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2019-05-13  Nathan Sidwell  <nathan@acm.org>
+
+	* dwarf2out.c (breakout_comdat_types): Move comment to correct
+	piece of code.
+	(const_ok_for_output_1): Balance parens around #if/#else/#endif
+	(gen_member_die): Move abstract origin check earlier.  Only VARs
+	can be static_inline_p.  Simplify splicing control flow.
+
 2019-05-13  Richard Biener  <rguenther@suse.de>
 
 	* tree-vect-slp.c (vect_get_and_check_slp_defs): Handle
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5b1a32b65c8c..e5d8ebc6a117 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -8576,11 +8576,12 @@ break_out_comdat_types (dw_die_ref die)
         /* Break out nested types into their own type units.  */
         break_out_comdat_types (c);
 
-        /* Create a new type unit DIE as the root for the new tree, and
-           add it to the list of comdat types.  */
+        /* Create a new type unit DIE as the root for the new tree.  */
         unit = new_die (DW_TAG_type_unit, NULL, NULL);
         add_AT_unsigned (unit, DW_AT_language,
                          get_AT_unsigned (comp_unit_die (), DW_AT_language));
+
+	/* Add the new unit's type DIE into the comdat type list.  */
         type_node = ggc_cleared_alloc<comdat_type_node> ();
         type_node->root_die = unit;
         type_node->next = comdat_type_list;
@@ -14509,11 +14510,10 @@ const_ok_for_output_1 (rtx rtl)
 		"non-delegitimized UNSPEC %s (%d) found in variable location",
 		((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
 		 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
-		XINT (rtl, 1));
 #else
 		"non-delegitimized UNSPEC %d found in variable location",
-		XINT (rtl, 1));
 #endif
+		XINT (rtl, 1));
       expansion_failed (NULL_TREE, rtl,
 			"UNSPEC hasn't been delegitimized.\n");
       return false;
@@ -25161,19 +25161,20 @@ gen_member_die (tree type, dw_die_ref context_die)
 			     context_die);
     }
 
-  /* Now output info about the data members and type members.  */
+  /* Now output info about the members. */
   for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
     {
+      /* Ignore clones.  */
+      if (DECL_ABSTRACT_ORIGIN (member))
+	continue;
+
       struct vlr_context vlr_ctx = { type, NULL_TREE };
       bool static_inline_p
-	= (TREE_STATIC (member)
+	= (VAR_P (member)
+	   && TREE_STATIC (member)
 	   && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
 	       != -1));
 
-      /* Ignore clones.  */
-      if (DECL_ABSTRACT_ORIGIN (member))
-	continue;
-
       /* If we thought we were generating minimal debug info for TYPE
 	 and then changed our minds, some of the member declarations
 	 may have already been defined.  Don't define them again, but
@@ -25183,11 +25184,14 @@ gen_member_die (tree type, dw_die_ref context_die)
 	{
 	  /* Handle inline static data members, which only have in-class
 	     declarations.  */
-	  dw_die_ref ref = NULL; 
+	  bool splice = true;
+
+	  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
@@ -25206,17 +25210,17 @@ gen_member_die (tree type, dw_die_ref context_die)
 		  ref = NULL;
 		  static_inline_p = false;
 		}
-	    }
 
-	  if (child->die_tag == DW_TAG_variable
-	      && child->die_parent == comp_unit_die ()
-	      && ref == NULL)
-	    {
-	      reparent_child (child, context_die);
-	      if (dwarf_version < 5)
-		child->die_tag = DW_TAG_member;
+	      if (!ref)
+		{
+		  reparent_child (child, context_die);
+		  if (dwarf_version < 5)
+		    child->die_tag = DW_TAG_member;
+		  splice = false;
+		}
 	    }
-	  else
+
+	  if (splice)
 	    splice_child_die (context_die, child);
 	}
 
-- 
GitLab