[Bug fortran/48462] New: matmul Segmentation Fault with Allocatable Array

ortp21 at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Apr 5 15:22:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48462

           Summary: matmul Segmentation Fault with Allocatable Array
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ortp21@gmail.com


The segmentation fault occurs in the current stable release version of gcc
(4.6.0). The release version source code was downloaded from a gcc mirror and
configured in the following way:

Target: x86_64-apple-darwin10.6.0
Configured with: ../gcc-4.6.0/configure --prefix=$HOME/gcc/gcc-release
--enable-languages=fortran --enable-checking=release --disable-bootstrap
Thread model: posix
gcc version 4.6.0 (GCC) 

Small example:


! matmulTester.f90
program main
implicit none
    integer, parameter :: dp = kind(0.0d0)
    real(kind=dp), allocatable :: a(:,:)
    real(kind=dp), allocatable :: b(:,:)

    allocate(a(3,3))
    allocate(b(3,3))

    a(1,:) = [ 3.11_dp, 3.12_dp, 3.13_dp ]
    a(2,:) = [ 3.21_dp, 3.22_dp, 3.23_dp ]
    a(3,:) = [ 3.31_dp, 3.32_dp, 3.33_dp ]

    b = 6.0_dp * a

    a = matmul( matmul( a, b ), b ) ! Segmentation Fault
end program main


The segmentation fault occurs on the last line of the program above. It can be
fixed by separating the lines:

a = matmul(a,b)
a = matmul(a,b)

The segmentation fault also disappears, and the program runs fine, if
non-allocatable arrays are used for a and b. In addition, replacing the last
line of the program with the following removes the segmentation fault:

b = matmul( matmul( a, b ), b ) ! NO Segmentation Fault

Also, the segmentation fault disappears when another allocatable array is
introduced to the code above:

real(kind=dp), allocatable :: c(:,:)
allocate(3,3)
...
c = matmul( matmul( a, b ), b ) ! NO Segmentation Fault

I used the following command:

gfortran -o matmulTester matmulTester.f90

Finally, building in debug mode and running yields the following:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x000000010008b3ab in __gfortran_matmul_r8 (retarray=<value temporarily
unavailable, due to optimizations>, a=<value temporarily unavailable, due to
optimizations>, b=<value temporarily unavailable, due to optimizations>,
try_blas=<value temporarily unavailable, due to optimizations>, blas_limit=24,
gemm=0x18) at ../../../gcc-4.6.0/libgfortran/generated/matmul_r8.c:284
284              dest_y[x] += abase_n[x] * bbase_yn;


I hope this is not a duplicate and was a worthwhile reporting. If not, I
apologize.

Thanks,
John N.



More information about the Gcc-bugs mailing list