public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data
@ 2009-05-06 8:01 mick at nag dot co dot uk
2009-05-06 8:35 ` [Bug fortran/40037] " rguenth at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mick at nag dot co dot uk @ 2009-05-06 8:01 UTC (permalink / raw)
To: gcc-bugs
The program below compiled with gfortran 4.4.0 (and 4.3.2) and using the
-O3 optimization flag generates, in subroutine SMALL, sse instructions
which assume that the data array C is aligned on a 16 byte boundary.
For example: mulpd (%rax,%rcx,1),%xmm0
where register %rax may not be 16-byte aligned.
This leads to a segmentation violation at run time.
The test program deliberately forces array C to be unaligned before
being passed to subroutine SMALL. In a real situation one would
not do this, of course, but when the memory holding array C comes from
somewhere else (e.g. a program written in a different language) there
is no guarantee of alignment.
gfortran version 4.2.0 did not display this problem - the code
generated for SMALL did not assume alignment.
C Declare a REAL array as workspace. We pass it to a routine
C expecting a DOUBLE PRECISION array. This allows us to pass
C data aligned or not aligned on a 16 byte boundary.
real c(100)
integer m
external tt
m = 2
C Call tt with array C aligned on 16 byte boundary
call tt(m, c(1))
C Call tt with array C not aligned on 16 byte boundary
call tt(m, c(2))
end
subroutine tt(m, c)
double precision c(m,m)
external small
do i = 1, m
do j = 1, m
c(i,j) = 1.0d0
end do
end do
call small(m, c)
write (*,*) 'After call small(m, c), c(1,1) = ', c(1,1)
end
subroutine small(m, c)
integer m
double precision c(m,*)
integer i
do 70, i = 1, m
c(i,1) = c(i,1) + c(i,1)
70 continue
return
end
Here's the output from the -v flag of the compiler:
% gfortran -v -O3 align.f
Driving: gfortran -v -O3 align.f -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /opt/gcc-4.4.0-build/gcc-4.4.0/configure
--enable-languages=c,fortran,c++ --prefix=/opt/gcc-4.4.0
--with-mpfr=/opt/mpfr-2.4.1 --with-gmp=/opt/gmp-4.1.4
Thread model: posix
gcc version 4.4.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-O3' '-shared-libgcc' '-mtune=generic'
/opt/gcc-4.4.0/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/f951 align.f
-ffixed-form -quiet -dumpbase align.f -mtune=generic -auxbase align -O3
-version -fintrinsic-modules-path
/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/finclude -o
/tmp/cc9eHSWv.s
GNU Fortran (GCC) version 4.4.0 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.4.0, GMP version 4.1.4, MPFR version 2.4.1.
warning: GMP header version 4.1.4 differs from library version 4.2.
warning: MPFR header version 2.4.1 differs from library version 2.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-O3' '-shared-libgcc' '-mtune=generic'
as -V -Qy -o /tmp/cc05mKcU.o /tmp/cc9eHSWv.s
GNU assembler version 2.19 (x86_64-unknown-linux-gnu) using BFD version (GNU
Binutils) 2.19
COMPILER_PATH=/opt/gcc-4.4.0/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/gcc-4.4.0/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/gcc-4.4.0/libexec/gcc/x86_64-unknown-linux-gnu/:/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/:/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-O3' '-shared-libgcc' '-mtune=generic'
/opt/gcc-4.4.0/libexec/gcc/x86_64-unknown-linux-gnu/4.4.0/collect2
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o
/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/crtbegin.o
-L/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0
-L/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64
-L/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/../../..
/tmp/cc05mKcU.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/opt/gcc-4.4.0/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/crtend.o
/usr/lib/../lib64/crtn.o
--
Summary: gfortran -O3 optimization generates code that seg faults
on unaligned array data
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mick at nag dot co dot uk
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/40037] gfortran -O3 optimization generates code that seg faults on unaligned array data
2009-05-06 8:01 [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data mick at nag dot co dot uk
@ 2009-05-06 8:35 ` rguenth at gcc dot gnu dot org
2009-05-06 8:46 ` mick at nag dot co dot uk
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-06 8:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2009-05-06 08:34 -------
I think this is not a valid Fortran program.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/40037] gfortran -O3 optimization generates code that seg faults on unaligned array data
2009-05-06 8:01 [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data mick at nag dot co dot uk
2009-05-06 8:35 ` [Bug fortran/40037] " rguenth at gcc dot gnu dot org
@ 2009-05-06 8:46 ` mick at nag dot co dot uk
2009-05-06 9:19 ` jakub at gcc dot gnu dot org
2009-05-06 17:40 ` hjl dot tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: mick at nag dot co dot uk @ 2009-05-06 8:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from mick at nag dot co dot uk 2009-05-06 08:45 -------
(In reply to comment #1)
> I think this is not a valid Fortran program.
>
The main program is illegal because it passes a REAL array argument
to a subroutine expecting DOUBLE PRECISION array. However, the subroutine
SMALL is not illegal, but causes bad code to be generated. The main
program is only present for easy demonstration of the bug in SMALL.
Mick Pont
--
mick at nag dot co dot uk changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/40037] gfortran -O3 optimization generates code that seg faults on unaligned array data
2009-05-06 8:01 [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data mick at nag dot co dot uk
2009-05-06 8:35 ` [Bug fortran/40037] " rguenth at gcc dot gnu dot org
2009-05-06 8:46 ` mick at nag dot co dot uk
@ 2009-05-06 9:19 ` jakub at gcc dot gnu dot org
2009-05-06 17:40 ` hjl dot tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-06 9:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jakub at gcc dot gnu dot org 2009-05-06 09:18 -------
The code generated for SMALL is correct, any caller that passes argument not
aligned on 8 byte boundary (you are mistaken that it requires 16 byte
alignment,
try calling it with c(3) which is 8 byte aligned, but not 16 byte aligned and
it will work too) is invalid. All DOUBLE PRECISION variables/arrays must be
properly aligned on 8 byte boundaries.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40037
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/40037] gfortran -O3 optimization generates code that seg faults on unaligned array data
2009-05-06 8:01 [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data mick at nag dot co dot uk
` (2 preceding siblings ...)
2009-05-06 9:19 ` jakub at gcc dot gnu dot org
@ 2009-05-06 17:40 ` hjl dot tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-05-06 17:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from hjl dot tools at gmail dot com 2009-05-06 17:39 -------
(In reply to comment #3)
> The code generated for SMALL is correct, any caller that passes argument not
> aligned on 8 byte boundary (you are mistaken that it requires 16 byte
> alignment,
> try calling it with c(3) which is 8 byte aligned, but not 16 byte aligned and
> it will work too) is invalid. All DOUBLE PRECISION variables/arrays must be
> properly aligned on 8 byte boundaries.
>
I believe x86-64 psABI requires that all arrays >= 16byte must be aligned
at 16byte.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40037
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-06 17:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-06 8:01 [Bug fortran/40037] New: gfortran -O3 optimization generates code that seg faults on unaligned array data mick at nag dot co dot uk
2009-05-06 8:35 ` [Bug fortran/40037] " rguenth at gcc dot gnu dot org
2009-05-06 8:46 ` mick at nag dot co dot uk
2009-05-06 9:19 ` jakub at gcc dot gnu dot org
2009-05-06 17:40 ` hjl dot tools at gmail dot com
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).