https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82143

--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Fri, Sep 08, 2017 at 12:31:12PM +0000, janus at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82143
> 
> --- Comment #3 from janus at gcc dot gnu.org ---
> (In reply to kargl from comment #2)
> > Actaully, the -fdefault-real* and -fdefault-integer-* options
> > should be deprecated.  These options are broken by design,
> 
> I don't know what that means. And no one else does, because
> the documentation does not say anything about it.
> 
> > and probably do not do what one wants.
> 
> That depends on what you want, I guess. What they do is documented rather
> clearly, isn't it? So, people with reading abilities should be able
> to use them without any surprises.

I wrote the code for those options.  Although it may appear to
work for a typical user, these options have some underlying 
issues.  I submitted a patch a few years ago to deprecate the
options.  That did not go over too well.

One the big hidden issues that typical users never consider is
storage association.  When -fdefault-real-8 promotes REAL to
DOUBLE PRECISION and DOUBLE PRECISION to REAL(16), there was 
an attempt to maintain storage assocation.  This as done too
naively.

> > Use the -freal-4-real-16 (and similar options).
> 
> > From the documentation of those options it sounds like they only
> > affect variables with explicit kind declaration, but not those
> > with implicit / default kind.
> 
> If that is true, they are not able to fully replace the unbeloved
> -fdefault-real-* options.
> 
> If it is not true, obviously the documentation needs to be improved.

The best way to fix the documentation is to remove the -fdefault-*
options, and then the documentation can be removed.

> > % cat cat a.f90 
> > program foo
> >    real x
> >    x = 1. / 3.
> >    print *, x
> > end program foo
> > %  gfortran6 -static -o z a.f90 && ./z
> >   0.333333343    
> > % gfortran6 -static -o z -freal-4-real-16 a.f90 && ./z
> >   0.333333333333333333333333333333333317
> 
> Your test case seems to suggest that the latter of the two aforementioned
> options is true. From earlier experiments I believe I remember the opposite,
> though. So either the implementation has changed over time, or I'm just
> misremembering ...

-freal-4-real-16 promotes everything that should have been a REAL(4)
to a REAL(16).  -fdefault-real-8 promotes some things that are REAL(4)
to REAL(8), and if available it promotes some things from REAL(8) to
REAL(16).  Here's a different program with an implicitly typed REAL(4)
variable, explicitly typed 1._4, 1._8, and implicitly typed 1.

program foo
   real x
   double precision y
   a = 1._4 / 3
   x = 1._4 / 3
   y = 1._8 / 3
   print *, a
   print *, x
   print *, y
   a = 1. / 3
   x = 1. / 3
   y = 1. / 3
   print *, a
   print *, x
   print *, y
end program foo

Let SP mean 'single precision' and DP mean 'double precision', you
then have

% gfortran6 -static -o z a.f90 && ./z
  0.333333343                             explicit SP 1. on rhs
  0.333333343                             explicit SP 1. on rhs
  0.33333333333333331                     explicit DP 1. on rhs
  0.333333343                             implicit SP 1. on rhs 
  0.333333343                             implicit SP 1. on rhs
  0.33333334326744080                     implicit SP 1. on rhs

% gfortran6 -static -o z a.f90 -fdefault-real-8 && ./z
  0.33333334326744080                     explicit SP 1. retains REAL(4) nature
  0.33333334326744080                     explicit SP 1. retains REAL(4) nature 
  0.333333333333333314829616256247390993  REAL(8) promoted to REAL(16)    
  0.33333333333333331                     implicit SP 1. becomes DP 1.
  0.33333333333333331                     implicit SP 1. becomes DP 1.
  0.333333333333333314829616256247390993  implicit SP 1. becomes DP 1.
                                          REAL(8) promoted to REAL(16)

% gfortran6 -static -o z a.f90 -freal-4-real-8 && ./z
  0.33333333333333331     Everything promoted from REAL(4) to REAL(8)
  0.33333333333333331     Ditto
  0.33333333333333331     REAL(8) is not promoted to REAL(16)    
  0.33333333333333331     Everything promoted from REAL(4) to REAL(8)
  0.33333333333333331     Everything promoted from REAL(4) to REAL(8)
  0.33333333333333331     REAL(8) is not promoted to REAL(16)

% gfortran6 -static -o z a.f90 -freal-4-real-16 && ./z
  0.333333333333333333333333333333333317     All REAL(4) promoted to REAL(16) 
  0.333333333333333333333333333333333317     Ditto
  0.33333333333333331                        REAL(8) is not changed by option
  0.333333333333333333333333333333333317     All REAL(4) promoted to REAL(16)
  0.333333333333333333333333333333333317     Ditto
  0.33333333333333331                        REAL(8) is not changed by option

Reply via email to