tree-pretty-print.c (dump_generic_node): Protect against NULL op0.
authorDiego Novillo <dnovillo@google.com>
Mon, 6 Jul 2009 17:04:34 +0000 (13:04 -0400)
committerDiego Novillo <dnovillo@gcc.gnu.org>
Mon, 6 Jul 2009 17:04:34 +0000 (13:04 -0400)
* tree-pretty-print.c (dump_generic_node): Protect
against NULL op0.
(debug_tree_chain): Handle cycles.

From-SVN: r149289

gcc/ChangeLog
gcc/tree-pretty-print.c

index 7a035f6..0c740eb 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-06  Diego Novillo  <dnovillo@google.com>
+
+       * tree-pretty-print.c (dump_generic_node): Protect
+       against NULL op0.
+       (debug_tree_chain): Handle cycles.
+
 2009-07-06  Nick Clifton  <nickc@redhat.com>
            DJ Delorie  <dj@redhat.com>
 
index 1426907..faf23c6 100644 (file)
@@ -99,13 +99,24 @@ debug_generic_stmt (tree t)
 void
 debug_tree_chain (tree t)
 {
+  struct pointer_set_t *seen = pointer_set_create ();
+
   while (t)
-  {
-    print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
-    fprintf(stderr, " ");
-    t = TREE_CHAIN (t);
-  }
+    {
+      print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
+      fprintf (stderr, " ");
+      t = TREE_CHAIN (t);
+      if (pointer_set_insert (seen, t))
+       {
+         fprintf (stderr, "... [cycled back to ");
+         print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
+         fprintf (stderr, "]");
+         break;
+       }
+    }
   fprintf (stderr, "\n");
+
+  pointer_set_destroy (seen);
 }
 
 /* Prints declaration DECL to the FILE with details specified by FLAGS.  */
@@ -1051,7 +1062,7 @@ dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
     case COMPONENT_REF:
       op0 = TREE_OPERAND (node, 0);
       str = ".";
-      if (TREE_CODE (op0) == INDIRECT_REF)
+      if (op0 && TREE_CODE (op0) == INDIRECT_REF)
        {
          op0 = TREE_OPERAND (op0, 0);
          str = "->";