[LTO][PATCH] Fix lto1 ICE in pp_base_format

Simon Baldwin simonb@google.com
Fri Nov 21 14:52:00 GMT 2008


This patch fixes a compiler error that can occur in lto1 where a backend
diagnostic message contains a %E formatter.  Without the patch lto1 fails
at pretty-print.c:559, for example:

  $ cat sse.cc
  typedef short v8hi __attribute__((__vector_size__(16)));
  static void func() { v8hi x, y, z; z = __builtin_ia32_paddw128(x, y); }
  $ gcc -msse2 -fwhopr -c sse.cc
  $ gcc -shared -fwhopr -o /dev/null sse.o
  ...
  In function 'func':
  in pp_base_format, at pretty-print.c:559
  Please submit a full bug report,...

lto1 fails trying to print "error: '__builtin_ia32_paddw128' needs isa
option -msse2".  With the patch in place, lto1 prints the expected message.


gcc/lto/ChangeLog
2008-11-21  Simon Baldwin  <simonb@google.com>

	* lto.c (lto_tree_printer): New function.
	(lto_main): Register lto_tree_printer() for diagnostics.


Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c	(revision 142039)
+++ gcc/lto/lto.c	(working copy)
@@ -55,6 +55,9 @@ Boston, MA 02110-1301, USA.  */
 DEF_VEC_P(bitmap);
 DEF_VEC_ALLOC_P(bitmap,heap);
 
+static bool lto_tree_printer (pretty_printer *, text_info *, const char *,
+			      int, bool, bool, bool);
+
 /* Read the constructors and inits.  */
 
 static void
@@ -1246,6 +1249,60 @@ lto_maybe_unlink (const char *file)
     fprintf (stderr, "[Leaving LTRANS %s]\n", file);
 }
 
+/* Called during diagnostic message formatting process to print a
+   source-level entity onto BUFFER.  This is a slightly extended version
+   of default_tree_printer() from toplev.c, and adds support for the '%E'
+   for error messages printed by backends.  */
+
+static bool
+lto_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
+		  int precision, bool wide, bool set_locus, bool hash)
+{
+  tree t = va_arg (*text->args_ptr, tree);
+  const char *n = "({anonymous})";
+  pp->padding = pp_none;
+
+  if (precision != 0 || wide || hash)
+    return false;
+
+  if (set_locus && text->locus)
+    *text->locus = DECL_SOURCE_LOCATION (t);
+
+  switch (*spec)
+    {
+    case 'E':
+      if (TREE_CODE (t) == IDENTIFIER_NODE)
+	{
+	  pp_string (pp, IDENTIFIER_POINTER (t));
+	  return true;
+	}
+      break;
+
+    case 'D':
+      if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
+	t = DECL_DEBUG_EXPR (t);
+      /* FALLTHRU */
+
+    case 'F':
+    case 'T':
+      break;
+
+    default:
+      return false;
+    }
+
+  if (DECL_P (t))
+    {
+      if (DECL_NAME (t))
+	n = lang_hooks.decl_printable_name (t, 2);
+      pp_string (pp, n);
+    }
+  else
+    dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
+
+  return true;
+}
+
 void
 lto_main (int debug_p ATTRIBUTE_UNUSED)
 {
@@ -1260,6 +1317,9 @@ lto_main (int debug_p ATTRIBUTE_UNUSED)
   unsigned num_objects;
   int t;
 
+  /* Register a tree printer for diagnostics.  */
+  diagnostic_format_decoder (global_dc) = &lto_tree_printer;
+
   /* Set the hooks so that all of the ipa passes can read in their data.  */
   lto_set_in_hooks (all_file_decl_data, get_section_data,
 		    free_section_data);



More information about the Gcc-patches mailing list