[Bug fortran/18197] New: bus error on returning from a function
niilo dot sirola at tut dot fi
gcc-bugzilla@gcc.gnu.org
Thu Oct 28 12:31:00 GMT 2004
The attached code compiles without warnings, but gives "bus error" on execution.
Used GNU Fortran 95 (GCC 4.0.0 20041027 (experimental)) on powerpc-apple-darwin7.5.0.
It seems that when crashing, the __result of function f somehow gets data address 0x0, which seems
bit abnormal. Very delicate changes in the code remove this behaviour, it seems to have something to
do with assumed-shape arrays.
Somewhat reduced testcase and a debugging session follow:
module innerfun
contains
function f(n,x) result(y)
integer, intent(in) :: n
real, dimension(:), intent(in) :: x
real, dimension(n) :: y
y = 1
end function f
end module innerfun
module outerfun
contains
subroutine foo(n,funname)
integer, intent(in) :: n
real, dimension(n) :: y
real, dimension(2) :: x
interface
function funname(n,x) result(y)
integer, intent(in) :: n
real, dimension(:), intent(in) :: x
real, dimension(n) :: y
end function funname
end interface
x = (/ 0.2, 0.3 /)
y = funname(n, x ) ! this works
y = funname(n, (/ 0.2, 0.3 /)) ! this doesn't
end subroutine foo
end module outerfun
program test
use outerfun
use innerfun
call foo(1,f)
end program test
(gdb) run
Starting program: /Users/niilo/fortran/test
Reading symbols for shared libraries . done
Program received signal EXC_BAD_ACCESS, Could not access memory.
0x00002b1c in __innerfun (__result=@0xbffff774, n=@0x14ec4, x=@0xbffff73c) at test.f90:7
7 y = 1
(gdb) print __result
$1 = (struct array1_real4 &) @0xbffff774: {
data = 0x0,
offset = 0,
dtype = 281,
dim = {{
stride = 0,
lbound = 1711407104,
ubound = 0
}}
}
(gdb) where
#0 0x00002b1c in __innerfun (__result=@0xbffff774, n=@0x14ec4, x=@0xbffff73c) at test.f90:7
#1 0x00002dd0 in __outerfun__foo (n=@0x14ec4, funname=0x2a74 <__innerfun(float)>) at test.f90:
27
#2 0x00002e84 in MAIN__ () at test.f90:35
#3 0x00002eb0 in main (argc=-1073744012, argv=0x14ec4) at ../../../gcc/libgfortran/fmain.c:18
--
Summary: bus error on returning from a function
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: niilo dot sirola at tut dot fi
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-apple-darwin7.5.0
GCC host triplet: powerpc-apple-darwin7.5.0
GCC target triplet: powerpc-apple-darwin7.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18197
More information about the Gcc-bugs
mailing list