PR94446 - Bogus "type mismatch" with TYPE(c_ptr) and sizeof()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PR94446 - Bogus "type mismatch" with TYPE(c_ptr) and sizeof()

Andrew Benson-3
I opened PR94446 for this problem:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94446

The following causes a bogus "type mismatch" error with the current trunk
(e899d4b71255b9ae096a7ecd31a61fc76f200019):

$ cat file1.F90
module nrn
  use, intrinsic :: ISO_C_Binding

  type :: rgc
     private
   contains
     procedure :: st => rgcST
  end type rgc

  type, extends(rgc) :: rgcG
     private
   contains
     procedure :: st => rgcGST
  end type rgcG
 
  interface
     module subroutine rgcGST(s,gsf)
       class(rgcG), intent(inout) :: s
       type(c_ptr), intent(in   ) :: gsf
     end subroutine rgcGST
  end interface

contains

  subroutine rgcST(s,gsf)
    implicit none
    class(rgc), intent(inout) :: s
    type(c_ptr), intent(in   ) :: gsf
  end subroutine rgcST
 
end module nrn


$ cat file2.F90

module gn
  use :: nrn

  type, public :: mt
     class (rgc), pointer :: rgc_
  end type mt

  type, public :: tn
    type (mt), pointer :: ht
   contains
  end type tn

contains

  subroutine tnc()
    type(tn) :: a
    write (0,*) sizeof(a)
  end subroutine tnc
 
end module gn

module eh
  use :: gn
end module eh



$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-
linux-gnu/10.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-git/configure --prefix=/home/abenson/Galacticus/Tools --
enable-languages=c,c++,fortran --disable-multilib : (reconfigured) ../gcc-git/
configure --prefix=/home/abenson/Galacticus/Tools --disable-multilib --enable-
languages=c,c++,fortran,lto --no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200401 (experimental) (GCC)


$ gfortran -c  file1.F90 -o file1.o

$ gfortran -c  file2.F90 -o file2.o                                                                                                                                    
file2.F90:24:8:

   24 |   use :: gn
      |        1
Error: Argument mismatch for the overriding procedure 'st' at (1): Type
mismatch in argument 'gsf' (TYPE(c_ptr)/INTEGER(8))


The error only occurs if the module in file1.F90 is compiled separately - if I
combine file1.F90 and file2.F90 into a single file, that single file compiles
without error.

I haven't been able to reduce the testcase further, and figuring out the cause
of the error has so far been beyond my ability. What I have found though is
that in the nrn.mod module file created by compiling file.F90 all instances of
symbol "gsf" are correctly given DERIVED type. But, in gn.mod created by
compiling file2.F90 there are two instances of symbol "gsf", the first has
DERIVED type, while the second has INTEGER type. So, it seems that the problem
occurs at (or before) the creation of the gn.mod module file.

Also, the use of the "sizeof()" intrinsic is necessary to trigger the bug.

-Andrew

--

* Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html

* Galacticus: https://github.com/galacticusorg/galacticus