This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/50924] New: Attempt to allocate negative amount of memory. Possible integer overflow
- From: "fwi at inducks dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 30 Oct 2011 17:57:16 +0000
- Subject: [Bug fortran/50924] New: Attempt to allocate negative amount of memory. Possible integer overflow
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50924
Bug #: 50924
Summary: Attempt to allocate negative amount of memory.
Possible integer overflow
Classification: Unclassified
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: fwi@inducks.org
When allocating a large array the progrem stops with:
Fortran runtime error: Attempt to allocate negative amount of memory. Possible
integer overflow
Test program:
PROGRAM MAIN
DOUBLE PRECISION, ALLOCATABLE :: E(:,:,:)
INTEGER :: N
N=645
ALLOCATE(E(N,N,N))
DEALLOCATE(E)
END PROGRAM MAIN
With N=646:
$ gfortran -fbacktrace -g test.f90 && ./a.out
Fortran runtime error: Attempt to allocate negative amount of memory. Possible
integer overflow
Backtrace for this error:
+ /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6) [0xe2dbd6]
With N=645, the program works fine and takes 68.5% of the memory, so there
should be enough room for a 646^3 array (no other program is using a
significant amount of memory).
I believe the problem is that sizeof(double)=8 so the array size is:
8*(645^3) = 2 146 689 000
8*(646^3) = 2 156 689 088
and: 2^31 = 2 147 483 648
So my guess is that the total amount of memory needed for the array is saved in
some integer, which overflows and become negative.
If that's of any use:
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Celeron(R) CPU E3300 @ 2.50GHz
stepping : 10
cpu MHz : 2493.807
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc
arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3
cx16 xtpr pdcm xsave lahf_lm tpr_shadow vnmi flexpriority
bogomips : 4987.61
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Celeron(R) CPU E3300 @ 2.50GHz
stepping : 10
cpu MHz : 2493.807
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc
arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3
cx16 xtpr pdcm xsave lahf_lm tpr_shadow vnmi flexpriority
bogomips : 4987.44
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.3 LTS"
Thanks.