[PATCH] Fix for PR fortran/21375

Steve Kargl sgk@troutmask.apl.washington.edu
Sun Jun 5 18:20:00 GMT 2005


On Sun, Jun 05, 2005 at 06:46:12PM +0100, Paul Brook wrote:
> > See attached patch (for a fun exercise in hacking).
> > Bootstrapped and regression tested on i386-*-freebsd.
> > ChangeLog entries for patch and test case are the
> > same as in the first email of the thread.
> 
> >+       apstat = gfc_build_addr_expr (NULL, astat);
> >+       apstat = build_int_cst (gfc_int4_type_node, 0);
> 
> This looks wrong. Assigning to a variable then immediately overwriting its 
> value.

Whoops.  The  build_int_cst () is left over from an 
earlier attempt to intialize astat.  The second line
should be deleted.

> Presumably there should be some library changes to go with this patch?

No.  The library already generated a 0 (for success) or 1 (for failure).
We simply never implemented the STAT= part of deallocate in trans-*.[ch].
Currently, a NULL pointer is passed as the 2nd argument to 
_gfortran_deallocate, so the STAT= is always ignored.

> It would also be nice to have a comment that explained (in C or pseudocode) 
> what we the code we generate should look like.

There are comments in the code.  The relevant one is

+       /* Keep track of the number of failed deallocations.  */

Consider

   program d1
     implicit none
     integer i
     real, allocatable :: b1(:), b2(:,:)
     allocate(b1(2), b2(2,2))
     b1 = 1. ; b2 = 2.
     deallocate(b1,     stat=i)
     deallocate(b2, b1, stat=i)
   end program d1

-fdump-tree-original shows (with comments added by me):

  /* First deallocate statement */
  {
    int4 astat.4;
    int4 stat.3;
    {
      real4[0:] * * ptr.5;
      ptr.5 = &b1.data;
      _gfortran_deallocate (ptr.5, &stat.3);
    }
    astat.4 = stat.3;  /* seen = 0, so initialize astat.4 to the 1st  */
                       /* return value from gfortran_deallocate.      */
    i = astat.4;       /* Set the STAT= value.  */
  }

  /* Second deallocate statement. */
  {
    int4 astat.7;
    int4 stat.6;
    /* deallocate b1 */
    {
      real4[0:] * * ptr.8;
      ptr.8 = &b2.data;
      _gfortran_deallocate (ptr.8, &stat.6);
    }
    astat.7 = stat.6;  /* seen = 0, so initialize astat.7 to the 1st  */
                       /* return value from gfortran_deallocate.      */
    /* deallocate b2 */
    {
      real4[0:] * * ptr.9;
      ptr.9 = &b1.data;
      _gfortran_deallocate (ptr.9, &stat.6);
    }
    astat.7 = astat.7 + stat.6;  /* Add the next return value.  */

    i = astat.7;  /* Set the STAT= value. */
  }

-- 
Steve



More information about the Gcc-patches mailing list