User account creation filtered due to spam.

Bug 52846 - [F2008] Support submodules
Summary: [F2008] Support submodules
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords:
Depends on: 66762
Blocks: 39627
  Show dependency treegraph
 
Reported: 2012-04-03 14:59 UTC by Tobias Burnus
Modified: 2015-10-18 10:57 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-21 00:00:00


Attachments
draft patch (6.91 KB, patch)
2015-06-14 19:47 UTC, Paul Thomas
Details | Diff
A partially cooked patch to complete the implentation of submodules (2.68 KB, patch)
2015-07-07 21:13 UTC, Paul Thomas
Details | Diff
test case (954 bytes, text/plain)
2015-07-16 12:58 UTC, Salvatore Filippone
Details
test case (940 bytes, text/plain)
2015-07-16 13:22 UTC, Salvatore Filippone
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-04-03 14:59:17 UTC
Fortran 2008 added submodules support.

That's a tracker bug with the main intention to add a link to the following bugs. Those contain a change which won't work with submodules. Thus, some special submodule check has to be inserted for PR 52751 and PR 40973.
Comment 1 Dominique d'Humieres 2014-12-21 15:31:11 UTC
What is the purpose of this PR? To remind that submodules are not yet supported and/or that the commits for PR 52751 and PR 40973 will have to be updated when submodules will be supported?

In the latter case could you elaborate?
Comment 2 Paul Thomas 2015-06-14 19:46:33 UTC
Dear Dominique and Tobias,

Whatever is the purpose of this PR, I will use it to hang my hat on :-) I have a submodule patch nearly ready to go.

My plan is to submit next Saturday.

Cheers

Paul
Comment 3 Paul Thomas 2015-06-14 19:47:34 UTC
Created attachment 35779 [details]
draft patch
Comment 4 Paul Thomas 2015-06-14 19:48:27 UTC
Testcase:

! Test vehicle for submodules
! 14th June 2015
!
! Paul Thomas - check1406b.diff applies
!
! FIXED OR MOSTLY FIXED:
! Access in submodules to PROCEDURE COMPONENTS - FIXED 06/06/2015
! MODULE FUNCTIONS - partially FIXED 10/06/15 - syntax errors give difficult to understand messages
! Salvatore's submodbug fixed 10/06/15 - module variable must remain use associated
! Name mangling of MODULE PROCEDUREs - FIXED 13/06
! Parsing of SUBMODULE (module:parent_submodule:.....) - already worked(!) tested 14/06
! Checking characteristics between interface and submodule declaration - FIXED 14/06
!
! TODOs:
! Clean up and comment all the new code (Partially done 14/06)
! Prepare testcases for testsuite
! Constraints as delineated in N1602.pdf or F2008 standard (will have to check what is left!)
! Restricting output of .mod file from submodules to local symbols, etc. only (not essential)
! Prepare ChangeLogs
! Submit :-)
!
 module foo_interface
   implicit none

   type foo
     character(len=15) :: greeting = "Hello, world!  "
   contains
     procedure :: greet => say_hello
     procedure :: farewell => bye
   end type foo

   interface
     module subroutine say_hello(this)
       import foo
       class(foo), intent(in) :: this
     end subroutine
     module subroutine bye(this)
       import foo
       class(foo), intent(in) :: this
     end subroutine
     module function realf (arg) result (res)
       real :: arg, res
     end function
     integer module function intf (arg)
       integer :: arg
     end function
     real module function realg (arg)
       real :: arg
     end function
     integer module function intg (arg)
       integer :: arg
     end function
   end interface
 contains
   subroutine smurf
     class(foo), allocatable :: this
     allocate (this)
     print *, "say_hello from SMURF --->"
! Test that say_hello is effectively host associated
     call say_hello (this)
   end subroutine
 end module

!_________________________________________________________________________________!
  SUBMODULE (foo_interface) foo_interface_son
!
  contains
! Test module procedure with conventional specification part for dummies
     module subroutine say_hello(this)
       class(foo), intent(in) :: this
       class(foo), allocatable :: that
       allocate (that, source = this)
! Test that components of foo are accessible
       print *, "(say_hello)", that%greeting
!       call this%farewell         ! NOTE WELL: This compiles and causes a crash in run-time
!                                               due to recursion through the call to this procedure from
!                                               say hello.
     end subroutine
     module function realf (arg) result (res)
       real :: arg, res
       res = 2*arg
     end function
  end SUBMODULE foo_interface_son

!_________________________________________________________________________________!
! Check that multiple generations of submodules are OK
  SUBMODULE (foo_interface:foo_interface_son) foo_interface_grandson
!
  contains
     integer module function intf (arg)
       integer :: arg
       intf = 2*arg
     end function
  end SUBMODULE foo_interface_grandson

!_________________________________________________________________________________!
  SUBMODULE (foo_interface) foo_interface_daughter
!
  contains
! Test module procedure with abbreviated declaration and no specification of dummies
     module procedure bye
! Verify the derived type foo is accessible - had problems with this because if_source != IFSRC_DECL
       class(foo), allocatable :: that
       print *, "(bye) ", this%greeting
       print *, "say_hello from BYE --->"
       call say_hello (this)
       allocate (that, source = this)
! Test that components of foo are accessible
       print *, "(bye)", that%greeting
       print *, "call that%greet from BYE --->"
       call that%greet
     end subroutine
     module procedure intg
       intg = 3*arg
     end function
     module procedure realg
       realg = 3*arg
     end function
  end SUBMODULE foo_interface_daughter

!_________________________________________________________________________________!
 program try
   use foo_interface
   implicit none
   type(foo) :: bar
   call bar%greet ! typebound call

!   Unnecessary tests at present
!   bar%greeting = "Goodbye, world!"
!   call bar%greet ! typebound call with changed message

   print *, "say_hello from TRY --->"
   call say_hello(bar) ! Checks use association of 'say_hello'
   call bye(bar) ! Checks use association in another submodule
   call smurf ! Checks host association of 'say_hello'
   bar%greeting = "farewell     "
   call bar%farewell
   print *, realf(2.0) ! Check module procedure with explicit result
   print *, intf(2)    ! ditto
   print *, realg(3.0) ! Check module procedure with function declaration result
   print *, intg(3)    ! ditto
 end program
!_________________________________________________________________________________!
Comment 5 Paul Thomas 2015-07-02 20:40:28 UTC
Author: pault
Date: Thu Jul  2 20:39:56 2015
New Revision: 225354

URL: https://gcc.gnu.org/viewcvs?rev=225354&root=gcc&view=rev
Log:
2015-07-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (get_proc_name): Make a partially populated interface
	symbol to carry the characteristics of a module procedure and
	its result.
	(variable_decl): Declarations of dummies or results in the
	abreviated form of module procedure is an error.
	(gfc_match_import): IMPORT is not permitted in the interface
	declaration of module procedures.
	(match_attr_spec): Submodule variables have implicit save
	attribute for F2008 onwards.
	(gfc_match_prefix): Add 'module' as the a prefix and set the
	module_procedure attribute.
	(gfc_match_formal_arglist): For a module procedure keep the
	interface formal_arglist from the interface, match new the
	formal arguments and then compare the number and names of each.
	(gfc_match_procedure): Add case COMP_SUBMODULE.
	(gfc_match_function_decl, gfc_match_subroutine_decl): Set the
	module_procedure attribute.
	(gfc_match_entry, gfc_match_end):  Add case COMP_SUBMODULE. If
	attr abr_modproc_decl is set, switch the message accordingly
	for subroutines and functions.
	(gfc_match_submod_proc): New function to match the abbreviated
	style of submodule declaration.
	* gfortran.h : Add ST_SUBMODULE and ST_END_SUBMODULE. Add the
	attribute bits 'used_in_submodule' and 'module_procedure'. Add
	the bit field 'abr_modproc_decl' to gfc_symbol. Add prototypes
	for 'gfc_copy_dummy_sym', 'gfc_check_dummy_characteristics' and
	'gfc_check_result_characteristics'.
	* interface.c : Add the prefix 'gfc_' to the names of functions
	'check_dummy(result)_characteristics' and all their references.
	* match.h : Add prototype for 'gfc_match_submod_proc' and
	'gfc_match_submodule'.
	(check_sym_interfaces): A module procedure is not an error in
	a module procedure statment in a generic interface.
	* module.c (gfc_match_submodule): New function. Add handling
	for the 'module_procedure' attribute bit.
	(gfc_use_module): Make sure that a submodule cannot use itself.
	* parse.c (decode_statement): Set attr has_'import_set' for
	the interface declaration of module procedures. Handle a match
	occurring in 'gfc_match_submod_proc' and a match for
	'submodule'.
	(gfc_enclosing_unit): Include the state COMP_SUBMODULE.
	(gfc_ascii_statement): Add END SUBMODULE.
	(accept_statement): Add ST_SUBMODULE.
	(parse_spec): Disallow statement functions in a submodule
	specification part.
	(parse_contained): Add ST_END_SUBMODULE and COMP_SUBMODULE
	twice each.
	(get_modproc_result): Copy the result symbol of the interface.
	(parse_progunit): Call it.
	(set_syms_host_assoc): Make symbols from the ancestor module
	and submodules use associated, as required by the standard and
	set all private components public. Module procedures 'external'
	attribute bit is reset and the 'used_in_submodule' bit is set.
	(parse_module): If this is a submodule, use the ancestor module
	and submodules. Traverse the namespace, calling
	'set_syms_host_assoc'. Add ST_END_SUBMODULE and COMP_SUBMODULE.
	* parse.h : Add COMP_SUBMODULE.
	* primary.c (match_variable): Add COMP_SUBMODULE.
	* resolve.c (compare_fsyms): New function to compare the dummy
	characteristics of a module procedure with its interface.
	(resolve_fl_procedure): Compare the procedure, result and dummy
	characteristics of a module_procedure with its interface, using
	'compare_fsyms' for the dummy arguments.
	* symbol.c (gfc_add_procedure): Suppress the check for existing
	procedures in the case of a module procedure.
	(gfc_add_explicit_interface): Skip checks that must fail for
	module procedures.
	(gfc_add_type): Allow a new type to be added to module
	procedures, their results or their dummy arguments.
	(gfc_copy_dummy_sym): New function to generate new dummy args
	and copy the characteristics from the interface.
	* trans-decl.c (gfc_sym_mangled_function_id): Module procedures
	must always have their names mangled as if they are symbols
	coming from a declaration in a module.
	(gfc_get_symbol_decl): Add 'used_in_submodule' to the assert.
	(gfc_finish_var_decl): Symbols with the 'used_in_submodule' bit
	set are set DECL_EXTERNAL as if they were use associated.

2015-07-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* gfortran.dg/submodule_1.f90: New test
	* gfortran.dg/submodule_2.f90: New test
	* gfortran.dg/submodule_3.f90: New test
	* gfortran.dg/submodule_4.f90: New test
	* gfortran.dg/submodule_5.f90: New test
	* gfortran.dg/submodule_6.f90: New test
	* gfortran.dg/submodule_7.f90: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_1.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_2.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_3.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_4.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_5.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_6.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/parse.h
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Paul Thomas 2015-07-03 19:00:39 UTC
I have yet to sort out private symbols before I close this PR. It will take some days to conclude because of the issues discussed on the list.

I'm on to it!

Paul
Comment 7 Paul Thomas 2015-07-07 21:13:15 UTC
Created attachment 35926 [details]
A partially cooked patch to complete the implentation of submodules

The attached is a first attempt to complete the submodule implementation such that private entities are correctly dealt with.

There are two parts to the patch:

(i) Modifications to the front end to write a second half to the module files, which contains all the information about the private entities in the module. This is the bulk of the patch; and

(ii) A change in the way that declarations of private entities are handled in trans-decl.c. This follows a suggestion from Richard Biener to use a technique borrowed from g++. In this patch it is only applied to variables.

Concerning (i), I am open to opinions as to whether or not it is better to write the private parts to a separate file. At present, anything other than a submodule does not visit the private part of the module file. Mention was made on the list of encrypting this part of the file. Unfortunately, this overwhelms the compression and module files remain rather large. This might be a strong argument for emitting two files; one for the public part, as at present, and the other for the private. In this way, a build could result in a library that is only propagated with the public module file.

In respect of (ii), I have checked that the map shows no signs of the private variables and that the library only carries their names.

A typical, basic makefile might look like this:

# Build submodule_8
#
submodule_8 : submodule_8_prog.o submodule_8_lib.so
	~/irun/bin/gfortran -O3 submodule_8_prog.o submodule_8_lib.so -o submodule_8
#
submodule_8_prog.o : submodule_8_prog.f90
	~/irun/bin/gfortran -O3 -c submodule_8_prog.f90 -o submodule_8_prog.o
#
submodule_8_lib.so : submodule_8_lib1.o submodule_8_lib2.o
	~/irun/bin/gfortran -O3 -shared submodule_8_lib1.o submodule_8_lib2.o -o submodule_8_lib.so
#
# Relocation runs into problems without -fPIC for both of these compilations.
#
submodule_8_lib1.o : submodule_8_lib1.f90
	~/irun/bin/gfortran -O3 -fPIC -c submodule_8_lib1.f90 -o submodule_8_lib1.o
#
submodule_8_lib2.o : submodule_8_lib2.f90
	~/irun/bin/gfortran -O3 -fPIC -c submodule_8_lib2.f90 -o submodule_8_lib2.o

In this tested case, ~lib1 contains two modules and ~lib2 the submodules. Some of the entities in ~lib1 are private but they are correctly propagated to ~lib2 but not to the program, ~prog.

Cheers

Paul
Comment 8 Salvatore Filippone 2015-07-13 15:44:11 UTC
(In reply to Paul Thomas from comment #7)
> Created attachment 35926 [details]
> A partially cooked patch to complete the implentation of submodules
> 
> The attached is a first attempt to complete the submodule implementation
> such that private entities are correctly dealt with.
> 
> There are two parts to the patch:
> 
> (i) Modifications to the front end to write a second half to the module
> files, which contains all the information about the private entities in the
> module. This is the bulk of the patch; and
> 
> (ii) A change in the way that declarations of private entities are handled
> in trans-decl.c. This follows a suggestion from Richard Biener to use a
> technique borrowed from g++. In this patch it is only applied to variables.
> ............
> Cheers
> 
> Paul

Seems to work for my codes.

I am not completely happy with the fact that a change in the PRIVATE entities will cause a change of the .mod file; it may be argued that changes are more likely to occur in the submodules than in the main module, but still, this is not 100% satisfactory wrt the advertisement that submodules are ssolving the compilation cascade problem. 
From a user's point of view, I do not see a good solution to this; if the .mod file contains any kind of timestamp, it's going to change anyway, even in the case where the PRIVATE part is written to a separate file. 

On a relate note, the point raised in the mailing list about protecting trade secrets by putting them in the PRIVATE parts is IMHO moot: if I really wanted to protect trade secrets, I would put them in a separate module that is only ever USEd by the implementation files of the user visible module, files of which I only distribute the object code. 
I don't think that C++ is any different in this respect. 

Salvatore
Comment 9 Salvatore Filippone 2015-07-14 12:44:03 UTC
(In reply to Salvatore Filippone from comment #8)
> (In reply to Paul Thomas from comment #7)
> Salvatore

Spoke too quickly: I get this linker error

ppde3d.f90:(.text+0x9d0): undefined reference to `__psb_error_mod_MOD_psb_perror'
../../lib/libpsb_prec.a(psb_dilu_fct.o): In function `psb_dilu_fct_':
psb_dilu_fct.f90:(.text+0x6a0): undefined reference to `__psb_error_mod_MOD_psb_serror'
psb_dilu_fct.f90:(.text+0x21db): undefined reference to `__psb_error_mod_MOD_psb_serror'


whereas the relevant implementation submodule shows:
0000000000000000 T __psb_error_impl_mod_MOD_psb_perror
0000000000000220 T __psb_error_impl_mod_MOD_psb_serror

i.e. the name mangling is going wrong.
Salvatore
Comment 10 paul.richard.thomas@gmail.com 2015-07-16 11:03:17 UTC
Hi Salvatore,

If you could reduce the source that produces this error for me, I
would be grateful. By the looks of it, the name mangling is
functioning correctly but is picking up the wrong program unit name.

Thanks

Paul

On 14 July 2015 at 14:44, sfilippone at uniroma2 dot it
<gcc-bugzilla@gcc.gnu.org> wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52846
>
> --- Comment #9 from Salvatore Filippone <sfilippone at uniroma2 dot it> ---
> (In reply to Salvatore Filippone from comment #8)
>> (In reply to Paul Thomas from comment #7)
>> Salvatore
>
> Spoke too quickly: I get this linker error
>
> ppde3d.f90:(.text+0x9d0): undefined reference to
> `__psb_error_mod_MOD_psb_perror'
> ../../lib/libpsb_prec.a(psb_dilu_fct.o): In function `psb_dilu_fct_':
> psb_dilu_fct.f90:(.text+0x6a0): undefined reference to
> `__psb_error_mod_MOD_psb_serror'
> psb_dilu_fct.f90:(.text+0x21db): undefined reference to
> `__psb_error_mod_MOD_psb_serror'
>
>
> whereas the relevant implementation submodule shows:
> 0000000000000000 T __psb_error_impl_mod_MOD_psb_perror
> 0000000000000220 T __psb_error_impl_mod_MOD_psb_serror
>
> i.e. the name mangling is going wrong.
> Salvatore
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
> You are the assignee for the bug.
Comment 11 Salvatore Filippone 2015-07-16 12:58:12 UTC
Created attachment 35995 [details]
test case
Comment 12 Salvatore Filippone 2015-07-16 12:58:50 UTC
(In reply to Salvatore Filippone from comment #11)
> Created attachment 35995 [details]
> test case

Enjoy :) 

[sfilippo@jacobi tlink]$ gfortran -v 
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/gnu/dev/libexec/gcc/x86_64-unknown-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-dev/configure --prefix=/opt/gnu/dev --enable-languages=c,c++,fortran --with-gmp=/home/travel/GNUBUILD/gmp --with-mpfr=/home/travel/GNUBUILD/mpfr --with-mpc=/home/travel/GNUBUILD/mpc --with-cloog=/home/travel/GNUBUILD/cloog : (reconfigured) ../gcc-dev/configure --prefix=/opt/gnu/dev --enable-languages=c,c++,fortran --with-gmp=/home/travel/GNUBUILD/gmp --with-mpfr=/home/travel/GNUBUILD/mpfr --with-mpc=/home/travel/GNUBUILD/mpc --with-cloog=/home/travel/GNUBUILD/cloog : (reconfigured) ../gcc-dev/configure --prefix=/opt/gnu/dev --with-gmp=/home/travel/GNUBUILD/gmp --with-mpfr=/home/travel/GNUBUILD/mpfr --with-mpc=/home/travel/GNUBUILD/mpc --with-cloog=/home/travel/GNUBUILD/cloog CC=gcc CXX=g++ --enable-languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
gcc version 6.0.0 20150713 (experimental) (GCC) 
[sfilippo@jacobi tlink]$ gfortran -o testlk testlk.f90 
/tmp/cchNLmkr.o: In function `__error_impl_mod_MOD_ser_error_print_stack':
testlk.f90:(.text+0x1b): undefined reference to `__error_mod_MOD_serror'
/tmp/cchNLmkr.o: In function `__error_impl_mod_MOD_par_error_print_stack':
testlk.f90:(.text+0x3b): undefined reference to `__error_mod_MOD_perror'
/tmp/cchNLmkr.o: In function `__error_mod_MOD_par_error_handler':
testlk.f90:(.text+0x5f): undefined reference to `erractionrestore_'
testlk.f90:(.text+0x7b): undefined reference to `__error_mod_MOD_perror'
testlk.f90:(.text+0x97): undefined reference to `__error_mod_MOD_perror'
/tmp/cchNLmkr.o: In function `__error_mod_MOD_ser_error_handler':
testlk.f90:(.text+0xb8): undefined reference to `erractionrestore_'
testlk.f90:(.text+0xc7): undefined reference to `__error_mod_MOD_serror'
/tmp/cchNLmkr.o: In function `MAIN__':
testlk.f90:(.text+0xfc): undefined reference to `__error_mod_MOD_serror'
collect2: error: ld returned 1 exit status
Comment 13 Salvatore Filippone 2015-07-16 13:22:31 UTC
Created attachment 35996 [details]
test case

Cleaned up a bit of noise due to the process of reducing the test case: it was spitting out a legitimate but pointless liker error about erractionrestore.

[sfilippo@jacobi tlink]$ gfortran -o testlk testlk.f90 
/tmp/ccbhv5VA.o: In function `__error_impl_mod_MOD_ser_error_print_stack':
testlk.f90:(.text+0x1b): undefined reference to `__error_mod_MOD_serror'
/tmp/ccbhv5VA.o: In function `__error_impl_mod_MOD_par_error_print_stack':
testlk.f90:(.text+0x3b): undefined reference to `__error_mod_MOD_perror'
/tmp/ccbhv5VA.o: In function `__error_mod_MOD_par_error_handler':
testlk.f90:(.text+0x6a): undefined reference to `__error_mod_MOD_perror'
testlk.f90:(.text+0x86): undefined reference to `__error_mod_MOD_perror'
/tmp/ccbhv5VA.o: In function `__error_mod_MOD_ser_error_handler':
testlk.f90:(.text+0xa5): undefined reference to `__error_mod_MOD_serror'
/tmp/ccbhv5VA.o: In function `MAIN__':
testlk.f90:(.text+0xda): undefined reference to `__error_mod_MOD_serror'
collect2: error: ld returned 1 exit status
Comment 14 Paul Thomas 2015-07-16 14:52:58 UTC
(In reply to Salvatore Filippone from comment #13)
> Created attachment 35996 [details]
> test case
> 
> Cleaned up a bit of noise due to the process of reducing the test case: it
> was spitting out a legitimate but pointless liker error about
> erractionrestore.
> 
> [sfilippo@jacobi tlink]$ gfortran -o testlk testlk.f90 
> /tmp/ccbhv5VA.o: In function `__error_impl_mod_MOD_ser_error_print_stack':
> testlk.f90:(.text+0x1b): undefined reference to `__error_mod_MOD_serror'
> /tmp/ccbhv5VA.o: In function `__error_impl_mod_MOD_par_error_print_stack':
> testlk.f90:(.text+0x3b): undefined reference to `__error_mod_MOD_perror'
> /tmp/ccbhv5VA.o: In function `__error_mod_MOD_par_error_handler':
> testlk.f90:(.text+0x6a): undefined reference to `__error_mod_MOD_perror'
> testlk.f90:(.text+0x86): undefined reference to `__error_mod_MOD_perror'
> /tmp/ccbhv5VA.o: In function `__error_mod_MOD_ser_error_handler':
> testlk.f90:(.text+0xa5): undefined reference to `__error_mod_MOD_serror'
> /tmp/ccbhv5VA.o: In function `MAIN__':
> testlk.f90:(.text+0xda): undefined reference to `__error_mod_MOD_serror'
> collect2: error: ld returned 1 exit status

OK - this compiles and runs if the PRIVATE statement is removed. As soon as I return to the privacy issue, I will check that this testcase is OK.

Thanks

Paul
Comment 15 Paul Thomas 2015-07-17 17:24:17 UTC
Author: pault
Date: Fri Jul 17 17:23:45 2015
New Revision: 225945

URL: https://gcc.gnu.org/viewcvs?rev=225945&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_1.f08
      - copied, changed from r225943, trunk/gcc/testsuite/gfortran.dg/submodule_1.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/lib/fortran-modules.exp
Comment 16 Paul Thomas 2015-07-17 17:25:04 UTC
Author: pault
Date: Fri Jul 17 17:24:32 2015
New Revision: 225946

URL: https://gcc.gnu.org/viewcvs?rev=225946&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_2.f08
      - copied, changed from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_2.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_2.f90
Comment 17 Paul Thomas 2015-07-17 17:25:21 UTC
Author: pault
Date: Fri Jul 17 17:24:49 2015
New Revision: 225947

URL: https://gcc.gnu.org/viewcvs?rev=225947&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_3.f08
      - copied unchanged from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_3.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_3.f90
Comment 18 Paul Thomas 2015-07-17 17:25:35 UTC
Author: pault
Date: Fri Jul 17 17:25:04 2015
New Revision: 225948

URL: https://gcc.gnu.org/viewcvs?rev=225948&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_4.f08
      - copied unchanged from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_4.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_4.f90
Comment 19 Paul Thomas 2015-07-17 17:26:29 UTC
Author: pault
Date: Fri Jul 17 17:25:55 2015
New Revision: 225953

URL: https://gcc.gnu.org/viewcvs?rev=225953&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
      - copied unchanged from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_5.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_5.f90
Comment 20 Paul Thomas 2015-07-17 17:26:43 UTC
Author: pault
Date: Fri Jul 17 17:26:12 2015
New Revision: 225955

URL: https://gcc.gnu.org/viewcvs?rev=225955&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_6.f08
      - copied, changed from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_6.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_6.f90
Comment 21 Paul Thomas 2015-07-17 17:27:14 UTC
Author: pault
Date: Fri Jul 17 17:26:42 2015
New Revision: 225956

URL: https://gcc.gnu.org/viewcvs?rev=225956&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_7.f08
      - copied, changed from r225922, trunk/gcc/testsuite/gfortran.dg/submodule_7.f90
Removed:
    trunk/gcc/testsuite/gfortran.dg/submodule_7.f90
Comment 22 Paul Thomas 2015-07-17 17:28:14 UTC
Author: pault
Date: Fri Jul 17 17:27:42 2015
New Revision: 225957

URL: https://gcc.gnu.org/viewcvs?rev=225957&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_8.f08
    trunk/gcc/testsuite/gfortran.dg/submodule_9.f08
Comment 23 Paul Thomas 2015-07-17 17:32:41 UTC
Author: pault
Date: Fri Jul 17 17:32:09 2015
New Revision: 225958

URL: https://gcc.gnu.org/viewcvs?rev=225958&root=gcc&view=rev
Log:
2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* decl.c (gfc_match_end): Pick out declared submodule name from
	the composite identifier.
	* gfortran.h : Add 'submodule_name' to gfc_use_list structure.
	* module.c (gfc_match_submodule): Define submodule_name and add
	static 'submodule_name'.
	(gfc_match_submodule): Build up submodule filenames, using '@'
	as a delimiter. Store the output filename in 'submodule_name'.
	Similarly, the submodule identifier is built using '.' as an
	identifier.
	(gfc_dump_module): If current state is COMP_SUBMODULE, write
	to file 'submodule_name', using SUBMODULE_EXTENSION.
	(gfc_use_module): Similarly, use the 'submodule_name' field in
	the gfc_use_list structure and SUBMODULE_EXTENSION to read the
	implicitly used submodule files.

2015-07-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* lib/fortran-modules.exp (proc cleanup-submodules): New
	procedure.
	* gfortran.dg/submodule_1.f08: Change extension and clean up
	the submodule files.
	* gfortran.dg/submodule_2.f08: ditto
	* gfortran.dg/submodule_6.f08: ditto
	* gfortran.dg/submodule_7.f08: ditto
	* gfortran.dg/submodule_8.f08: New test
	* gfortran.dg/submodule_9.f08: New test

Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 24 Joost VandeVondele 2015-07-18 06:54:45 UTC
(In reply to Paul Thomas from comment #23)

> 	(gfc_dump_module): If current state is COMP_SUBMODULE, write
> 	to file 'submodule_name', using SUBMODULE_EXTENSION.

just a comment / question. I wonder if the use of a different extension makes life more easy / more difficult for people using dependencies based on .mod files to stop recompilation cascades, or other aspects of the build system. I haven't looked carefully enough at the submodule feature to know, but maybe it is worth thinking about. Similarly, if the .smod changes, while this reflect in a .mod timestamp change. 

There is obviously no standard requirement on this, but this gfortran feature is very useful for those who develop & recompile large Fortran projects.
Comment 25 Paul Thomas 2015-08-05 12:06:56 UTC
Author: pault
Date: Wed Aug  5 12:06:25 2015
New Revision: 226622

URL: https://gcc.gnu.org/viewcvs?rev=226622&root=gcc&view=rev
Log:
2015-08-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* module.c (check_access): Return true if new static flag
	'dump_smod' is true..
	(gfc_dump_module): Rename original 'dump_module' and call from
	new version. Use 'dump_smod' rather than the stack state to
	determine if a submodule is being processed. The new version of
	this procedure sets 'dump_smod' depending on the stack state and
	then writes both the mod and smod files if a module is being
	processed or just the smod for a submodule.
	(gfc_use_module): Eliminate the check for module_name and
	submodule_name being the same.
	* trans-decl.c (gfc_finish_var_decl, gfc_build_qualified_array,
	get_proc_pointer_decl): Set TREE_PUBLIC unconditionally and use
	the conditions to set DECL_VISIBILITY as hidden and to set as
	true DECL_VISIBILITY_SPECIFIED.

2015-08-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846

	* lib/fortran-modules.exp: Call cleanup-submodules from
	cleanup-modules.
	* gfortran.dg/public_private_module_2.f90: Add two XFAILS to
	cover the cases where private entities are no longer optimized
	away.
	* gfortran.dg/public_private_module_6.f90: Add an XFAIL for the
	same reason.
	* gfortran.dg/submodule_1.f08: Change cleanup module names.
	* gfortran.dg/submodule_5.f08: The same.
	* gfortran.dg/submodule_9.f08: The same.
	* gfortran.dg/submodule_10.f08: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/submodule_10.f08
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/public_private_module_2.f90
    trunk/gcc/testsuite/gfortran.dg/public_private_module_6.f90
    trunk/gcc/testsuite/gfortran.dg/submodule_1.f08
    trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
    trunk/gcc/testsuite/gfortran.dg/submodule_9.f08
    trunk/gcc/testsuite/lib/fortran-modules.exp
Comment 26 Joost VandeVondele 2015-08-16 18:01:22 UTC
One more datapoint on the .smod / .mod issue. 

I ran into the first package that fails to build with 6.0 because of this. libxc (version 2.2.2, Tobias Burnus actually being one of the authors), relies on a configure macro named ax_cv_f90_modext this macro now leads in the Makefile to :

[...]
am__untar = $${TAR-tar} xf -
ax_cv_f90_modext = mod
smod
bindir = ${exec_prefix}/bin
[...]

which leads to an obvious:> make -j
Makefile:319: *** missing separator.  Stop.

While arguably this is a bug in the ax_cv_f90_modext macro, it might be indicative of possible problems 'in the wild'.

However, I do like the idea of having only public info in the .mod, and hence improving the recompilation cascade problem.
Comment 27 Paul Thomas 2015-09-17 09:10:06 UTC
Author: pault
Date: Thu Sep 17 09:09:34 2015
New Revision: 227855

URL: https://gcc.gnu.org/viewcvs?rev=227855&root=gcc&view=rev
Log:
2015-09-17  Paul Thomas  <pault@gcc.gnu.org>

	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-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/52846
	* gfortran.dg/public_private_module_5.f90: Add module procedure
	trigger_smod to ensure that the smod file is written.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/submodule_5.f08
Comment 28 Paul Thomas 2015-10-18 10:57:13 UTC
The LTO issue is another PR, so closing this one

Paul