Bug 52884 - double precision constants promoted to 16 byte by -fdefault-real-8
Summary: double precision constants promoted to 16 byte by -fdefault-real-8
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 89078
  Show dependency treegraph
 
Reported: 2012-04-05 21:50 UTC by steven.vancoillie
Modified: 2019-01-30 15:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-01-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description steven.vancoillie 2012-04-05 21:50:56 UTC
Contrary to what the man pages say, double precision constants like '1.d0' get promoted to 16 bytes when using -fdefault-real-8 (without -fdefault-double-8).  The man pages at the section of -fdefault-double-8 say however that -fdefault-real-8 does not promote constants like that.  Is this an error in the man pages?

From the man pages:

-fdefault-double-8
           Set the "DOUBLE PRECISION" type to an 8 byte wide type.
           If -fdefault-real-8 is given, "DOUBLE PRECISION" would instead be
           promoted to 16 bytes if possible, and -fdefault-double-8 can be used
           to prevent this.  The kind of real constants like "1.d0" will not be
           changed by -fdefault-real-8 though, so also -fdefault-double-8 does
           not affect it.

Using e.g. the following program:

program doubletrouble
real*8 x
double precision y
write(*,*) kind(x), kind(y), kind(1.d0)
end

Compiling without any options gives '8 8 8' as output.  Compiling with -fdefault-real-8 gives '8 16 16', while I expected it to be '8 16 8' based on the documentation.

This is with gfortran 4.7.0 on Linux x86_64 (Intel Core i5 M 540)
Comment 1 Dominique d'Humieres 2014-01-07 14:25:30 UTC
If I replace kind(1.d0) with kind(1.0_8), I get '8 16 8' with -fdefault-real-8.

I am in favor to replace 'does promote the default width of DOUBLE PRECISION to 16 bytes if possible' with something such as 'does promote the default width of DOUBLE PRECISION to 16 bytes if possible, as well as double real constants like 1.d0' and 'The kind of real constants like "1.d0"' with 'The kind of real constants like "1.0_8"'.
Comment 2 Dominique d'Humieres 2016-04-06 21:40:30 UTC
I am planning to submit the following patch

--- ../_clean/gcc/fortran/invoke.texi	2016-03-13 09:07:16.000000000 +0100
+++ gcc/fortran/invoke.texi	2016-04-06 20:44:26.000000000 +0200
@@ -361,9 +361,10 @@ it does not promote variables with expli
 @opindex @code{fdefault-double-8}
 Set the @code{DOUBLE PRECISION} type to an 8 byte wide type.  Do nothing if this
 is already the default.  If @option{-fdefault-real-8} is given,
-@code{DOUBLE PRECISION} would instead be promoted to 16 bytes if possible, and
+@code{DOUBLE PRECISION} would instead be promoted to 16 bytes if possible,
+as well as double real constants like @code{1.d0}, and
 @option{-fdefault-double-8} can be used to prevent this.  The kind of real
-constants like @code{1.d0} will not be changed by @option{-fdefault-real-8}
+constants like @code{1.0_8} will not be changed by @option{-fdefault-real-8}
 though, so also @option{-fdefault-double-8} does not affect it.
 
 @item -finteger-4-integer-8
Comment 3 Jerry DeLisle 2016-04-11 01:27:49 UTC
May I suggest the following wording:

-fdefault-real-8
    Set the default real type to an 8 byte wide type. This option
    also affects the kind of non-double real constants like 1.0.
    This option promotes the default width of DOUBLE PRECISION
    and double real constants like 1.d0 to 16 bytes if possible.
    If -fdefault-double-8 is given along with -fdefault-real-8,
    DOUBLE PRECISION and double real constants are not promoted.
    Note, -fdefault-real-8, does not promote variables with explicit
    kind declarations.

-fdefault-double-8
    Set the DOUBLE PRECISION type to an 8 byte wide type. Do nothing
    if this is already the default. This option prevents -fdefault-real-8
    from promoting DOUBLE PRECISION and double real constants like 1.d0
    to 16 bytes.
Comment 4 Dominique d'Humieres 2019-01-27 14:20:39 UTC
Patch submitted at https://gcc.gnu.org/ml/fortran/2019-01/msg00251.html.
Comment 5 dominiq 2019-01-30 15:54:22 UTC
Author: dominiq
Date: Wed Jan 30 15:53:51 2019
New Revision: 268396

URL: https://gcc.gnu.org/viewcvs?rev=268396&root=gcc&view=rev
Log:
2019-01-30  Dominique d'Humieres  <dominiq@gcc.gnu.org>

	PR fortran/52884
	* invoke.texi: Document the promotion of double precision
	constants.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/invoke.texi
Comment 6 Dominique d'Humieres 2019-01-30 15:58:38 UTC
Closing.