ee890f
2013-07-25  Sterling Augustine  <saugustine@google.com>
ee890f
ee890f
	* dwarf2out.c (size_of_pubnames): Move code to...
ee890f
	(include_pubname_in_output): ...here.  New.
ee890f
	(output_pubnames): Call include_pubname_in_output.  Move assertion.
ee890f
ee890f
--- gcc/dwarf2out.c	(revision 201254)
ee890f
+++ gcc/dwarf2out.c	(revision 201255)
ee890f
@@ -7806,6 +7806,30 @@ unmark_all_dies (dw_die_ref die)
ee890f
       unmark_all_dies (AT_ref (a));
ee890f
 }
ee890f
 
ee890f
+/* Calculate if the entry should appear in the final output file.  It may be
ee890f
+   from a pruned a type.  */
ee890f
+
ee890f
+static bool
ee890f
+include_pubname_in_output (vec<pubname_entry, va_gc> *table, pubname_entry *p)
ee890f
+{
ee890f
+  if (table == pubname_table)
ee890f
+    {
ee890f
+      /* Enumerator names are part of the pubname table, but the parent
ee890f
+	 DW_TAG_enumeration_type die may have been pruned.  Don't output
ee890f
+	 them if that is the case.  */
ee890f
+      if (p->die->die_tag == DW_TAG_enumerator && !p->die->die_mark)
ee890f
+	return false;
ee890f
+
ee890f
+      /* Everything else in the pubname table is included.  */
ee890f
+      return true;
ee890f
+    }
ee890f
+
ee890f
+  /* The pubtypes table shouldn't include types that have been
ee890f
+     pruned.  */
ee890f
+  return (p->die->die_offset != 0
ee890f
+	  || !flag_eliminate_unused_debug_types);
ee890f
+}
ee890f
+
ee890f
 /* Return the size of the .debug_pubnames or .debug_pubtypes table
ee890f
    generated for the compilation unit.  */
ee890f
 
ee890f
@@ -7818,9 +7842,7 @@ size_of_pubnames (vec
ee890f
 
ee890f
   size = DWARF_PUBNAMES_HEADER_SIZE;
ee890f
   FOR_EACH_VEC_ELT (*names, i, p)
ee890f
-    if (names != pubtype_table
ee890f
-	|| p->die->die_offset != 0
ee890f
-	|| !flag_eliminate_unused_debug_types)
ee890f
+    if (include_pubname_in_output (names, p))
ee890f
       size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
ee890f
 
ee890f
   size += DWARF_OFFSET_SIZE;
ee890f
@@ -8999,22 +9021,14 @@ output_pubnames (vec
ee890f
 
ee890f
   FOR_EACH_VEC_ELT (*names, i, pub)
ee890f
     {
ee890f
-      /* Enumerator names are part of the pubname table, but the parent
ee890f
-         DW_TAG_enumeration_type die may have been pruned.  Don't output
ee890f
-         them if that is the case.  */
ee890f
-      if (pub->die->die_tag == DW_TAG_enumerator && !pub->die->die_mark)
ee890f
-        continue;
ee890f
-
ee890f
-      /* We shouldn't see pubnames for DIEs outside of the main CU.  */
ee890f
-      if (names == pubname_table)
ee890f
-	gcc_assert (pub->die->die_mark);
ee890f
-
ee890f
-      if (names != pubtype_table
ee890f
-	  || pub->die->die_offset != 0
ee890f
-	  || !flag_eliminate_unused_debug_types)
ee890f
+      if (include_pubname_in_output (names, pub))
ee890f
 	{
ee890f
 	  dw_offset die_offset = pub->die->die_offset;
ee890f
 
ee890f
+	  /* We shouldn't see pubnames for DIEs outside of the main CU.  */
ee890f
+	  if (names == pubname_table)
ee890f
+	    gcc_assert (pub->die->die_mark);
ee890f
+
ee890f
 	  /* If we're putting types in their own .debug_types sections,
ee890f
 	     the .debug_pubtypes table will still point to the compile
ee890f
 	     unit (not the type unit), so we want to use the offset of