User account creation filtered due to spam.

Bug 18026 - boz initialization of REALs fails
Summary: boz initialization of REALs fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 23074 29561 33001 33002 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2004-10-15 21:33 UTC by Harald Anlauf
Modified: 2014-02-16 13:16 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-02 11:09:35


Attachments
A simple program showing that initialization of BOZ constants fails in modules. (402 bytes, text/plain)
2006-05-12 13:05 UTC, Stephane Guilloteau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2004-10-15 21:33:54 UTC
Hi,

the following code does not compile with gfortran, although it does
with g77:

      PROGRAM GFCBUG19
      DOUBLE PRECISION inf, nan
c IEEE exceptional values on Intel x87
      DATA inf / Z'7FF0000000000000' /
      DATA nan / Z'FFF8000000000000' /
      print *, inf, nan
      END

% g77 gfcbug19.f -ftypeless-boz && ./a.out
  INF  NAN
% gfc gfcbug19.f -ftypeless-boz
f951: error: unrecognized command line option "-ftypeless-boz"
% gfc gfcbug19.f
 In file gfcbug19.f:4

      DATA inf / Z'7FF0000000000000' /                                  
                                   1
Error: Integer too big for integer kind 4 at (1)
 In file gfcbug19.f:5

      DATA nan / Z'FFF8000000000000' /                                  
                                   1
Error: Integer too big for integer kind 4 at (1)


Cheers,
-ha
Comment 1 Andrew Pinski 2004-10-15 23:15:27 UTC
Confirmed.
Comment 2 Tobias Schlüter 2005-03-13 19:05:38 UTC
While the compile-time error has disappeared, we now give the following
incorrect output at runtime:
[tobi@marktplatz tests]$ ./a.out
  9.218868437227405E+018  1.844449227389587E+019
[tobi@marktplatz tests]$         

The following testcase gives the expected result, though:
      PROGRAM GFCBUG19
      integer*8 infi, nani
      DOUBLE PRECISION inf, nan
      equivalence (infi, inf), (nani, nan)
!c IEEE exceptional values on Intel x87
      DATA infi / Z'7FF0000000000000' /
      DATA nani / Z'FFF8000000000000' /
      print *, inf, nan
      END
[tobi@marktplatz tests]$ ./a.out
               +Infinity                     NaN
[tobi@marktplatz tests]$       
Comment 3 kargl 2005-03-15 21:05:46 UTC
I've removed the "reject-valid" keyward because the code is not valid
Fortran 95.  From section 5.2.10, we have:

   If a data-statement-constant is a boz-literal-constant, the corresponding
   object shall be of type integer.  A data-stmt-constant that is a
   boz-literal-constant is treated as if the constant were an int-literal-
   constant with a kind-param that specifies the representation method with
   the largest decimal exponent range supported by the processor.
Comment 4 Andrew Pinski 2005-07-26 13:03:15 UTC
*** Bug 23074 has been marked as a duplicate of this bug. ***
Comment 5 Stephane Guilloteau 2006-05-12 13:05:03 UTC
Created attachment 11443 [details]
A simple program showing that initialization of BOZ constants fails in modules.

The test program shows initialization of BOZ constant failing when in a MODULE.
The initialization would work if the module code was put in a simple INCLUDE
file in Fortran-77 style. 

GNU Fortran 95 (GCC) 4.2.0 20060420 (experimental)
on Cygwin (April 2006 update)
Comment 6 kargl 2006-05-12 17:43:00 UTC
(In reply to comment #5)
> Created an attachment (id=11443) [edit]
> A simple program showing that initialization of BOZ constants
> fails in modules.
> 

Please read Comment #3.  Your code is invalid for several reasons.
Comment 7 Francois-Xavier Coudert 2006-10-02 11:09:35 UTC
If it's a regression wrt g77, then it's not an enhancement, it's a bug.
Comment 8 kargl 2006-10-02 16:47:15 UTC
Remove reject-valid keyword, again!
Return this to enhancement.

This is NOT a bug.  g77 compatibility and the Fortran 95 standard
have a conflict, and so IMNSHO the Fortran 95 standard wins.
See comment #3.  The Fortran 95 standard has quite explicit language
concerning how a BOZ is handled in a DATA statement, and that is what
gfortran implements.  A BOZ is handled consistently so that the
gfortran extension of allowing a BOZ in an assignment gives the same 
result as the DATA statement.

troutmask:kargl[204] cat a.f90
      PROGRAM GFCBUG19
      DOUBLE PRECISION y, x
      DATA x / Z'7FF0000000000000' /   ! Conforms to Fortran 95 standard
      y = Z'7FF0000000000000'          ! gfortran extension
      print *, x, y
      END
troutmask:kargl[205] gfc -o z a.f90
troutmask:kargl[206] ./z
  9.218868437227405E+018  9.218868437227405E+018

If someone wants to create a patch to implement a -fbroken-boz-behavior
option, then that's fine.  OTOH, the user can use the bit manipulation
functions and TRANSFER to create whatever bit pattern the user wants.
Or, the user can use the -fno-range-check option and simply compute
inf = 1./0. and nan = 0. / .0.

Comment 9 Harald Anlauf 2006-10-02 21:35:10 UTC
(In reply to comment #8)

> This is NOT a bug.  g77 compatibility and the Fortran 95 standard
> have a conflict, and so IMNSHO the Fortran 95 standard wins.

Gfortran unfortunately does not have a switch to compile legacy code
in a way that is sufficiently compatible with g77.
The (multiple) libraries that I use do use code similar to the
example in quite a few places.  I am not the author of these
libraries, I just use them.
Fortunately I can still use g77 on my platforms to compile the
relevant set of files.
Comment 10 Steve Kargl 2006-10-03 01:48:26 UTC
Subject: Re:  boz initialization of REALs fails

On Mon, Oct 02, 2006 at 09:35:11PM -0000, anlauf at gmx dot de wrote:
> 
> > This is NOT a bug.  g77 compatibility and the Fortran 95 standard
> > have a conflict, and so IMNSHO the Fortran 95 standard wins.
> 
> Gfortran unfortunately does not have a switch to compile legacy code
> in a way that is sufficiently compatible with g77.

Actually, gfortran does have -std=legacy.  It, unfortunately,
does not have code inside the appropriate IF statements to
do what you want.

> The (multiple) libraries that I use do use code similar to the
> example in quite a few places.  I am not the author of these
> libraries, I just use them.

Have you submitted bug reports to the authors of these libraries?

Comment 11 kargl 2006-10-23 17:10:13 UTC
*** Bug 29561 has been marked as a duplicate of this bug. ***
Comment 12 tobias.burnus 2006-10-23 18:52:04 UTC
Cf. also bug 29471.

In the Intel Fortran Compiler
 real :: r
 data r/some BOZ/
gives the same result as using the Fortran 2003 statement in ifort:
 real :: r
 r = real(some boz)
(At least with the "-switch fe_new_BOZ_constants".)

Therefore, with Fortran 2003 BOZ support in place, implementing this in gfortran should then become easier. (Working around will also become easier.(

(As gfortran accepts [integer] BOZ everywhere, it will also have the problem whether real( z'F' ) is meant as "convert integer BOZ to integer and then to real" or as "convert real BOZ to real". Ifort gives a default warning for both -stand f95 and -stand f03, treating the BOZ differently for those two cases.)
Comment 13 Steve Kargl 2006-10-23 19:39:32 UTC
Subject: Re:  boz initialization of REALs fails

On Mon, Oct 23, 2006 at 06:52:06PM -0000, tobias dot burnus at physik dot fu-berlin dot de wrote:
> 
> In the Intel Fortran Compiler
>  real :: r
>  data r/some BOZ/
> gives the same result as using the Fortran 2003 statement in ifort:
>  real :: r
>  r = real(some boz)
> (At least with the "-switch fe_new_BOZ_constants".)

(1) I'd need to see an example.
(2) The 2 code examples are technically invalid F95.
(3) The first code example is invalid in F2003.

> Therefore, with Fortran 2003 BOZ support in place, implementing this in
> gfortran should then become easier. (Working around will also become easier.(

gfortran implements the F2003 intrepetation of a BOZ in a data
statement.  See the BIG comment in match_boz_constant.   What is
missing is gfortran does not retain knowledge that a BOZ was seen,
so when you hit

real r
data r/some BOZ/

the "assignment" to r does not know the value can from a BOZ.  Hence,
a warning/error can't be issued.

> (As gfortran accepts [integer] BOZ everywhere, it will also have the problem
> whether real( z'F' ) is meant as "convert integer BOZ to integer and then to
> real" or as "convert real BOZ to real". Ifort gives a default warning for both
> -stand f95 and -stand f03, treating the BOZ differently for those two cases.)

I spent a few hours on Friday night and Saturday looking at the F2003
behavior for REAL(z'f').  My first attempt to handle this failed, which
I don't understand.  I have a plan B.

Comment 14 kargl 2007-08-06 17:30:22 UTC
*** Bug 33001 has been marked as a duplicate of this bug. ***
Comment 15 kargl 2007-08-06 17:32:34 UTC
*** Bug 33002 has been marked as a duplicate of this bug. ***
Comment 16 Tobias Burnus 2007-12-08 21:47:19 UTC
Subject: Bug 18026

Author: burnus
Date: Sat Dec  8 21:46:56 2007
New Revision: 130713

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130713
Log:
2007-12-08  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34342
        PR fortran/34345
        PR fortran/18026
        PR fortran/29471

        * gfortran.texi (BOZ literal constants): Improve documentation
        and adapt for BOZ changes.
        * Make-lang.ini (resolve.o): Add target-memory.h dependency.
        * gfortran.h (gfc_expr): Add is_boz flag.
        * expr.c: Include target-memory.h.
        (gfc_check_assign): Support transferring BOZ for real/cmlx.
        * resolve.c: Include target-memory.h
        (resolve_ordinary_assign): Support transferring BOZ for real/cmlx.
        * target-memory.c (gfc_convert_boz): New function.
        * target-memory.c (gfc_convert_boz): Add prototype.
        * primary.c (match_boz_constant): Set is_boz, enable F95 error
        also without -pedantic, and allow for Fortran 2003 BOZ.
        (match_real_constant): Fix comment.
        * simplify.c
        * (simplify_cmplx,gfc_simplify_dble,gfc_simplify_float,
        gfc_simplify_real): Support Fortran 2003 BOZ.

2007-12-08  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34342
        PR fortran/34345
        PR fortran/18026
        PR fortran/29471

        * gfortran.dg/boz_8.f90: New.
        * gfortran.dg/boz_9.f90: New.
        * gfortran.dg/boz_10.f90: New.
        * gfortran.dg/boz_7.f90: Update dg-warning.
        * gfortran.dg/pr16433.f: Add dg-error.
        * gfortan.dg/ibits.f90: Update dg-warning.
        * gfortran.dg/unf_io_convert_1.f90: Update/delete dg-warning.
        * gfortran.dg/unf_io_convert_2.f90: Ditto.


Added:
    trunk/gcc/testsuite/gfortran.dg/boz_10.f90
    trunk/gcc/testsuite/gfortran.dg/boz_8.f90
    trunk/gcc/testsuite/gfortran.dg/boz_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/Make-lang.in
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/boz_7.f90
    trunk/gcc/testsuite/gfortran.dg/ibits.f90
    trunk/gcc/testsuite/gfortran.dg/pr16433.f
    trunk/gcc/testsuite/gfortran.dg/unf_io_convert_1.f90
    trunk/gcc/testsuite/gfortran.dg/unf_io_convert_2.f90

Comment 17 Tobias Burnus 2007-12-08 22:09:07 UTC
Fixed on the trunk (4.3.0).

gfortran now transfers the BOZ in
      DATA inf / Z'7FF0000000000000' /
      DATA nan / Z'FFF8000000000000' /
bitwise to the real/complex variables (contrary to g77 without needing an option such as -ftypeless-boz).

Note: As this use of the BOZ is invalid Fortran 95 and 2003 syntax, it is rejected using -std=f95/-std=f2003.

gfortran now also supports the Fortran 2003 syntax:
 r = real(some boz)

For the exact description of the non-standard BOZ, see:
http://gcc.gnu.org/onlinedocs/gfortran/BOZ-literal-constants.html

(Wait a day for the update of that page.)
Comment 18 Jackie Rosen 2014-02-16 13:16:02 UTC Comment hidden (spam)