Bug 35960 - run time abort with assignment of RESHAPEd zero sized array
Summary: run time abort with assignment of RESHAPEd zero sized array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-04-16 21:18 UTC by Dick Hendrickson
Modified: 2008-04-20 20:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-04-17 21:58:22


Attachments
proposed patch (855 bytes, patch)
2008-04-19 14:11 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2008-04-16 21:18:59 UTC
Each line of the following subroutine causes a run-time
abort. Except for the one labeled gf1069.  It works if
literal constants are used in place of the nf* variables.

Dick Hendrickson

      program try_gf1065


! fails on Windows XP
! gcc version 4.4.0 20080312 (experimental) [trunk revision 133139]


      call       gf1065(1,  2,  3,  4,  7,  8,  9)
      end

      SUBROUTINE GF1065(nf1,nf2,nf3,nf4,nf7,nf8,nf9)
!        also 1066 thru 1070, 1069 works

      REAL RDA(10,9)
      REAL RCA1(90)
      integer ila(2)
!gf1065
      RDA(NF9:NF8, NF7:NF3) = RESHAPE(RCA1,(/0,0/), (/1.0/),(/2,1/))
      print *, 'gf1065'

!gf1066
      rDA(NF9:NF8, NF7:NF3) = RESHAPE(rCA1,(/0,0/),ORDER=(/2,1/))
      print *, 'gf1066'

      ILA(1) = 5
      ILA(2) = 0
!gf1067
      rDA(NF4:NF8, NF7:NF3) = RESHAPE(rcA1,ILA)
      print *, 'gf1067'

!gf1068
      RdA(NF4:NF8, NF7:NF3) = RESHAPE(RcA1,ILA,PAD=(/-1.0/))
      print *, 'gf1068'

      ILA(1) = 0
      ILA(2) = 5
!gf1069    this one works
      RdA(NF9:NF8,NF4:NF8)=RESHAPE(RcA1,ILA,(/-1.0/),(/NF2,NF1/))
      print *, 'gf1069'

      ILA(1) = 5
      ILA(2) = 0
!gf1070
      RdA(NF4:NF8, NF7:NF3) = RESHAPE(RcA1,ILA,ORDER=(/NF1,NF2/))
      print *, 'gf1070'


      END SUBROUTINE


C:\gfortran:gfortran gf1065.f

C:\gfortran:a
Fortran runtime error: shape and target do not conform
Comment 1 Thomas Koenig 2008-04-17 21:58:22 UTC
Confirmed.

I'll take a look at this.
Comment 2 Thomas Koenig 2008-04-19 11:29:37 UTC
We don't check for empty arrays in reshape.

Should be fairly straightforward.
Comment 3 Thomas Koenig 2008-04-19 14:11:37 UTC
Created attachment 15496 [details]
proposed patch

Here's a patch.

I'll regression-test and commit tomorrow, probably.
Comment 4 Thomas Koenig 2008-04-20 19:56:53 UTC
Subject: Bug 35960

Author: tkoenig
Date: Sun Apr 20 19:56:07 2008
New Revision: 134490

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134490
Log:
2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/35960
	* intrinsics/reshape_generic.c (reshape_internal): If the size
	of the resized array is zero, as determined by the SHAPE
	argument, return early.
	* m4/reshape.m4:  Likewise.
	* generated/reshape_i4.c:  Regererated.
	* generated/reshape_i8.c:  Regenerated.
	* generated/reshape_i16.c:  Regenerated.
	* generated/reshape_r4.c:  Regenerated.
	* generated/reshape_r8.c:  Regenerated.
	* generated/reshape_r10.c:  Regenerated.
	* generated/reshape_r16.c:  Regenerated.
	* generated/reshape_c4.c:  Regenerated.
	* generated/reshape_c8.c:  Regenerated.
	* generated/reshape_c10.c:  Regenerated.
	* generated/reshape_c16.c:  Regenerated.

2008-04-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/35960
	* gfortran.dg/reshape_zerosize_1.f90:  New file.


Added:
    trunk/gcc/testsuite/gfortran.dg/reshape_zerosize_1.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/generated/reshape_c10.c
    trunk/libgfortran/generated/reshape_c16.c
    trunk/libgfortran/generated/reshape_c4.c
    trunk/libgfortran/generated/reshape_c8.c
    trunk/libgfortran/generated/reshape_i16.c
    trunk/libgfortran/generated/reshape_i4.c
    trunk/libgfortran/generated/reshape_i8.c
    trunk/libgfortran/generated/reshape_r10.c
    trunk/libgfortran/generated/reshape_r16.c
    trunk/libgfortran/generated/reshape_r4.c
    trunk/libgfortran/generated/reshape_r8.c
    trunk/libgfortran/intrinsics/reshape_generic.c
    trunk/libgfortran/m4/reshape.m4

Comment 5 Thomas Koenig 2008-04-20 20:07:45 UTC
Fixed on trunk (no need to backport this to 4.3).

Closing.
Comment 6 Thomas Koenig 2008-04-25 20:12:09 UTC
Subject: Bug 35960

Author: tkoenig
Date: Fri Apr 25 20:11:19 2008
New Revision: 134677

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134677
Log:
2008-04-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/35960
	* m4/reshape.m4:  Fix typo in last commit.
	* generated/reshape_i4.c:  Regererated.
	* generated/reshape_i8.c:  Regenerated.
	* generated/reshape_i16.c:  Regenerated.
	* generated/reshape_r4.c:  Regenerated.
	* generated/reshape_r8.c:  Regenerated.
	* generated/reshape_r10.c:  Regenerated.
	* generated/reshape_r16.c:  Regenerated.
	* generated/reshape_c4.c:  Regenerated.
	* generated/reshape_c8.c:  Regenerated.
	* generated/reshape_c10.c:  Regenerated.
	* generated/reshape_c16.c:  Regenerated.


Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/generated/reshape_c10.c
    trunk/libgfortran/generated/reshape_c16.c
    trunk/libgfortran/generated/reshape_c4.c
    trunk/libgfortran/generated/reshape_c8.c
    trunk/libgfortran/generated/reshape_i16.c
    trunk/libgfortran/generated/reshape_i4.c
    trunk/libgfortran/generated/reshape_i8.c
    trunk/libgfortran/generated/reshape_r10.c
    trunk/libgfortran/generated/reshape_r16.c
    trunk/libgfortran/generated/reshape_r4.c
    trunk/libgfortran/generated/reshape_r8.c
    trunk/libgfortran/m4/reshape.m4