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