Hi,

Atm, using fdump-tree-all-graph produces invalid dot files:
...
$ rm *.c.* ; gcc test.c -O2 -S -fdump-tree-all-graph
$ for f in *.dot; do dot -Tpdf $f -o dot.pdf; done
Warning: test.c.006t.omplower.dot: syntax error in line 1 near '}'
Warning: test.c.007t.lower.dot: syntax error in line 1 near '}'
Warning: test.c.010t.eh.dot: syntax error in line 1 near '}'
Warning: test.c.292t.statistics.dot: syntax error in line 1 near '}'
$ cat test.c.006t.omplower.dot
}
$
...
These dot files are finalized, but never initialized or used.

The 006/007/010 files are not used because '(fn->curr_properties & PROP_cfg) == 0' at the corresponding passes.

And the file test.c.292t.statistics.dot is not used, because it doesn't belong to a single pass.

The current finalization code doesn't handle these cases:
...
  /* Do whatever is necessary to finish printing the graphs.  */
  for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
    if (dumps->dump_initialized_p (i)
        && (dfi->pflags & TDF_GRAPH) != 0
        && (name = dumps->get_dump_file_name (i)) != NULL)
      {
        finish_graph_dump_file (name);
        free (name);
      }
...

The patch fixes this by simply testing for pass->graph_dump_initialized instead.

[ That fix exposes the lack of initialization of graph_dump_initialized. It seems to be initialized for static passes, but for dynamically added passes, such as f.i. vzeroupper the value is uninitialized. The patch also fixes this. ]

Bootstrapped and reg-tested on x86_64.

OK for stage1?

Thanks,
- Tom
Only finalize dot files that have been initialized

2016-03-16  Tom de Vries  <t...@codesourcery.com>

	PR other/70185
	* passes.c (opt_pass::opt_pass): Add missing initialization of
	graph_dump_initialized.
	(finish_optimization_passes): Only call finish_graph_dump_file if
	pass->graph_dump_initialized.

---
 gcc/passes.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/gcc/passes.c b/gcc/passes.c
index 9d90251..5aa2b32 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -105,6 +105,7 @@ opt_pass::opt_pass (const pass_data &data, context *ctxt)
     sub (NULL),
     next (NULL),
     static_pass_number (0),
+    graph_dump_initialized (false),
     m_ctxt (ctxt)
 {
 }
@@ -363,14 +364,18 @@ finish_optimization_passes (void)
     }
 
   /* Do whatever is necessary to finish printing the graphs.  */
+  gcc::pass_manager *passes = g->get_passes ();
   for (i = TDI_end; (dfi = dumps->get_dump_file_info (i)) != NULL; ++i)
-    if (dumps->dump_initialized_p (i)
-	&& (dfi->pflags & TDF_GRAPH) != 0
-	&& (name = dumps->get_dump_file_name (i)) != NULL)
-      {
-	finish_graph_dump_file (name);
-	free (name);
-      }
+    {
+      opt_pass *pass = passes->get_pass_for_id (i);
+      if (pass == NULL
+	  || !pass->graph_dump_initialized)
+	continue;
+
+      name = dumps->get_dump_file_name (i);
+      finish_graph_dump_file (name);
+      free (name);
+    }
 
   timevar_pop (TV_DUMP);
 }

Reply via email to