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 <al...@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.

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  <al...@redhat.com>
+
+       * dwarf2out.c (dwarf2out_early_global_decl): Set cfun correctly
+       even if cfun stack is empty.
+
 2014-09-19  Aldy Hernandez  <al...@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;
        }
     }

Reply via email to