public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/18197] New: bus error on returning from a function
@ 2004-10-28 12:31 niilo dot sirola at tut dot fi
  2004-10-28 12:33 ` [Bug fortran/18197] " niilo dot sirola at tut dot fi
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: niilo dot sirola at tut dot fi @ 2004-10-28 12:31 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-01-01  5:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-18197-9538@http.gcc.gnu.org/bugzilla/>
2005-10-27 16:46 ` [Bug fortran/18197] bus error on returning from a function pinskia at gcc dot gnu dot org
2005-11-07 14:49 ` tobi at gcc dot gnu dot org
2005-12-06 18:04 ` eedelman at gcc dot gnu dot org
2005-12-06 19:38 ` eedelman at gcc dot gnu dot org
2005-12-14  6:51 ` jpr at csc dot fi
2005-12-15  0:47 ` eedelman at gcc dot gnu dot org
2005-12-16 18:54 ` eedelman at gcc dot gnu dot org
2005-12-17 19:51 ` eedelman at gcc dot gnu dot org
2005-12-17 19:55 ` eedelman at gcc dot gnu dot org
2006-01-01  5:26 ` pinskia at gcc dot gnu dot org
2004-10-28 12:31 [Bug fortran/18197] New: " niilo dot sirola at tut dot fi
2004-10-28 12:33 ` [Bug fortran/18197] " niilo dot sirola at tut dot fi
2004-10-28 13:26 ` pinskia at gcc dot gnu dot org
2004-12-08 23:58 ` tobi at gcc dot gnu dot org
2005-04-11 23:45 ` pinskia at gcc dot gnu dot org
2005-04-12  0:49 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).