[lto][patch] Fix segfaults in dump_generic_node

Cary Coutant ccoutant@google.com
Thu Nov 6 22:19:00 GMT 2008


With the pruning of the trees in LTO, some nodes can now be NULL that
the pretty-printing code isn't expecting to be NULL, leading to
segfaults when GLOBAL_STREAMER_TRACE is defined. This patch fixes two
of those situations that I've encountered.

OK?

-cary


2008-11-06  Cary Coutant  <ccoutant@google.com>

        * tree-pretty-print.c (dump_generic_node): Guard against NULL
TREE_TYPE and
          TYPE_METHOD_BASETYPE.


Index: tree-pretty-print.c
===================================================================
--- tree-pretty-print.c	(revision 141655)
+++ tree-pretty-print.c	(working copy)
@@ -574,7 +574,12 @@ dump_generic_node (pretty_printer *buffe
     case REFERENCE_TYPE:
       str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");

-      if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
+      if (TREE_TYPE (node) == NULL)
+        {
+	  pp_string (buffer, str);
+          pp_string (buffer, "<null type>");
+        }
+      else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
         {
 	  tree fnode = TREE_TYPE (node);

@@ -615,7 +620,10 @@ dump_generic_node (pretty_printer *buffe
       break;

     case METHOD_TYPE:
-      dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
+      if (TYPE_METHOD_BASETYPE (node))
+        dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE
(node)), flags);
+      else
+        pp_string (buffer, "<null method basetype>");
       pp_string (buffer, "::");
       break;



More information about the Gcc-patches mailing list