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

* [Bug fortran/61459] segfault when assigning to allocatable function result from matmul result
  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 ` 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
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gmx dot de @ 2014-06-09 21:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #1 from Harald Anlauf <anlauf at gmx dot de> ---
Version 4.5.2 works, version 4.6.0 fails.
Clearly a regression.


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

* [Bug fortran/61459] [4.7/4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  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 ` 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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-06-09 22:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-06-09
                 CC|                            |pault at gcc dot gnu.org
            Summary|segfault when assigning to  |[4.7/4.8/4.9/4.10
                   |allocatable function result |Regression] segfault when
                   |from matmul result          |assigning to allocatable
                   |                            |function result from matmul
                   |                            |result
     Ever confirmed|0                           |1

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
The code gives the expected output up to r167173 (2010-11-26), an ICE from
r167380 (2010-12-02) up to r184438 (2012-02-21), and a segmentation fault from
r184852 (2012-03-03) up to trunk (4.10.0, r211378).

The first change may be due to r167220 (pr35810). The second one may be due to
r184651 (pr52386). Both are wild guesses.


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  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 ` rguenth at gcc dot gnu.org
  2014-07-06  9:20 ` tkoenig at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-06-25 11:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.4


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (2 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2014-07-06  9:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tkoenig at gcc dot gnu.org

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
The debugger shows that retarray is NULL on the call to matmul_r4.
Clearly, this is not supposed to happen.

Program received signal SIGSEGV, Segmentation fault.
_gfortran_matmul_r4 (retarray=0x0, a=0x7fffffffd730, b=0x7fffffffd700,
try_blas=0, blas_limit=0, gemm=0x0) at
../../../trunk/libgfortran/generated/matmul_r4.c:104
104       if (retarray->base_addr == NULL)

I am  a bit baffled by this, because this looks correct if you look at the use
of the variable D.2357.

      struct array1_real(kind=4) D.2357;
      D.2357 = *(struct array1_real(kind=4) *) __result;
      D.2357.data = 0B;
      _gfortran_matmul_r4 (*(struct array1_real(kind=4) * *) &D.2357, D.2384,
D.2391, 0, 0, 0B);
      ((struct array1_real(kind=4) *) __result)->data = D.2357.data;
      D.2360 = ((((struct array1_real(kind=4) *) __result)->dim[0].lbound -
D.2357.dim[0].lbound) - ((struct array1_real(kind=4) *)
__result)->dim[0].ubound) + D.2357.dim[0].ubound != 0;
      ((struct array1_real(kind=4) *) __result)->dim[0].ubound =
D.2357.dim[0].ubound + D.2362;


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (3 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2014-07-06 14:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 33077
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33077&action=edit
Fix for the PR

This regtests OK for dg.exp=gfortran.dg/alloc* so I presume that it is OK. Am
regtesting the whole testsuite right now.

2014-07-06  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    * trans-expr.c (fcncall_realloc_result): Use the natural type
    for the address expression of 'res_desc'.
2014-07-06  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    * gfortran.dg/allocatable_function_8.f90 : New test


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-07-06 16:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

--- Comment #5 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
AFAICT the patch also fixes pr58883.


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2014-07-07 20:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Mon Jul  7 20:00:49 2014
New Revision: 212338

URL: https://gcc.gnu.org/viewcvs?rev=212338&root=gcc&view=rev
Log:
2014-07-07  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * trans-expr.c (fcncall_realloc_result): Use the natural type
    for the address expression of 'res_desc'.

2014-07-07  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * gfortran.dg/allocatable_function_8.f90 : New test

Added:
   
branches/gcc-4_9-branch/gcc/testsuite/gfortran.dg/allocatable_function_8.f90
Modified:
    branches/gcc-4_9-branch/gcc/fortran/ChangeLog
    branches/gcc-4_9-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2014-07-07 20:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Mon Jul  7 20:04:05 2014
New Revision: 212339

URL: https://gcc.gnu.org/viewcvs?rev=212339&root=gcc&view=rev
Log:
2014-07-07  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * trans-expr.c (fcncall_realloc_result): Use the natural type
    for the address expression of 'res_desc'.

2014-07-07  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * gfortran.dg/allocatable_function_8.f90 : New test

Added:
    trunk/gcc/testsuite/gfortran.dg/allocatable_function_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2014-07-08 19:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

--- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Tue Jul  8 19:51:04 2014
New Revision: 212369

URL: https://gcc.gnu.org/viewcvs?rev=212369&root=gcc&view=rev
Log:
2014-07-08  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * trans-expr.c (fcncall_realloc_result): Use the natural type
    for the address expression of 'res_desc'.

2014-07-08  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/61459
    PR fortran/58883
    * gfortran.dg/allocatable_function_8.f90 : New test

Added:
   
branches/gcc-4_8-branch/gcc/testsuite/gfortran.dg/allocatable_function_8.f90
Modified:
    branches/gcc-4_8-branch/gcc/fortran/ChangeLog
    branches/gcc-4_8-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog


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

* [Bug fortran/61459] [4.8/4.9/4.10 Regression] segfault when assigning to allocatable function result from matmul result
  2014-06-09 20:45 [Bug fortran/61459] New: segfault when assigning to allocatable function result from matmul result johnww at tds dot net
                   ` (8 preceding siblings ...)
  2014-07-08 19:51 ` pault at gcc dot gnu.org
@ 2014-07-08 19:52 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2014-07-08 19:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61459

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on 4.8, 4.9 and trunk.

Thanks for the report

Paul


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