public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* don't access cfun in dump_function_to_file
@ 2021-07-28  7:22 Alexandre Oliva
  2021-07-28 12:33 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2021-07-28  7:22 UTC (permalink / raw)
  To: gcc-patches


dump_function_to_file takes the function to dump as a parameter, and
parts of it use the local fun variable where cfun would be used
elsewhere.  Others use cfun, presumably in error.  Fixed to use fun
uniformly.  Added a few more tests for non-NULL fun before
dereferencing it.

Regstrapped on x86_64-linux-gnu.  Ok to install?


for  gcc/ChangeLog

	* tree-cfg.c (dump_function_to_file): Use fun, not cfun.
---
 gcc/tree-cfg.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 30b1b56293e3b..38269a27b7978 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -8074,9 +8074,9 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 	       : (fun->curr_properties & PROP_cfg) ? "cfg"
 	       : "");
 
-      if (cfun->cfg)
+      if (fun && fun->cfg)
 	{
-	  basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
+	  basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (fun);
 	  if (bb->count.initialized_p ())
 	    fprintf (file, ",%s(%" PRIu64 ")",
 		     profile_quality_as_string (bb->count.quality ()),
@@ -8162,8 +8162,8 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 
       tree name;
 
-      if (gimple_in_ssa_p (cfun))
-	FOR_EACH_SSA_NAME (ix, name, cfun)
+      if (gimple_in_ssa_p (fun))
+	FOR_EACH_SSA_NAME (ix, name, fun)
 	  {
 	    if (!SSA_NAME_VAR (name)
 		/* SSA name with decls without a name still get
@@ -8199,7 +8199,7 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
 
       fprintf (file, "}\n");
     }
-  else if (fun->curr_properties & PROP_gimple_any)
+  else if (fun && (fun->curr_properties & PROP_gimple_any))
     {
       /* The function is now in GIMPLE form but the CFG has not been
 	 built yet.  Emit the single sequence of GIMPLE statements

-- 
Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
   Free Software Activist                       GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about <https://stallmansupport.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: don't access cfun in dump_function_to_file
  2021-07-28  7:22 don't access cfun in dump_function_to_file Alexandre Oliva
@ 2021-07-28 12:33 ` Richard Biener
  2021-08-17 11:05   ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2021-07-28 12:33 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: GCC Patches

On Wed, Jul 28, 2021 at 10:12 AM Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> dump_function_to_file takes the function to dump as a parameter, and
> parts of it use the local fun variable where cfun would be used
> elsewhere.  Others use cfun, presumably in error.  Fixed to use fun
> uniformly.  Added a few more tests for non-NULL fun before
> dereferencing it.
>
> Regstrapped on x86_64-linux-gnu.  Ok to install?

OK.

Richard.

>
> for  gcc/ChangeLog
>
>         * tree-cfg.c (dump_function_to_file): Use fun, not cfun.
> ---
>  gcc/tree-cfg.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> index 30b1b56293e3b..38269a27b7978 100644
> --- a/gcc/tree-cfg.c
> +++ b/gcc/tree-cfg.c
> @@ -8074,9 +8074,9 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
>                : (fun->curr_properties & PROP_cfg) ? "cfg"
>                : "");
>
> -      if (cfun->cfg)
> +      if (fun && fun->cfg)
>         {
> -         basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
> +         basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (fun);
>           if (bb->count.initialized_p ())
>             fprintf (file, ",%s(%" PRIu64 ")",
>                      profile_quality_as_string (bb->count.quality ()),
> @@ -8162,8 +8162,8 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
>
>        tree name;
>
> -      if (gimple_in_ssa_p (cfun))
> -       FOR_EACH_SSA_NAME (ix, name, cfun)
> +      if (gimple_in_ssa_p (fun))
> +       FOR_EACH_SSA_NAME (ix, name, fun)
>           {
>             if (!SSA_NAME_VAR (name)
>                 /* SSA name with decls without a name still get
> @@ -8199,7 +8199,7 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
>
>        fprintf (file, "}\n");
>      }
> -  else if (fun->curr_properties & PROP_gimple_any)
> +  else if (fun && (fun->curr_properties & PROP_gimple_any))
>      {
>        /* The function is now in GIMPLE form but the CFG has not been
>          built yet.  Emit the single sequence of GIMPLE statements
>
> --
> Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
>    Free Software Activist                       GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts.  Ask me about <https://stallmansupport.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: don't access cfun in dump_function_to_file
  2021-07-28 12:33 ` Richard Biener
@ 2021-08-17 11:05   ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2021-08-17 11:05 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On Jul 28, 2021, Richard Biener <richard.guenther@gmail.com> wrote:

> OK.

Thanks, I've finally put this in as well.

>> * tree-cfg.c (dump_function_to_file): Use fun, not cfun.

-- 
Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
   Free Software Activist                       GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about <https://stallmansupport.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-17 11:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28  7:22 don't access cfun in dump_function_to_file Alexandre Oliva
2021-07-28 12:33 ` Richard Biener
2021-08-17 11:05   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).