https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70161

--- Comment #3 from vries at gcc dot gnu.org ---
(In reply to Richard Biener from comment #2)
> Hum, what does it do if only guarding the !pass->graph_dump_initialized
> check?

That fixes the segfault, but we run into another segfault with -fipa-pta (which
calls cgraph_node::get_body), due to dump_file_name being NULL. This patch
fixes that:
...
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 7727313..f187913 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -3365,7 +3365,9 @@ cgraph_node::get_body (void)
     {
       opt_pass *saved_current_pass = current_pass;
       FILE *saved_dump_file = dump_file;
+      const char *saved_dump_file_name = dump_file_name;
       int saved_dump_flags = dump_flags;
+      dump_file_name = NULL;

       push_cfun (DECL_STRUCT_FUNCTION (decl));
       execute_all_ipa_transforms ();
@@ -3377,6 +3379,7 @@ cgraph_node::get_body (void)

       current_pass = saved_current_pass;
       dump_file = saved_dump_file;
+      dump_file_name = saved_dump_file_name;
       dump_flags = saved_dump_flags;
     }
   return updated;
...

However, looking at test.c.074i.inline.dot, we see that the graph has
duplicated edges. This seems an issue that also occcurs for normal dump files:
a simple-ipa pass dumps at execute, and an ipa pass dumps at execute and at
transform. AFAIU, an ipa pass does not do transforms at execute, so that dump
seems superfluous. This patch fixes that:
...
diff --git a/gcc/passes.c b/gcc/passes.c
index 8206463..2865033 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -2352,8 +2352,6 @@ execute_one_pass (opt_pass *pass)
     check_profile_consistency (pass->static_pass_number, 1, true);

   verify_interpass_invariants ();
-  if (dump_file)
-    do_per_function (execute_function_dump, pass);
   if (pass->type == IPA_PASS)
     {
       struct cgraph_node *node;
@@ -2361,6 +2359,8 @@ execute_one_pass (opt_pass *pass)
        FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
          node->ipa_transforms_to_apply.safe_push ((ipa_opt_pass_d *)pass);
     }
+  else if (dump_file)
+    do_per_function (execute_function_dump, pass);

   if (!current_function_decl)
     symtab->process_new_functions ();
...

And then we run into:
- the ipa variant of PR70185.
- other errors:
  Warning: inline.c.070i.cp.dot: syntax error in line 1 near 'subgraph'
  Warning: inline.c.074i.inline.dot: syntax error in line 1 near 'subgraph'

The first can be fixed with the tentative fix for the PR.
The second by using a different (and simpler) fix for the original sigsegv:
...
diff --git a/gcc/passes.c b/gcc/passes.c
index bbe35b3..ad49d12 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -2219,7 +2219,7 @@ execute_one_ipa_transform_pass (struct cgraph_node *node,
     check_profile_consistency (pass->static_pass_number, 1, true);

   if (dump_file)
-    do_per_function (execute_function_dump, NULL);
+    do_per_function (execute_function_dump, pass);
   pass_fini_dump_file (pass);

   current_pass = NULL;
...
[ Btw, the 'do_per_function (execute_function_dump, pass)' is equivalent to
'execute_function_dump (cfun, pass)'. ]

> Otherwise your patch is equivalent to removing the
> 
>   if (dump_file)
>     do_per_function (execute_function_dump, NULL);
> 
> call from execute_one_ipa_transform_pass, no?

Not equivalent, since removing that call also removes the normal dump.

> That is, no graph dumps from
> IPA passes?

Indeed, the original pass skipped dot graph dumps from ipa transforms (but
still dumped after execute).


I'll attach the updated tentative patch.

Reply via email to