This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] RFA: c-pretty-print tolerance for loopy chains
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 28 Aug 2002 16:34:18 -0400
- Subject: [tree-ssa] RFA: c-pretty-print tolerance for loopy chains
Hi -
The following patch teaches one function in c-pretty-print
how to deal with buggy tree structures that somehow end up
with TREE_CHAIN loops. It's useful for debugging these
"can't happen" conditions. Shall I commit?
2002-08-28 Frank Ch. Eigler <fche@redhat.com>
* c-pretty-print.c (dump_c_tree): Detect loops in statement chains
using a hash table to track visited status.
Index: c-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pretty-print.c,v
retrieving revision 1.1.4.8
diff -u -w -s -p -r1.1.4.8 c-pretty-print.c
--- c-pretty-print.c 26 Aug 2002 01:34:49 -0000 1.1.4.8
+++ c-pretty-print.c 28 Aug 2002 20:31:25 -0000
@@ -27,6 +27,7 @@ Software Foundation, 59 Temple Place - S
#include "c-common.h"
#include "diagnostic.h"
#include "real.h"
+#include "hashtab.h"
static int op_prio PARAMS ((tree));
static const char *op_symbol PARAMS ((tree));
@@ -129,9 +130,21 @@ dump_c_tree (buffer, t, spc)
HOST_WIDE_INT spc;
{
tree node = t;
+ htab_t htab;
+ int circularity_p = 0;
+
+ htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
while (node && node != error_mark_node)
{
+ void **slot;
+ slot = htab_find_slot (htab, node, INSERT);
+ *slot = (void *) node;
+
spc = dump_c_node (buffer, node, spc, 0);
+
+ if (circularity_p)
+ break;
+
switch (TREE_CODE (node))
{
case TYPE_DECL:
@@ -140,12 +153,21 @@ dump_c_tree (buffer, t, spc)
case PARM_DECL:
/* Some nodes on which we need to stop the recursive printing,
otherwise we print all declared vars in the scope. */
+ {
+ htab_delete (htab);
return;
+ }
default:
break;
}
node = TREE_CHAIN (node);
+ if (htab_find (htab, node))
+ {
+ output_add_string (buffer, "/* circularity detected! */\n");
+ circularity_p = 1; /* Allow one final loop iteration. */
+ }
}
+ htab_delete (htab);
}
/* Dump the node NODE on the output_buffer BUFFER, SPC spaces of indent. */