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:

The following causes a bogus "type mismatch" error with the current trunk

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

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

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


  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
  end type tn


  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.
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                                                                                                                                    

   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 Benson:

* Galacticus: