]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/57987 (Fortran finalizers considered extern-inline by middle-end)
authorMartin Jambor <mjambor@suse.cz>
Tue, 6 Aug 2013 12:48:53 +0000 (14:48 +0200)
committerMartin Jambor <jamborm@gcc.gnu.org>
Tue, 6 Aug 2013 12:48:53 +0000 (14:48 +0200)
2013-08-06  Martin Jambor  <mjambor@suse.cz>

PR fortran/57987
* cgraphunit.c (cgraph_finalize_function): Assert that nested function
is not re-finalized.  Rename second parameter to no_collect.

fortran/
* trans-decl.c (gfc_generate_function_code): Never call
cgraph_finalize_function on nested functions.

testsuite/
* gfortran.dg/pr57987.f90: New test.

From-SVN: r201526

gcc/ChangeLog
gcc/cgraphunit.c
gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr57987.f90 [new file with mode: 0644]

index 6274c8bd56453af65c8b051df9cf1870d41dd1e4..a28af116a7e062e9222530b26482c262f0715e11 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-06  Martin Jambor  <mjambor@suse.cz>
+
+       PR fortran/57987
+       * cgraphunit.c (cgraph_finalize_function): Assert that nested function
+       is not re-finalized.  Rename second parameter to no_collect.
+
 2013-08-06  Martin Jambor  <mjambor@suse.cz>
 
        PR middle-end/58041
index ad91117d6b1c7f56ada64c4e8d99a24ee0587abb..cf92b1d658aa16f003584abc704c900aa9e17419 100644 (file)
@@ -404,17 +404,20 @@ referred_to_p (symtab_node node)
 }
 
 /* DECL has been parsed.  Take it, queue it, compile it at the whim of the
-   logic in effect.  If NESTED is true, then our caller cannot stand to have
+   logic in effect.  If NO_COLLECT is true, then our caller cannot stand to have
    the garbage collector run at the moment.  We would need to either create
    a new GC context, or just not compile right now.  */
 
 void
-cgraph_finalize_function (tree decl, bool nested)
+cgraph_finalize_function (tree decl, bool no_collect)
 {
   struct cgraph_node *node = cgraph_get_create_node (decl);
 
   if (node->symbol.definition)
     {
+      /* Nested functions should only be defined once.  */
+      gcc_assert (!DECL_CONTEXT (decl)
+                 || TREE_CODE (DECL_CONTEXT (decl)) != FUNCTION_DECL);
       cgraph_reset_node (node);
       node->local.redefined_extern_inline = true;
     }
@@ -453,7 +456,7 @@ cgraph_finalize_function (tree decl, bool nested)
   if (warn_unused_parameter)
     do_warn_unused_parameter (decl);
 
-  if (!nested)
+  if (!no_collect)
     ggc_collect ();
 
   if (cgraph_state == CGRAPH_STATE_CONSTRUCTION
index 7a9fe6ef8bd3cc7cf16bd401dc4e4a21f3e7b437..bcd91a928971ef2128fc69a8aa362df20ba6b1ef 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-06  Martin Jambor  <mjambor@suse.cz>
+
+       PR fortran/57987
+       * trans-decl.c (gfc_generate_function_code): Never call
+       cgraph_finalize_function on nested functions.
+
 2013-08-06  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/57306
index 43f401d83d4e71190b7fb81d2ce406270197bfd7..1708931660241315e029bfe6f7e62470e0e8a4d3 100644 (file)
@@ -5643,14 +5643,16 @@ gfc_generate_function_code (gfc_namespace * ns)
     }
   current_function_decl = old_context;
 
-  if (decl_function_context (fndecl) && gfc_option.coarray != GFC_FCOARRAY_LIB
-      && has_coarray_vars)
-    /* Register this function with cgraph just far enough to get it
-       added to our parent's nested function list.
-       If there are static coarrays in this function, the nested _caf_init
-       function has already called cgraph_create_node, which also created
-       the cgraph node for this function.  */
-    (void) cgraph_create_node (fndecl);
+  if (decl_function_context (fndecl))
+    {
+      /* Register this function with cgraph just far enough to get it
+        added to our parent's nested function list.
+        If there are static coarrays in this function, the nested _caf_init
+        function has already called cgraph_create_node, which also created
+        the cgraph node for this function.  */
+      if (!has_coarray_vars || gfc_option.coarray != GFC_FCOARRAY_LIB)
+       (void) cgraph_create_node (fndecl);
+    }
   else
     cgraph_finalize_function (fndecl, true);
 
index 790c5568cdc23df765bd3539e4190b5348f54667..c81ec3f9199379b7a21738cef16a00adb342ff92 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-06  Martin Jambor  <mjambor@suse.cz>
+
+       PR fortran/57987
+       * gfortran.dg/pr57987.f90: New test.
+
 2013-08-06  Martin Jambor  <mjambor@suse.cz>
 
        PR middle-end/58041
diff --git a/gcc/testsuite/gfortran.dg/pr57987.f90 b/gcc/testsuite/gfortran.dg/pr57987.f90
new file mode 100644 (file)
index 0000000..c881e6d
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline" }
+
+program test
+  call test2 ()
+contains
+  subroutine test2 ()
+    type t
+      integer, allocatable :: x
+    end type t
+
+    type t2
+      class(t), allocatable :: a
+    end type t2
+
+    type(t2) :: one, two
+
+    allocate (two%a)
+    one = two
+  end subroutine test2
+end program test
+
+! { dg-final { scan-ipa-dump-not "redefined extern inline functions are not considered for inlining" "inline" } }
+! { dg-final { cleanup-ipa-dump "inline" } }