public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/48746] New: Matmul with allocate on assignment
@ 2011-04-23 22:08 tkoenig at gcc dot gnu.org
  2011-04-27  6:05 ` [Bug fortran/48746] " jpr at csc dot fi
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-04-23 22:08 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Matmul with allocate on assignment
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tkoenig@gcc.gnu.org
                CC: pault@gcc.gnu.org


The following program crashes with a double free on current trunk:

program main
  implicit none

  integer, parameter :: m=10, n=12, count=4
  double precision :: optmatmul(m, n)
  double precision :: a(m, count), b(count, n), c(m, n)
  double precision, dimension(:,:), allocatable :: tmp
  call random_number(a)
  call random_number(b)
  tmp = matmul(a,b)
end program main

Paul, if you happen to have any idea...


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

* [Bug fortran/48746] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
@ 2011-04-27  6:05 ` jpr at csc dot fi
  2011-04-27  6:59 ` [Bug fortran/48746] [4.6/4.7 Regression] " burnus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jpr at csc dot fi @ 2011-04-27  6:05 UTC (permalink / raw)
  To: gcc-bugs

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

jpr at csc dot fi changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jpr at csc dot fi

--- Comment #1 from jpr at csc dot fi 2011-04-27 05:56:57 UTC ---
Problem here is that the return array "dtype" field is uninitialized when
lhs is (unallocated) allocatable. Due to this there are also similiar
problems in other intrinsics such as reshape(), etc...


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
  2011-04-27  6:05 ` [Bug fortran/48746] " jpr at csc dot fi
@ 2011-04-27  6:59 ` burnus at gcc dot gnu.org
  2011-04-27 15:05 ` tkoenig at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-04-27  6:59 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |burnus at gcc dot gnu.org
   Target Milestone|---                         |4.6.1
            Summary|Matmul with allocate on     |[4.6/4.7 Regression] Matmul
                   |assignment                  |with allocate on assignment

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-04-27 06:58:21 UTC ---
I think the PR is related to PR 48462, though the issue mentioned here is not
covered there.


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
  2011-04-27  6:05 ` [Bug fortran/48746] " jpr at csc dot fi
  2011-04-27  6:59 ` [Bug fortran/48746] [4.6/4.7 Regression] " burnus at gcc dot gnu.org
@ 2011-04-27 15:05 ` tkoenig at gcc dot gnu.org
  2011-04-27 15:11 ` tkoenig at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-04-27 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.04.27 14:58:54
     Ever Confirmed|0                           |1

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-04-27 14:58:54 UTC ---
(In reply to comment #1)
> Problem here is that the return array "dtype" field is uninitialized when
> lhs is (unallocated) allocatable. Due to this there are also similiar
> problems in other intrinsics such as reshape(), etc...

Interesting observation.  This works:

program main
  implicit none
  integer, parameter :: m=10, n=12, count=4
  double precision :: a(m, count), b(count, n), c(m, n)
  double precision, dimension(:,:), allocatable :: tmp

  call random_number(a)
  call random_number(b)
  allocate (tmp(3,3))
  deallocate(tmp)
  tmp = matmul(a,b)
end program main


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-04-27 15:05 ` tkoenig at gcc dot gnu.org
@ 2011-04-27 15:11 ` tkoenig at gcc dot gnu.org
  2011-04-28 10:58 ` tkoenig at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-04-27 15:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-04-27 15:07:21 UTC ---
(In reply to comment #3)
> (In reply to comment #1)
> > Problem here is that the return array "dtype" field is uninitialized when
> > lhs is (unallocated) allocatable. Due to this there are also similiar
> > problems in other intrinsics such as reshape(), etc...
> 
> Interesting observation.  This works:

... well, for a given value of "works".  tmp keeps its size of 3*3.


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-04-27 15:11 ` tkoenig at gcc dot gnu.org
@ 2011-04-28 10:58 ` tkoenig at gcc dot gnu.org
  2011-04-29 20:32 ` pault at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-04-28 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-04-28 10:52:51 UTC ---
The problem is that matmul calls size0, which depends on correct
rank information in the dtype field.

Should be easy enough to fix by adding a default initializer
for the dtype field, if only anybody knew where to look...

Paul?


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-04-28 10:58 ` tkoenig at gcc dot gnu.org
@ 2011-04-29 20:32 ` pault at gcc dot gnu.org
  2011-04-30 11:16 ` tkoenig at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2011-04-29 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> 2011-04-29 20:26:59 UTC ---
Author: pault
Date: Fri Apr 29 20:26:56 2011
New Revision: 173185

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173185
Log:
2011-04-29  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48462
    * trans-expr.c (arrayfunc_assign_needs_temporary): Deal with
    automatic reallocation when the lhs is a target.

    PR fortran/48746
    * trans-expr.c (fcncall_realloc_result): Make sure that the
    result dtype field is set before the function call.

2011-04-29  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48462
    * gfortran.dg/realloc_on_assign_7.f03: Modify to test for lhs
    being a target.

    PR fortran/48746
    * gfortran.dg/realloc_on_assign_7.f03: Add subroutine pr48746.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/realloc_on_assign_7.f03


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-04-29 20:32 ` pault at gcc dot gnu.org
@ 2011-04-30 11:16 ` tkoenig at gcc dot gnu.org
  2011-04-30 11:47 ` pault at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-04-30 11:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-04-30 11:12:29 UTC ---
Hi Paul,

the least I can do is to supply you with a more complete test case :-)

program main
  implicit none
  integer, parameter :: m=4, n=3, count=2
  double precision :: a(m, count), b(count, n), c(m,n)
  double precision, dimension(:,:), allocatable :: tmp

  data a /1.d0, -2.d0, 4.d0, -8.d0, 16.d0, -32.d0, 64.d0, -128.d0/
  data b /256.d0, -512.d0, 1024.d0, -2048.d0, 4096.d0, -8182.d0 /
  data c/  -7936.d0,  15872.d0, -31744.d0,  63488.d0, -31744.d0,  &
           63488.d0,-126976.d0, 253952.d0,-126816.d0, 253632.d0, &
           -507264.d0,1014528.d0/

  tmp = matmul(a,b)
  if (size(tmp,1) /= 4 .or. size(tmp,2) /= 3) call abort
  if (any (tmp /= c)) call abort
end program main


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-04-30 11:16 ` tkoenig at gcc dot gnu.org
@ 2011-04-30 11:47 ` pault at gcc dot gnu.org
  2011-04-30 12:01 ` pault at gcc dot gnu.org
  2011-04-30 12:14 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2011-04-30 11:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> 2011-04-30 11:46:34 UTC ---
Author: pault
Date: Sat Apr 30 11:46:31 2011
New Revision: 173213

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173213
Log:
2011-04-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48746
    * trans-expr.c (fcncall_realloc_result): Set the bounds and the
    offset so that the lbounds are one.
    (gfc_trans_arrayfunc_assign): Add rank to arguments of above.

2011-04-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48746
    * gfortran.dg/realloc_on_assign_7.f03: Test bounds.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/realloc_on_assign_7.f03


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2011-04-30 11:47 ` pault at gcc dot gnu.org
@ 2011-04-30 12:01 ` pault at gcc dot gnu.org
  2011-04-30 12:14 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2011-04-30 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> 2011-04-30 12:00:53 UTC ---
Author: pault
Date: Sat Apr 30 12:00:50 2011
New Revision: 173214

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173214
Log:
2011-04-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48462
    PR fortran/48746
    * trans-expr.c ( arrayfunc_assign_needs_temporary): Need a temp
    if automatic reallocation on assignement is active, the lhs is a
    target and the rhs an intrinsic function.
    (realloc_lhs_bounds_for_intrinsic_call): Rename as next.
    (fcncall_realloc_result): Renamed version of above function.
    Free the original descriptor data after the function call.Set the bounds
and the
    offset so that the lbounds are one.
    (gfc_trans_arrayfunc_assign): Call renamed function.

2011-04-30  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/48462
    PR fortran/48746
    * gfortran.dg/realloc_on_assign_7.f03: New test.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/realloc_on_assign_7.f03
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog


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

* [Bug fortran/48746] [4.6/4.7 Regression] Matmul with allocate on assignment
  2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2011-04-30 12:01 ` pault at gcc dot gnu.org
@ 2011-04-30 12:14 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2011-04-30 12:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Paul Thomas <pault at gcc dot gnu.org> 2011-04-30 12:06:07 UTC ---
Fixed on trunk at 4.6

Thanks for the report.

Paul


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

end of thread, other threads:[~2011-04-30 12:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-23 22:08 [Bug fortran/48746] New: Matmul with allocate on assignment tkoenig at gcc dot gnu.org
2011-04-27  6:05 ` [Bug fortran/48746] " jpr at csc dot fi
2011-04-27  6:59 ` [Bug fortran/48746] [4.6/4.7 Regression] " burnus at gcc dot gnu.org
2011-04-27 15:05 ` tkoenig at gcc dot gnu.org
2011-04-27 15:11 ` tkoenig at gcc dot gnu.org
2011-04-28 10:58 ` tkoenig at gcc dot gnu.org
2011-04-29 20:32 ` pault at gcc dot gnu.org
2011-04-30 11:16 ` tkoenig at gcc dot gnu.org
2011-04-30 11:47 ` pault at gcc dot gnu.org
2011-04-30 12:01 ` pault at gcc dot gnu.org
2011-04-30 12:14 ` 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).