This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/23246] New: Error using function returning array as subroutine argument
- From: "f dot a dot akeroyd at rl dot ac dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Aug 2005 10:41:57 -0000
- Subject: [Bug fortran/23246] New: Error using function returning array as subroutine argument
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When nesting a function that returns an array result within a call to
a subroutine I get either segmentation or "double free" errors with gfortran.
I am using gfortran 4.0.1 on Fedora Core 4
$ gfortran -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-
checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-
exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-
home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux Thread
model: posix gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
$ uname -a
Linux localhost.localdomain 2.6.12-1.1398_FC4 #1 Fri Jul 15 00:52:32 EDT 2005
i686 athlon i386 GNU/Linux
$ gfortran -g -O0 test.f90
$ gdb a.out
GNU gdb Red Hat Linux (6.3.0.0-1.21rh) Copyright 2004 Free Software
Foundation, Inc. GDB is free software, covered by the GNU General Public
License, and you are welcome to change it and/or distribute copies of it under
certain conditions. Type "show copying" to see the conditions. There is
absolutely no warranty for GDB. Type "show warranty" for details. This GDB
was configured as "i386-redhat-linux-gnu"...Using host libthread_db
library "/lib/libthread_db.so.1".
(gdb) r
Starting program: a.out
Reading symbols from shared object read from target memory...done. Loaded
system supplied DSO at 0xc2b000
Program received signal SIGSEGV, Segmentation fault.
0x08048644 in __testmodule__func2 (__result=@0xbff7e770, string=@0x8048888,
flag=@0x8048890, _string=5) at test.f90:16
16 array(i) = ichar(string(i:i))
Current language: auto; currently fortran
(gdb)
$ cat test.f90
MODULE testmodule
IMPLICIT NONE
INTEGER, PARAMETER, PUBLIC :: i1 = selected_int_kind(2)
CONTAINS
subroutine sub1 (array3)
INTEGER(kind=i1),intent(in) :: array3(:)
END subroutine sub1
FUNCTION func2 (string,flag) RESULT (array)
CHARACTER(len=*), INTENT(in) :: string
INTEGER(kind=i1) :: array(255)
INTEGER :: i
logical flag
if (flag) then
DO i = 1,min(len_trim(string),(size(array)-1))
array(i) = ichar(string(i:i))
END DO
array(len_trim(string)+1) = 0
endif
END FUNCTION func2
END MODULE testmodule
program test
use testmodule
implicit none
INTEGER(kind=i1) :: array2(255)
array2 = func2('hello',.false.) ! OK
array2 = func2('hello',.true.) ! OK
call sub1(func2('hello',.false.)) ! "Possible double free of temporary" error
call sub1(func2('hello',.true.)) ! casues "segmentation fault" in func2
end
--
Summary: Error using function returning array as subroutine
argument
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: f dot a dot akeroyd at rl dot ac dot uk
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23246