diff mbox

[Fortran] PR 45087 - another -fwhole-program fix

Message ID 4C508FC4.1060506@net-b.de
State New
Headers show

Commit Message

Tobias Burnus July 28, 2010, 8:15 p.m. UTC
Dear all,

here is another whole-file fix. The only remaining issues I know of are
of the type MODULE in one file, several procedures using the modules in
another file. In that case, no gsym is generated and one gets multiple
declarations for module variables and types; I think module procedures
and external procedures declared in the module (but which are not in the
second file) are also affected. Cf. PR 44945 and PR 45077.

This patch fixes the case that an external procedure is declared in a
module - but is present in the file. In this case the declaration of the
actual external procedure should be used.

Built and regtested on x86-64-linux.
OK for the trunk?

Tobias

Comments

Daniel Kraft July 29, 2010, 8:14 a.m. UTC | #1
Tobias Burnus wrote:
> Dear all,
> 
> here is another whole-file fix. The only remaining issues I know of are
> of the type MODULE in one file, several procedures using the modules in
> another file. In that case, no gsym is generated and one gets multiple
> declarations for module variables and types; I think module procedures
> and external procedures declared in the module (but which are not in the
> second file) are also affected. Cf. PR 44945 and PR 45077.
> 
> This patch fixes the case that an external procedure is declared in a
> module - but is present in the file. In this case the declaration of the
> actual external procedure should be used.
> 
> Built and regtested on x86-64-linux.
> OK for the trunk?

Yes, ok.  Thanks!

Daniel
diff mbox

Patch

2010-07-28  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45087
	* trans-decl.c (gfc_get_extern_function_decl): Correctly handle
	external procedure declarations in modules.

2010-07-28  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45087
	* gfortran.dg/whole_file_25.f90: New.
	* gfortran.dg/whole_file_26.f90: New.

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(Revision 162653)
+++ gcc/fortran/trans-decl.c	(Arbeitskopie)
@@ -1409,7 +1409,7 @@  gfc_get_extern_function_decl (gfc_symbol
   gsym =  gfc_find_gsymbol (gfc_gsym_root, sym->name);
 
   if (gfc_option.flag_whole_file
-	&& !sym->attr.use_assoc
+	&& (!sym->attr.use_assoc || sym->attr.if_source != IFSRC_DECL)
 	&& !sym->backend_decl
 	&& gsym && gsym->ns
 	&& ((gsym->type == GSYM_SUBROUTINE) || (gsym->type == GSYM_FUNCTION))
@@ -1450,12 +1450,17 @@  gfc_get_extern_function_decl (gfc_symbol
 	    }
 	}
       else
-	{
-	  sym->backend_decl = gsym->ns->proc_name->backend_decl;
-	}
+	sym->backend_decl = gsym->ns->proc_name->backend_decl;
 
       if (sym->backend_decl)
-	return sym->backend_decl;
+	{
+	  /* Avoid problems of double deallocation of the backend declaration
+	     later in gfc_trans_use_stmts; cf. PR 45087.  */
+	  if (sym->attr.if_source != IFSRC_DECL && sym->attr.use_assoc)
+	    sym->attr.use_assoc = 0;
+
+	  return sym->backend_decl;
+	}
     }
 
   /* See if this is a module procedure from the same file.  If so,
Index: gcc/testsuite/gfortran.dg/whole_file_26.f90
===================================================================
--- gcc/testsuite/gfortran.dg/whole_file_26.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/whole_file_26.f90	(Revision 0)
@@ -0,0 +1,26 @@ 
+! { dg-do compile }
+! { dg-options "-fwhole-program  --param ggc-min-expand=0 --param ggc-min-heapsize=0" }
+!
+! PR fortran/45087
+!
+
+module INTS
+  interface
+    subroutine NEXT
+    end subroutine NEXT
+    subroutine VALUE()
+    end subroutine VALUE
+  end interface
+end module INTS
+
+subroutine NEXT
+end subroutine NEXT
+
+subroutine VALUE()
+  use INTS, only: NEXT
+  CALL NEXT
+end subroutine VALUE
+
+end
+
+! { dg-final { cleanup-modules "ints" } }
Index: gcc/testsuite/gfortran.dg/whole_file_25.f90
===================================================================
--- gcc/testsuite/gfortran.dg/whole_file_25.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/whole_file_25.f90	(Revision 0)
@@ -0,0 +1,21 @@ 
+! { dg-do compile }
+! { dg-options "-fwhole-program" }
+!
+! PR fortran/45087
+!
+
+module ints
+   INTERFACE
+      SUBROUTINE NOZZLE()
+      END SUBROUTINE NOZZLE
+   END INTERFACE
+end module ints
+
+      SUBROUTINE NOZZLE()
+      END SUBROUTINE NOZZLE
+      program CORTESA 
+      USE INTS
+      CALL NOZZLE ()
+      END program CORTESA
+
+! { dg-final { cleanup-modules "ints" } }