Dear All,
The attached patch fixes a memory leak, prevents writing of smod
files, when there are no submodules and adds a paragraph to the
gfortran documentation on submodules.
After this, PR66762, which is the -flto problem, is the last one to
sort out in order to complete the implementation of submodules.
Bootstraps and regtests on FC21/x86_64 - OK for trunk?
I will apply the patch tomorrow morning if there are no objections.
Cheers
Paul
2015-09-16 Paul Thomas <[email protected]>
PR fortran/52846
PR fortran/67588
* module.c : Add static no_module_procedures.
(gfc_match_submodule): Correct memory leakage caused during the
freeing of use_lists.
(mio_symbol_attribute): Reset above if module procedure is
encountered.
(gfc_dump_module): Set above and exit without writing smod file
if it reset.
* gfortran.texi : Add section on submodule support.
2015-09-16 Paul Thomas <[email protected]>
PR fortran/52846
* gfortran.dg/public_private_module_5.f90: Add module procedure
trigger_smod to ensure that the smod file is written.
Index: /home/pault/svn/trunk/gcc/fortran/module.c
===================================================================
*** /home/pault/svn/trunk/gcc/fortran/module.c (revision 227818)
--- /home/pault/svn/trunk/gcc/fortran/module.c (working copy)
*************** static gzFile module_fp;
*** 193,198 ****
--- 193,203 ----
static const char *module_name;
/* The name of the .smod file that the submodule will write to. */
static const char *submodule_name;
+
+ /* Suppress the output of a .smod file by module, if no module
+ procedures have been seen. */
+ static bool no_module_procedures;
+
static gfc_use_list *module_list;
/* If we're reading an intrinsic module, this is its ID. */
*************** gfc_match_submodule (void)
*** 798,804 ****
/* Just retain the ultimate .(s)mod file for reading, since it
contains all the information in its ancestors. */
use_list = module_list;
! for (; module_list->next; use_list = use_list->next)
{
module_list = use_list->next;
free (use_list);
--- 803,809 ----
/* Just retain the ultimate .(s)mod file for reading, since it
contains all the information in its ancestors. */
use_list = module_list;
! for (; module_list->next; use_list = module_list)
{
module_list = use_list->next;
free (use_list);
*************** mio_symbol_attribute (symbol_attribute *
*** 2222,2228 ****
--- 2227,2236 ----
if (attr->array_outer_dependency)
MIO_NAME (ab_attribute) (AB_ARRAY_OUTER_DEPENDENCY, attr_bits);
if (attr->module_procedure)
+ {
MIO_NAME (ab_attribute) (AB_MODULE_PROCEDURE, attr_bits);
+ no_module_procedures = false;
+ }
mio_rparen ();
*************** gfc_dump_module (const char *name, int d
*** 6081,6089 ****
else
dump_smod =false;
dump_module (name, dump_flag);
! if (dump_smod)
return;
/* Write a submodule file from a module. The 'dump_smod' flag switches
--- 6089,6098 ----
else
dump_smod =false;
+ no_module_procedures = true;
dump_module (name, dump_flag);
! if (no_module_procedures || dump_smod)
return;
/* Write a submodule file from a module. The 'dump_smod' flag switches
Index: /home/pault/svn/trunk/gcc/fortran/gfortran.texi
===================================================================
*** /home/pault/svn/trunk/gcc/fortran/gfortran.texi (revision 227818)
--- /home/pault/svn/trunk/gcc/fortran/gfortran.texi (working copy)
*************** of @code{ISO_FORTRAN_ENV}.
*** 1047,1052 ****
--- 1047,1060 ----
and experimental support for multiple images with the @option{-fcoarray=lib}
flag.
+ @item Submodules are supported. It should noted that @code{MODULEs} do not
+ produce the smod file needed by the descendent @code{SUBMODULEs} unless they
+ contain at least one @code{MODULE PROCEDURE} interface. The reason for this is
+ that @code{SUBMODULEs} are useless without @code{MODULE PROCEDUREs}. See
+ http://j3-fortran.org/doc/meeting/207/15-209.txt for a discussion and a draft
+ interpretation. Adopting this interpretation has the advantage that code that
+ does not use submodules does not generate smod files.
+
@item The @code{DO CONCURRENT} construct is supported.
@item The @code{BLOCK} construct is supported.
Index: /home/pault/svn/trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
===================================================================
*** /home/pault/svn/trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
(revision 227818)
--- /home/pault/svn/trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
(working copy)
*************** module foo_interface
*** 10,15 ****
--- 10,23 ----
type foo
character(len=16), private :: byebye = "adieu, world! "
end type foo
+
+ ! This interface is required to trigger the output of an .smod file.
+ ! See http://j3-fortran.org/doc/meeting/207/15-209.txt
+ interface
+ integer module function trigger_smod ()
+ end function
+ end interface
+
end module
module foo_interface_brother