This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/15335] New: [gfortran] runtime error "Attempt to allocate a non-positive amount of memory"
- From: "Tobias dot Schlueter at physik dot uni-muenchen dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 May 2004 00:27:58 -0000
- Subject: [Bug fortran/15335] New: [gfortran] runtime error "Attempt to allocate a non-positive amount of memory"
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This reduced testcase exhibits a problem in memory allocation for temporaries:
program Driver
real :: a(4,4)
call factor
contains
subroutine Factor
real :: A(4, 4), B(4), lu(4,4)
integer:: p(4)
do M = 1, 4
LU(P(I), M) = Reduce (LU(P(I), M), LU(P(I), 1: M - 1), LU(P(1: M - 1), M))
end do
return
end subroutine Factor
function Reduce (A, Row, Col)
real :: A, Row(:), Col(:)
reduce = 0
end function Reduce
end program Driver
[tobi@marktplatz meissner]$ gfortran reduced.f90
[tobi@marktplatz meissner]$ ./a.out
Fortran runtime error: Attempt to allocate a non-positive amount of memory.
[tobi@marktplatz meissner]$
After removing either the loop in factor or the declaration in main the program
yields a segfault instead, so this is a out-of-bound memory access. Valgrind
confirms this:
[tobi@marktplatz meissner]$ valgrind ./a.out
==1649== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==1649== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==1649== Using valgrind-2.0.0, a program supervision framework for x86-linux.
==1649== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==1649== Estimated CPU clock rate is 799 MHz
==1649== For more details, rerun with: -v
==1649==
==1649== Use of uninitialised value of size 4
==1649== at 0x804853D: factor.1 (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x804874F: MAIN__ (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x8048782: main (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x24F3F1: __libc_start_main (in /lib/libc-2.3.3.so)
==1649==
==1649== Invalid read of size 4
==1649== at 0x804853D: factor.1 (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x804874F: MAIN__ (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x8048782: main (in /home/tobi/src/tests/meissner/a.out)
==1649== by 0x24F3F1: __libc_start_main (in /lib/libc-2.3.3.so)
==1649== Address 0x5B73AC is not stack'd, malloc'd or free'd
Fortran runtime error: Attempt to allocate a non-positive amount of memory.
==1649==
==1649== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
==1649== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1649== malloc/free: 4 allocs, 4 frees, 16712 bytes allocated.
==1649== For a detailed leak analysis, rerun with: --leak-check=yes
==1649== For counts of detected errors, rerun with: -v
[tobi@marktplatz meissner]$
--
Summary: [gfortran] runtime error "Attempt to allocate a non-
positive amount of memory"
Product: gcc
Version: tree-ssa
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Tobias dot Schlueter at physik dot uni-muenchen dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux
GCC host triplet: i686-pc-linux
GCC target triplet: i686-pc-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15335