public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop
@ 2010-10-13 14:55 burnus at gcc dot gnu.org
  2010-10-13 15:30 ` [Bug fortran/46007] " mikael at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-10-13 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: wrong code for SHAPE in a scalarized loop
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: mikael@gcc.gnu.org, arjen.markus@deltares.nl


Reported by Arjen at http://gcc.gnu.org/ml/fortran/2010-10/msg00153.html

Reduced test case:

    integer, dimension(10)             :: int1d
    integer, dimension(:), pointer     :: int1d_retrieved

    allocate(int1d_retrieved(10))
    if (any(shape(int1d_retrieved) /= shape(INT1D))) call abort()
    end

It crashes (segfault) at run time for the IF condition.

First analysis:


    struct array1_integer(kind=4) atmp.1;
    atmp.1.dtype = 265;
    atmp.1.data = 0B;
    atmp.1.offset = 0;
    D.1529 = &int1d_retrieved;
    _gfortran_shape_4 (&atmp.1, D.1529);

The problem is that the bounds are not set - but _gfortran_shape tries to acces
the lbound/ubound via:

    if (GFC_DESCRIPTOR_EXTENT(ret,0) < 1)

Additionally, it tries to set the value via:
      ret->data[n * stride] = extent > 0 ? extent : 0 ;
which fails as ret->data alias "atmp.1.data" is not allocated.


Interestingly, if one uses:
      tmp = shape(int1d_retrieved)
one has:
    integer(kind=4) A.1[1];
    atmp.0.dim[0].lbound = 0;
    atmp.0.dim[0].ubound = 0;
    atmp.0.data = (void * restrict) &A.1;
    _gfortran_shape_4 (&atmp.0, D.1525);

which works. For some reason (scalarizer?) .data is not allocated/associated
and the bounds are not set for the first test case.


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

* [Bug fortran/46007] wrong code for SHAPE in a scalarized loop
  2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
@ 2010-10-13 15:30 ` mikael at gcc dot gnu.org
  2010-10-16 19:00 ` tkoenig at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mikael at gcc dot gnu.org @ 2010-10-13 15:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Mikael Morin <mikael at gcc dot gnu.org> 2010-10-13 15:30:06 UTC ---
(In reply to comment #0)
> Interestingly, if one uses:
>       tmp = shape(int1d_retrieved)
> one has:
>     integer(kind=4) A.1[1];
>     atmp.0.dim[0].lbound = 0;
>     atmp.0.dim[0].ubound = 0;
>     atmp.0.data = (void * restrict) &A.1;
>     _gfortran_shape_4 (&atmp.0, D.1525);
> 
> which works. For some reason (scalarizer?) .data is not allocated/associated
> and the bounds are not set for the first test case.

The difference is probably (I haven't checked) that with the assignment, one
uses gfc_trans_arrayfunc_assign, which prevents the creation of a temporary for
the return value. 
But I think it is valid to pass unallocated descriptors. The called function
takes care of allocating the array data and filling the descriptor in that
case. 
I have tried with matmul for example and it works basically.


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

* [Bug fortran/46007] wrong code for SHAPE in a scalarized loop
  2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
  2010-10-13 15:30 ` [Bug fortran/46007] " mikael at gcc dot gnu.org
@ 2010-10-16 19:00 ` tkoenig at gcc dot gnu.org
  2010-10-21 12:25 ` tkoenig at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2010-10-16 19:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2010.10.16 18:59:57
                 CC|                            |tkoenig at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2010-10-16 18:59:57 UTC ---
(In reply to comment #1)

> But I think it is valid to pass unallocated descriptors. The called function
> takes care of allocating the array data and filling the descriptor in that
> case. 
> I have tried with matmul for example and it works basically.

Yes, this is valid and is done in a lot of places in the library.
Obviously, we missed shape when doing this.

I'll make a patch (should be trivial).


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

* [Bug fortran/46007] wrong code for SHAPE in a scalarized loop
  2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
  2010-10-13 15:30 ` [Bug fortran/46007] " mikael at gcc dot gnu.org
  2010-10-16 19:00 ` tkoenig at gcc dot gnu.org
@ 2010-10-21 12:25 ` tkoenig at gcc dot gnu.org
  2010-10-21 13:02 ` tkoenig at gcc dot gnu.org
  2010-10-21 13:06 ` tkoenig at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2010-10-21 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2010-10-21 12:25:23 UTC ---
Author: tkoenig
Date: Thu Oct 21 12:25:12 2010
New Revision: 165770

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165770
Log:
2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46007
    * m4/shape.m4 (shape_'rtype_kind`):  Use variable for rank.
    Allocate return array if unallocated.
    * generated/shape_i4.c:  Regenerated.
    * generated/shape_i8.c:  Regenerated.
    * generated/shape_i16.c:  Regenerated.

2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46007
    * gfortran.dg/shape_5.f90:  New test case.


Added:
    trunk/gcc/testsuite/gfortran.dg/shape_5.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/generated/shape_i16.c
    trunk/libgfortran/generated/shape_i4.c
    trunk/libgfortran/generated/shape_i8.c
    trunk/libgfortran/m4/shape.m4


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

* [Bug fortran/46007] wrong code for SHAPE in a scalarized loop
  2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2010-10-21 12:25 ` tkoenig at gcc dot gnu.org
@ 2010-10-21 13:02 ` tkoenig at gcc dot gnu.org
  2010-10-21 13:06 ` tkoenig at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2010-10-21 13:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2010-10-21 13:02:15 UTC ---
Author: tkoenig
Date: Thu Oct 21 13:02:09 2010
New Revision: 165773

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165773
Log:
2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46007
    Backport from trunk
    * m4/shape.m4 (shape_'rtype_kind`):  Use variable for rank.
    Allocate return array if unallocated.
    * generated/shape_i4.c:  Regenerated.
    * generated/shape_i8.c:  Regenerated.
    * generated/shape_i16.c:  Regenerated.

2010-10-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46007
    Backport from trunk
    * gfortran.dg/shape_5.f90:  New test case.


Added:
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/shape_5.f90
Modified:
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/libgfortran/ChangeLog
    branches/gcc-4_5-branch/libgfortran/generated/shape_i16.c
    branches/gcc-4_5-branch/libgfortran/generated/shape_i4.c
    branches/gcc-4_5-branch/libgfortran/generated/shape_i8.c
    branches/gcc-4_5-branch/libgfortran/m4/shape.m4


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

* [Bug fortran/46007] wrong code for SHAPE in a scalarized loop
  2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2010-10-21 13:02 ` tkoenig at gcc dot gnu.org
@ 2010-10-21 13:06 ` tkoenig at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2010-10-21 13:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2010-10-21 13:05:55 UTC ---
Fixed on trunk and 4.5.  Closing.


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

end of thread, other threads:[~2010-10-21 13:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-13 14:55 [Bug fortran/46007] New: wrong code for SHAPE in a scalarized loop burnus at gcc dot gnu.org
2010-10-13 15:30 ` [Bug fortran/46007] " mikael at gcc dot gnu.org
2010-10-16 19:00 ` tkoenig at gcc dot gnu.org
2010-10-21 12:25 ` tkoenig at gcc dot gnu.org
2010-10-21 13:02 ` tkoenig at gcc dot gnu.org
2010-10-21 13:06 ` tkoenig 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).