[PATCH]: Integrate gfortran with MPC

Steve Kargl sgk@troutmask.apl.washington.edu
Fri May 29 18:01:00 GMT 2009


On Thu, May 28, 2009 at 09:09:35PM -0700, Steve Kargl wrote:
> On Thu, May 28, 2009 at 04:04:41PM -0700, Kaveh R. Ghazi wrote:
> > From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
> > 
> > So I toyed with doing this conversion myself and the testcase
> > gfortran.dg/real_const_3.f90 started failing on lines 45 and 48.  I traced
> > it to the compile-time evaluation of these variables.  I think it happens in
> > gfc_arith_divide.
> > 
> >  complex :: z = (-0.1,-2.2)/(0.0,0.0)
> >  complex :: z2 = (0.1,1)/0
> > 
> > The above lines currently transform into NaN in gfortran and that's what the
> > testcase expects.  MPC, MPFR (and C) turn finite/zero into Inf.  Only
> > zero/zero turns into NaN.
> > 
> > I'm wondering if it was really meant for fortran to be different, or is this
> > a bug accidentally immortalized in the testcase?  I.e. what does the fortran
> > standard say?
> > 
> 
> Andrew's correct in that the Fortran standard does not
> address Inf or NaN unless one is using Fortran 2003's
> IEEE intrinsic module. 
> 
> I suspect that this is bug that has been immortalized in
> the testsuite.  It should probably be fixed to give the
> result that an equivalent C program would give.  Can you
> open a bug report and add me to cc?

There appears to be a middle-end issue here as well.  Consider,
the following program:

program d
   implicit none
   complex z1, z2
   real r1
   z1 = (1.,2.)
   z2 = (0.,0.)
   r1 = 0.
   call sub1(z1, z2)
   call sub2(z1, r1)
end program d

subroutine sub1(z1, z2)
   implicit none
   complex z1, z2
   complex :: z3 = (1.,2.) / (0.,0.) ! gfortran folds this.
   print '(4F8.0)', z1 / z2, z3      ! z1/z2 in middle-end?
end subroutine sub1
 
subroutine sub2(z1, r1)
   implicit none
   real r1
   complex z1
   complex :: z3 = (1.,2.) / 0.   ! gfortran folds this.
   print '(4F8.0)', z1 / r1, z3   ! z1/r1 in middle-end?
end subroutine sub2

troutmask:sgk[204] gfc4x -o z -fdump-tree-original -fno-range-check d.f90
troutmask:sgk[205] ./z
     NaN     NaN     NaN     NaN
     NaN     NaN     NaN     NaN

Striping out the IO stuff from the dump, gfortran produces

d ()
{
  real(kind=4) r1;
  complex(kind=4) z1;
  complex(kind=4) z2;
  static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 0};

  _gfortran_set_options (8, (void *) &options.0);
  z1 = __complex__ (1.0e+0, 2.0e+0);
  z2 = __complex__ (0.0, 0.0);
  r1 = 0.0;
  sub1 (&z1, &z2);
  sub2 (&z1, &r1);
}

sub1 (complex(kind=4) & z1, complex(kind=4) & z2)
{
  static complex(kind=4) z3 = __complex__ ( Nan,  Nan);

  {
    {
      complex(kind=4) D.1535;

      D.1535 = *z1 / *z2;
      _gfortran_transfer_complex (&dt_parm.1, &D.1535, 4);
    }
    _gfortran_transfer_complex (&dt_parm.1, &z3, 4);
    _gfortran_st_write_done (&dt_parm.1);
  }
}

sub2 (complex(kind=4) & z1, real(kind=4) & r1)
{
  static complex(kind=4) z3 = __complex__ ( Nan,  Nan);

  {
    {
      complex(kind=4) D.1545;

      D.1545 = *z1 / COMPLEX_EXPR <*r1, 0.0>;
      _gfortran_transfer_complex (&dt_parm.2, &D.1545, 4);
    }
    _gfortran_transfer_complex (&dt_parm.2, &z3, 4);
    _gfortran_st_write_done (&dt_parm.2);
  }
}


 
-- 
Steve



More information about the Gcc-patches mailing list