[Bug fortran/68829] New: [4.7/4.8/4.9/5.3/6.0 Regression] Segfaults with -Ofast
Joost.VandeVondele at mat dot ethz.ch
gcc-bugzilla@gcc.gnu.org
Thu Dec 10 09:20:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68829
Bug ID: 68829
Summary: [4.7/4.8/4.9/5.3/6.0 Regression] Segfaults with -Ofast
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: Joost.VandeVondele at mat dot ethz.ch
Target Milestone: ---
Currently, switching from -O3 to -Ofast might result in segfaulting Fortran
programs:
> cat test.f90
MODULE foo
CONTAINS
SUBROUTINE mysum(a)
INTEGER :: a(:)
WRITE(6,*) SUM(a)
END SUBROUTINE
END MODULE foo
USE foo
INTEGER, ALLOCATABLE :: a(:)
INTEGER, PARAMETER :: N=2**26 ! 256Mb array
ALLOCATE(a(N)) ; a=1
CALL mysum(a*a)
END
> gfortran -O3 test.f90 && ./a.out
67108864
> gfortran -Ofast test.f90 && ./a.out
Segmentation fault
The reason for this is that -Ofast enables -fstack-arrays. This options puts
temporary arrays off unlimited size on the stack. While there is precedent for
this (ifort), I think this is a poor choice. I think -fstack-arrays should only
do this for sufficiently small arrays.
This is a regression from gcc 4.6 (presumably because -Ofast didn't imply
-fstack-arrays).
More information about the Gcc-bugs
mailing list