Possible bug with function result as argument
Andrew Benson
abenson@carnegiescience.edu
Thu Nov 10 16:39:00 GMT 2016
Dear Paul,
Thanks for confirming this (and for the workaround). I've opened this as
PR78293:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78293
Thanks,
Andrew
On Thursday, November 10, 2016 11:09:09 AM PST Paul Richard Thomas wrote:
> Dear Andrew,
>
> I can confirm this is a bug. Please would you post it on gcc Bugzilla.
> It compiles and runs fine with ifort.
>
> A workaround is:
> program p
> use m
> implicit none
> type(t), dimension(2) :: c
> type(t), allocatable, dimension(:) :: a, b
> a = ts()
> b = ts()
> c=tt(a,b)
> end program p
>
> Thanks
>
> Paul
>
> On 10 November 2016 at 10:12, Andrew Benson <abenson@carnegiescience.edu>
wrote:
> > The following code dies with a SIGABRT at run time in gfortran 7.0.0
> > (r241975), and also in gfortran 6.2.1. As far as I can see it's valid
> > code,
> > but I wanted to get a second opinion on that before opening a PR.
> >
> > -Andrew
> >
> > --
> >
> > module m
> >
> > implicit none
> >
> > type t
> >
> > integer, allocatable, dimension(:) :: r
> >
> > end type t
> >
> > contains
> >
> > function tt(a,b)
> >
> > implicit none
> > type(t), allocatable, dimension(:) :: tt
> > type(t), intent(in), dimension(:) :: a,b
> > allocate(tt(2))
> > allocate(tt(1)%r(1))
> > allocate(tt(2)%r(1))
> > return
> >
> > end function tt
> >
> > function ts()
> >
> > implicit none
> > type(t), allocatable, dimension(:) :: ts
> > allocate(ts(1))
> > allocate(ts(1)%r(1))
> > return
> >
> > end function ts
> >
> > end module m
> >
> > program p
> >
> > use m
> > implicit none
> > type(t), dimension(2) :: c
> > c=tt(ts(),ts())
> >
> > end program p
> >
> > $ a.out
> > *** Error in `a.out': free(): invalid pointer: 0x0000000002189f50 ***
> > ======= Backtrace: =========
> > /lib64/libc.so.6(+0x7570b)[0x2aceab27c70b]
> > /lib64/libc.so.6(+0x7deaa)[0x2aceab284eaa]
> > /lib64/libc.so.6(cfree+0x4c)[0x2aceab28840c]
> > a.out[0x4016ab]
> > a.out[0x40171c]
> > /lib64/libc.so.6(__libc_start_main+0xf1)[0x2aceab227731]
> > a.out[0x4007b9]
> > ======= Memory map: ========
> > 00400000-00402000 r-xp 00000000 fd:03 9574876 /
> > home/abenson/Galacticus/v0.9.4/a.out
> > 00601000-00602000 r--p 00001000 fd:03 9574876 /
> > home/abenson/Galacticus/v0.9.4/a.out
> > 00602000-00603000 rw-p 00002000 fd:03 9574876 /
> > home/abenson/Galacticus/v0.9.4/a.out
> > 02187000-021a8000 rw-p 00000000 00:00 0
> > [heap]
> > 2aceaa550000-2aceaa574000 r-xp 00000000 fd:01 400265
> > /usr/ lib64/ld-2.23.so
> > 2aceaa574000-2aceaa576000 rw-p 00000000 00:00 0
> > 2aceaa5c0000-2aceaa5c4000 rw-p 00000000 00:00 0
> > 2aceaa773000-2aceaa774000 r--p 00023000 fd:01 400265
> > /usr/ lib64/ld-2.23.so
> > 2aceaa774000-2aceaa775000 rw-p 00024000 fd:01 400265
> > /usr/ lib64/ld-2.23.so
> > 2aceaa775000-2aceaa776000 rw-p 00000000 00:00 0
> > 2aceaa776000-2aceaa8a4000 r-xp 00000000 fd:01 409988
> > /usr/ lib64/libgfortran.so.3.0.0
> > 2aceaa8a4000-2aceaaaa4000 ---p 0012e000 fd:01 409988
> > /usr/ lib64/libgfortran.so.3.0.0
> > 2aceaaaa4000-2aceaaaa5000 r--p 0012e000 fd:01 409988
> > /usr/ lib64/libgfortran.so.3.0.0
> > 2aceaaaa5000-2aceaaaa6000 rw-p 0012f000 fd:01 409988
> > /usr/ lib64/libgfortran.so.3.0.0
> > 2aceaaaa6000-2aceaaaa7000 rw-p 00000000 00:00 0
> > 2aceaaaa7000-2aceaabaf000 r-xp 00000000 fd:01 468489
> > /usr/ lib64/libm-2.23.so
> > 2aceaabaf000-2aceaadae000 ---p 00108000 fd:01 468489
> > /usr/ lib64/libm-2.23.so
> > 2aceaadae000-2aceaadaf000 r--p 00107000 fd:01 468489
> > /usr/ lib64/libm-2.23.so
> > 2aceaadaf000-2aceaadb0000 rw-p 00108000 fd:01 468489
> > /usr/ lib64/libm-2.23.so
> > 2aceaadb0000-2aceaadc6000 r-xp 00000000 fd:01 394309
> > /usr/ lib64/libgcc_s-6.2.1-20160916.so.1
> > 2aceaadc6000-2aceaafc5000 ---p 00016000 fd:01 394309
> > /usr/ lib64/libgcc_s-6.2.1-20160916.so.1
> > 2aceaafc5000-2aceaafc6000 r--p 00015000 fd:01 394309
> > /usr/ lib64/libgcc_s-6.2.1-20160916.so.1
> > 2aceaafc6000-2aceaafc7000 rw-p 00016000 fd:01 394309
> > /usr/ lib64/libgcc_s-6.2.1-20160916.so.1
> > 2aceaafc7000-2aceab006000 r-xp 00000000 fd:01 409963
> > /usr/ lib64/libquadmath.so.0.0.0
> > 2aceab006000-2aceab205000 ---p 0003f000 fd:01 409963
> > /usr/ lib64/libquadmath.so.0.0.0
> > 2aceab205000-2aceab206000 r--p 0003e000 fd:01 409963
> > /usr/ lib64/libquadmath.so.0.0.0
> > 2aceab206000-2aceab207000 rw-p 0003f000 fd:01 409963
> > /usr/ lib64/libquadmath.so.0.0.0
> > 2aceab207000-2aceab3c0000 r-xp 00000000 fd:01 464724
> > /usr/ lib64/libc-2.23.so
> > 2aceab3c0000-2aceab5bf000 ---p 001b9000 fd:01 464724
> > /usr/ lib64/libc-2.23.so
> > 2aceab5bf000-2aceab5c3000 r--p 001b8000 fd:01 464724
> > /usr/ lib64/libc-2.23.so
> > 2aceab5c3000-2aceab5c5000 rw-p 001bc000 fd:01 464724
> > /usr/ lib64/libc-2.23.so
> > 2aceab5c5000-2aceab5c9000 rw-p 00000000 00:00 0
> > 2aceac000000-2aceac021000 rw-p 00000000 00:00 0
> > 2aceac021000-2aceb0000000 ---p 00000000 00:00 0
> > 7ffd3397b000-7ffd3399d000 rw-p 00000000 00:00 0
> > [stack]
> > 7ffd339cf000-7ffd339d1000 r--p 00000000 00:00 0
> > [vvar]
> > 7ffd339d1000-7ffd339d3000 r-xp 00000000 00:00 0
> > [vdso]
> > ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
> > [vsyscall]
> >
> > Program received signal SIGABRT: Process abort signal.
> >
> > Backtrace for this error:
> > #0 0x2aceaa791df7 in ???
> > #1 0x2aceaa79102d in ???
> > #2 0x2aceab23b7df in ???
> > #3 0x2aceab23b765 in ???
> > #4 0x2aceab23d369 in ???
> > #5 0x2aceab27c70f in ???
> > #6 0x2aceab284ea9 in ???
> > #7 0x2aceab28840b in ???
> > #8 0x4016aa in p
> >
> > at /home/abenson/Galacticus/v0.9.4/t.F90:34
> >
> > #9 0x40171b in main
> >
> > at /home/abenson/Galacticus/v0.9.4/t.F90:31
> >
> > Abort (core dumped)
> >
> > --
> >
> > * Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html
> >
> > * Galacticus: http://sites.google.com/site/galacticusmodel
--
* Andrew Benson: http://users.obs.carnegiescience.edu/abenson/contact.html
* Galacticus: http://sites.google.com/site/galacticusmodel
More information about the Fortran
mailing list