Bug 34672

Summary: [4.3 Regression] .mod file misses renamed, USEd symbol
Product: gcc Reporter: Jos de Kloe <kloedej>
Component: fortranAssignee: Paul Thomas <pault>
Status: RESOLVED FIXED    
Severity: normal CC: burnus, dfranke, gcc-bugs
Priority: P3 Keywords: rejects-valid
Version: 4.3.0   
Target Milestone: ---   
URL: http://gcc.gnu.org/ml/fortran/2008-01/msg00077.html
Host: Target:
Build: Known to work: 4.2.1 4.1.3
Known to fail: 4.3.0 Last reconfirmed: 2008-01-07 13:06:22
Bug Depends on:    
Bug Blocks: 32834    

Description Jos de Kloe 2008-01-04 13:16:34 UTC
The attached piece of valid Fortran90 code generates a symbol error:

>gfortran -c moduletest.F90
moduletest.F90:22.19:

  USE MyMod3, only: write_MyInt
                  1
Error: Symbol 'write_myint' referenced at (1) not found in module 'mymod3'
>

Note that when the line marked with "mark" is commented out the error disappears! This seems a bug to me in gfortran.

The code works just fine for the 3 other fortran compilers that I have installed (ifort, pgf90, g95), and also works fine with my previous test version of gfortran (version of 20071024), but the current version 20080103 shows this bug.

Best regards,

Jos de kloe
-----

The following code demonstrates this behaviour:

MODULE MyMod1
  integer, parameter :: i2_ = Selected_Int_Kind(4)
END Module MyMod1

module MyMod2
  INTERFACE write_int
     module procedure write_int_local
  END INTERFACE
contains
  subroutine write_int_local(value)
    integer, intent(in)  :: value
    print *,value
  end subroutine write_int_local
end module MyMod2

module MyMod3
  USE MyMod2, only: write_MyInt   => write_int
  USE MyMod1, only: i2_                 ! mark                                  
end module MyMod3

module MyMod4
  USE MyMod3, only: write_MyInt
!contains                                                                       
!  subroutine MyWrite(a)                                                        
!    integer, intent(in)  :: a                                                  
!    call write_MyInt(a)                                                        
!  end subroutine MyWrite                                                       
end module MYMOD4
Comment 1 Tobias Burnus 2008-01-04 13:31:42 UTC
If one changes the order of the USE statements or remove the second USE statement, it works:

module MyMod3
  USE MyMod2, only: write_MyInt   => write_int
  USE MyMod1, only: i2_
end module MyMod3

Looking at the MOD file,
   (('write_myint' 'mymod2' 2))
is missing for the original example, but present if one one does either change mentioned above.
Comment 2 Paul Thomas 2008-01-04 16:12:11 UTC
Another way of looking as it is that the interface is not getting renamed when MyMod3 is written.  This works:

MODULE MyMod1
  integer, parameter :: i2_ = Selected_Int_Kind(4)
END Module MyMod1

module MyMod2
  INTERFACE write_int
     module procedure write_int_local
  END INTERFACE
contains
  subroutine write_int_local(value)
    integer, intent(in)  :: value
    print *,value
  end subroutine write_int_local
end module MyMod2

module MyMod3
  USE MyMod2, only: write_MyInt   => write_int
  USE MyMod1, only: i2_
end module MyMod3

module MyMod4
  USE MyMod3, write_MyInt => write_int     ! Use the original name
end module MYMOD4

I believe, although I have not yet checked, that when I reformed the interface handling in modules I did not change the writing part.  I'll bet it uses the symbol name, rather than the symtree.  This would have worked previously.

Paul
Comment 3 Paul Thomas 2008-01-07 13:06:22 UTC
Since I have submitted the patch, I should take it on!

Paul
Comment 4 Paul Thomas 2008-01-07 16:45:27 UTC
Subject: Bug 34672

Author: pault
Date: Mon Jan  7 16:44:43 2008
New Revision: 131377

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131377
Log:
2008-01-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34672
	* module.c (write_generic): Rewrite completely.
	(write_module): Change call to write_generic.

2008-01-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34672
	* gfortran.dg/use_only_2.f90: New test.



Added:
    trunk/gcc/testsuite/gfortran.dg/use_only_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2008-01-07 16:46:07 UTC
Fixed on trunk

Paul
Comment 6 Jos de Kloe 2008-01-16 14:11:56 UTC
Dear people,

this comment is just to let you know that the problem is also solved on my side now. My software compiles and runs again as expected.

thanks a lot for your effort and fast response.

Jos de Kloe