public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result
@ 2014-06-09 20:45 johnww at tds dot net
  2014-06-09 21:17 ` [Bug fortran/61459] " anlauf at gmx dot de
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: johnww at tds dot net @ 2014-06-09 20:45 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-08 19:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
2014-06-09 21:17 ` [Bug fortran/61459] " anlauf at gmx dot de
2014-06-09 22:18 ` [Bug fortran/61459] [4.7/4.8/4.9/4.10 Regression] " dominiq at lps dot ens.fr
2014-06-25 11:16 ` [Bug fortran/61459] [4.8/4.9/4.10 " rguenth at gcc dot gnu.org
2014-07-06  9:20 ` tkoenig at gcc dot gnu.org
2014-07-06 14:26 ` pault at gcc dot gnu.org
2014-07-06 16:36 ` dominiq at lps dot ens.fr
2014-07-07 20:01 ` pault at gcc dot gnu.org
2014-07-07 20:04 ` pault at gcc dot gnu.org
2014-07-08 19:51 ` pault at gcc dot gnu.org
2014-07-08 19:52 ` pault at gcc dot gnu.org

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).