[Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result
johnww at tds dot net
gcc-bugzilla@gcc.gnu.org
Mon Jun 9 20:45:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459
Bug ID: 61459
Summary: segfault when assigning to allocatable function result
from matmul result
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: johnww at tds dot net
Created attachment 32913
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=32913&action=edit
Output for "gfortran -v -Wall -Wextra -std=f2003" (compiler version 4.7.2)
In a function with an allocatable array as result variable, an assigment
statement with the result variable on the LHS segfaults when the value
assigned is generated by matmul. This behavior is observed with
versions 4.7.2, 4.8.0, and 4.9.0. With version 4.6.2, an ICE occurs
at the same assignment statement. Similar code worked with version
4.4.5, so there appears to be a regression.
The source code below illustrates the problem and shows a workaround.
Code like the example which worked with version 4.4.5 started failing when
compiled after an OS upgrade (Debian) installed 4.7.2. Coincidentally
colleagues using the same code on OS X upgraded from 4.4.x to gfortran 4.8.0
and 4.9.0, and likewise encountered segfaults with new compilations.
Since the segfault occurs with multiple versions under two operating systems,
I suspect that the problem is not due to something that Debian or whoever
packaged the Apple version did.
gdb reports that the segfault is detected within matmul.
No problem if the result variable is not allocatable.
I tried some other intrinsics in place of matmul; no problem.
With -Wall -Wextra -std=f2003 there are no warnings, errors, or any other
output from the compiler.
(In our production code, the arguments to matmul are a slice of an
allocatable integer array and an allocatable real(kind=real64) array,
but the problem occurs without these embellishments, as the example
code shows.)
Example source code:
module a
implicit none
private
public :: f_segfault, f_workaround
integer, dimension(2,2) :: b = reshape([1,-1,1,1],[2,2])
contains
function f_segfault(x)
real, dimension(:), allocatable :: f_segfault
real, dimension(:), intent(in) :: x
allocate(f_segfault(2))
f_segfault = matmul(b,x)
end function f_segfault
function f_workaround(x)
real, dimension(:), allocatable :: f_workaround
real, dimension(:), intent(in) :: x
real, dimension(:), allocatable :: tmp
allocate(f_workaround(2),tmp(2))
tmp = matmul(b,x)
f_workaround = tmp
end function f_workaround
end module a
program main
use a
implicit none
real, dimension(2) :: x = 1.0
print *, "f_workaround(x) =", f_workaround(x)
print *, "f_segfault(x) =", f_segfault(x)
end program main
More information about the Gcc-bugs
mailing list