[debug-early] fix fortran regressions
diff mbox

Message ID 54245ABF.8070708@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Sept. 25, 2014, 6:11 p.m. UTC
push_cfun() fails when there's no cfun stack.  With this patch, we use 
set_cfun if not stack is available.

This fixes the 16 Fortran guality regressions.

Now guality tests all pass, for all languages.

Committed to branch.
commit a6f19a625bc6f662db6f23679503458f22721de9
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Sep 22 10:37:16 2014 -0600

    	* dwarf2out.c (dwarf2out_early_global_decl): Set cfun correctly
    	even if cfun stack is empty.

Comments

Richard Biener Sept. 26, 2014, 8:29 a.m. UTC | #1
On Thu, Sep 25, 2014 at 8:11 PM, Aldy Hernandez <aldyh@redhat.com> wrote:
> push_cfun() fails when there's no cfun stack.  With this patch, we use
> set_cfun if not stack is available.
>
> This fixes the 16 Fortran guality regressions.
>
> Now guality tests all pass, for all languages.
>
> Committed to branch.

Hmm, I'd rather avoid push_cfun completely.  It seems that mainline
doesn't have it?  Note that push_cfun also does target specific
switching which shouldn't be necessary.

Eventually dwarf2out.c wants some own "context"?

That is, the type/decl part of dwarf2out.c should work solely with
current_function_decl (which you can simply change/restore)
while the backend part (locations, etc.) should work using cfun.

So - please try dropping push_cfun as you set current_function_decl
anyway.

Richard.

Patch
diff mbox

diff --git a/gcc/ChangeLog.debug-early b/gcc/ChangeLog.debug-early
index a6b9e0a..f8b1880 100644
--- a/gcc/ChangeLog.debug-early
+++ b/gcc/ChangeLog.debug-early
@@ -1,3 +1,8 @@ 
+2014-09-22  Aldy Hernandez  <aldyh@redhat.com>
+
+	* dwarf2out.c (dwarf2out_early_global_decl): Set cfun correctly
+	even if cfun stack is empty.
+
 2014-09-19  Aldy Hernandez  <aldyh@redhat.com>
 
 	* dwarf2out.c (gen_subprogram_die): Remove DW_AT_declaration even
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 48b1106..0519839 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20844,6 +20844,7 @@  dwarf2out_early_global_decl (tree decl)
   bool save = symtab->global_info_ready;
   symtab->global_info_ready = true;
 
+  bool fndecl_was_null = false;
   /* We don't handle TYPE_DECLs.  If required, they'll be reached via
      other DECLs and they can point to template types or other things
      that dwarf2out can't handle when done via dwarf2out_decl.  */
@@ -20857,7 +20858,13 @@  dwarf2out_early_global_decl (tree decl)
 	  if (!DECL_STRUCT_FUNCTION (decl))
 	    goto early_decl_exit;
 
-	  push_cfun (DECL_STRUCT_FUNCTION (decl));
+	  if (current_function_decl)
+	    push_cfun (DECL_STRUCT_FUNCTION (decl));
+	  else
+	    {
+	      set_cfun (DECL_STRUCT_FUNCTION (decl));
+	      fndecl_was_null = true;
+	    }
 	  current_function_decl = decl;
 	}
       dw_die_ref die = dwarf2out_decl (decl);
@@ -20865,7 +20872,10 @@  dwarf2out_early_global_decl (tree decl)
 	die->dumped_early = true;
       if (TREE_CODE (decl) == FUNCTION_DECL)
 	{
-	  pop_cfun ();
+	  if (fndecl_was_null)
+	    set_cfun (NULL);
+	  else
+	    pop_cfun ();
 	  current_function_decl = NULL;
 	}
     }