Array of derived type elements incorrectly accessed in function
Andrew Benson
abenson@carnegiescience.edu
Sat Feb 24 00:45:00 GMT 2018
I created PR84538 for the following bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84538
The following code results in incorrect behavior with gfortran 8.0.1
(r257956):
module bugMod
public
type :: t
integer :: i
end type t
type, extends(t) :: te
integer :: j
end type te
contains
subroutine check(n)
implicit none
class(t), intent(inout), dimension(:) :: n
write (0,*) "FROM MODULE ",n%i
return
end subroutine check
end module bugMod
program bug
use bugMod
class(t), allocatable, dimension(:) :: n
allocate(te :: n(2))
n(1:2)%i=[8,3]
write (0,*) "FROM PROGRAM ",n%i
call check(n)
end program bug
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/nfs/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-
linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/nfs/home/abenson/Galacticus/Tools --
enable-languages=c,c++,fortran --disable-multilib
Thread model: posix
gcc version 8.0.1 20180223 (experimental) (GCC)
$ gfortran bug.F90
$ a.out
FROM PROGRAM 8 3
FROM MODULE 8 0
I would expect the output to be the same from the module subroutine as from
the main program.
--
* Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html
* Galacticus: http://sites.google.com/site/galacticusmodel
More information about the Fortran
mailing list