Bug 38859 - [4.3 Regression] ubound and lbound treat structure component references as whole arrays
[4.3 Regression] ubound and lbound treat structure component references as wh...
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.4.0
: P4 normal
: 4.3.4
Assigned To: Not yet assigned to anyone
: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2009-01-15 19:47 UTC by Dick Hendrickson
Modified: 2009-01-26 05:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.1 4.1.3
Known to fail: 4.3.0 4.3.2 4.4.0
Last reconfirmed: 2009-01-15 20:04:20


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dick Hendrickson 2009-01-15 19:47:35 UTC
The UBOUND and LBOUND intrinsics treat a reference to an array structure component as if they were inquires on a whole array.  

Dick Hendrickson


       program try_jg_15_18

! fails on Windows XP
! gcc version 4.4.0 20081219 (experimental) [trunk revision 142842] (GCC)

       type x
         integer I
       end type x
       type (x) A(0:5, 2:8)
       integer ida(2)

       ida = lbound(a)
       if (any(ida /= (/0,2/))) print *, 'base array', ida

!note that a%i is neither a whole array nor an array structure component

       ida = lbound(a%i)
       if (any(ida /= (/1,1/))) print *, 'lbound    ', ida

       ida = ubound(a)
       if (any(ida /= (/6,7/))) print *, 'ubound    ', ida

       end


C:\gfortran>gfortran try_jg_15_18.f

C:\gfortran>a
 lbound               0           2
 ubound               5           8
Comment 1 Tobias Burnus 2009-01-15 20:04:19 UTC
Confirm. This is a regression with regards to 4.2.1; it fails at least since 20071008 (my oldest 4.3 trunk version).

Thanks for the report!
Comment 2 Tobias Burnus 2009-01-15 20:10:58 UTC
       ida = lbound(a%i)
       if (any(ida /= (/1,1/))) print *, 'lbound    ', ida

Here, gfortran prints:
   lbound  0  2
Correct would be
   lbound  1  1


       ida = ubound(a)
>>>>>>>>>>>>>>>>>>>^^^
Here a "%i" is missing otherwise the following line does not make sense:

       if (any(ida /= (/6,7/))) print *, 'ubound    ', ida

For ubound(a) the result should be "5 8" which is also gfortran's result.
For ubound(a%i):
  gfortran: 5 8
  correct:  6 7
Comment 3 Mikael Morin 2009-01-15 21:30:45 UTC
quick fix:

Index: simplify.c
===================================================================
--- simplify.c	(révision 143354)
+++ simplify.c	(copie de travail)
@@ -2253,7 +2253,8 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gf
 	    case AR_FULL:
 	      /* We're done because 'as' has already been set in the
 		 previous iteration.  */
-	      goto done;
+	      if (!ref->next)
+	        goto done;
 
 	    case AR_SECTION:
 	    case AR_UNKNOWN:
Comment 4 Mikael Morin 2009-01-17 14:59:59 UTC
shouldn't this be fixed for 4.3.3?
Comment 5 Tobias Burnus 2009-01-17 15:45:46 UTC
> shouldn't this be fixed for 4.3.3?
Too late - the release is too soon (freeze; release-candidate build is running). Regarding 4.4.0: Do you plan to submit a patch soonish?
Comment 6 Mikael Morin 2009-01-19 22:19:47 UTC
Subject: Bug 38859

Author: mikael
Date: Mon Jan 19 22:19:34 2009
New Revision: 143501

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143501
Log:
2009-01-19  Mikael Morin  <mikael.morin@tele2.fr>

	PR fortran/38859
	* simplify.c (simplify_bound): Don't use array specification
	if variable or component has subsequent references.

2009-01-19  Mikael Morin  <mikael.morin@tele2.fr>

	PR fortran/38859
	* gfortran.dg/bound_5.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/bound_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Paul Thomas 2009-01-20 05:54:56 UTC
Ticked off 4.4...:-)

Cheers

Paul
Comment 8 Paul Thomas 2009-01-26 05:43:55 UTC
Subject: Bug 38859

Author: pault
Date: Mon Jan 26 05:43:44 2009
New Revision: 143670

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143670
Log:
2009-01-26  Mikael Morin  <mikael.morin@tele2.fr>

        PR fortran/38859
	Backport from trunk
        * simplify.c (simplify_bound): Don't use array specification
        if variable or component has subsequent references.

2009-01-26  Mikael Morin  <mikael.morin@tele2.fr>

        PR fortran/38859
	Backport from trunk
        * gfortran.dg/bound_5.f90: New test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/bounds_5.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/simplify.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 9 Paul Thomas 2009-01-26 05:44:56 UTC
Closed on trunk and 4.3.

Once again, thanks for the report.

Paul