public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "harper at msor dot vuw.ac.nz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/57871] gfortran -freal-4-real-16 gives wrong result for selected_real_kind(1)
Date: Thu, 11 Jul 2013 22:30:00 -0000 [thread overview]
Message-ID: <bug-57871-4-5WbR7YGqa8@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57871-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57871
--- Comment #5 from harper at msor dot vuw.ac.nz ---
I have now found two more oddities of type promotion but I don't claim
that these are gfortran bugs, only that the mmanual might need amending.
Oddity 1. Although -freal-4-real-8 does what the manual implies with
the program below (making the real kinds 8,10,16 on an x86_64 system),
-fdefault-real-8 keeps the available kinds at 4,8,10,16 but merely
changes the defaults. I suggest that the following sentence
be added to the manual sewction on -fdefault-real-8 at the end:
If "REAL(KIND=4)" is a real type available with no -f options, then it
remains available with -fdefault-real-8 though not with -freal-4-real-8.
Oddity 2. If one uses -fdefault-double-8 in a system where default real
was 4 bytes wide then one must also use -fdefault-real-8. The manual
entries for -fdefault-double-8 and -fdefault-real-8 are both silent
on what happens if -fdefault-double-8 is given but -fdefault-real-8 is
not. I won't suggest an amendment here because I don't know what happens
in a system whose default real with no -f options was 8 bytes wide.
Evidence:
cayley[~/Jfh] % cat gfkinds.f90
implicit none
real xdefault
real(4 ) x4
real(8 ) x8
real(10) x10
real(16) x16
print *,kind(xdefault),kind(x4),kind(x8),kind(x10),kind(x16)
end
cayley[~/Jfh] % gf -freal-4-real-8 gfkinds.f90
cayley[~/Jfh] % ./a.out
8 8 8 10 16
cayley[~/Jfh] % gf -fdefault-real-8 gfkinds.f90
cayley[~/Jfh] % ./a.out
8 4 8 10 16
cayley[~/Jfh] % gf -fdefault-double-8 gfkinds.f90
<built-in>:0:0: fatal error: Use of -fdefault-double-8 requires
-fdefault-real-8
compilation terminated.
cayley[~/Jfh] % alias gf
/local/scratch/gf/bin/gfortran
cayley[~/Jfh] % gf -v
Using built-in specs.
COLLECT_GCC=/local/scratch/gf/bin/gfortran
COLLECT_LTO_WRAPPER=/local/scratch/gf/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /local/scratch/gcc-4.8-20130530/configure
--prefix=/local/scratch/gf --enable-languages=c,fortran --disable-libada
--with-local-prefix=/local/scratch --with-gmp=/local/scratch
Thread model: posix
gcc version 4.8.1 20130530 (prerelease) (GCC)
cayley[~/Jfh] %
On Wed, 10 Jul 2013, sgk at troutmask dot apl.washington.edu wrote:
> Date: Wed, 10 Jul 2013 20:02:43 +0000
> From: sgk at troutmask dot apl.washington.edu <gcc-bugzilla@gcc.gnu.org>
> To: john.harper@vuw.ac.nz
> Subject: [Bug fortran/57871] gfortran -freal-4-real-16 gives wrong result for
> selected_real_kind(1)
> Resent-Date: Wed, 10 Jul 2013 20:02:59 +0000
> Resent-From: <john.harper@vuw.ac.nz>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57871
>
> --- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
> On Wed, Jul 10, 2013 at 05:42:03PM +0000, kargl at gcc dot gnu.org wrote:
>> implicit none
>> integer,parameter:: p1 = selected_real_kind(1)
>>
>> This initialization expression is requesting the type with
>> smallest precision that exceeds 1. With -freal-4-real-16,
>> that type is double precision (ie kind=8). The problem
>> lies in gfc_simplify_selected_real_kind. It has no knowledge
>> of the -freal-*-real-* options. The loop (lines 5447-5457)
>
> (remove loop code)
>
>> searchs the ordered set [24, 53, 53, 113] (on FreeBSD-i386) or
>> [24, 53, 64, 113] (on FreeBSD-amd64). In either case, the
>> initialization expression returns REAL(4). However, with
>> -freal-4-real-16, one might expect the ordered set to be
>> searched is [113, 53, 64, 113] as REAL(4) has been promoted
>> to REAL(16).
>
> The results of running John's code are odder than what one
> might expect.
>
> The normal results:
>
> % gfc4x -o foo foo.f90 && ./foo
> kind(1.0_p1) 4 precision(1.0_p1) 6
> kind(1.0_dp) 8 precision(1.0_dp) 15
>
> One might expect the first line to be 8 and 15, respectively.
>
> % gfc4x -o foo foo.f90 -freal-4-real-16 && ./foo
> kind(1.0_p1) 16 precision(1.0_p1) 33
> kind(1.0_dp) 8 precision(1.0_dp) 15
>
> Here the default real kind is promoted to REAL(8), but literal
> constants declared with a kind type suffix are not promoted.
> The first line is the correct output, although one might
> anticipate 8 and 15. But, what may be surprising is that the
> double precision kind has been bumped to quad precision.
>
> troutmask:sgk[207] gfc4x -o foo foo.f90 -fdefault-real-8 && ./foo
> kind(1.0_p1) 4 precision(1.0_p1) 6
> kind(1.0_dp) 16 precision(1.0_dp) 33
>
> I've always hated these type options as a lzy programmer's
> crutch who refuses to properly port an algorithm from
> one precision to another.
>
> --
> You are receiving this mail because:
> You reported the bug.
>
>
>
-- John Harper, School of Mathematics Statistics and Operations Research
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5276 fax (+64)(4)463 5045
next prev parent reply other threads:[~2013-07-11 22:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-09 23:38 [Bug fortran/57871] New: " john.harper at vuw dot ac.nz
2013-07-10 13:07 ` [Bug fortran/57871] " dominiq at lps dot ens.fr
2013-07-10 17:42 ` kargl at gcc dot gnu.org
2013-07-10 20:02 ` sgk at troutmask dot apl.washington.edu
2013-07-10 21:31 ` harper at msor dot vuw.ac.nz
2013-07-11 22:30 ` harper at msor dot vuw.ac.nz [this message]
2013-07-11 22:51 ` sgk at troutmask dot apl.washington.edu
2013-11-25 0:59 ` kargl at gcc dot gnu.org
2021-03-04 11:59 ` dominiq at lps dot ens.fr
2021-03-05 9:43 ` cvs-commit at gcc dot gnu.org
2021-03-05 9:53 ` burnus at gcc dot gnu.org
2021-03-07 13:19 ` dominiq at lps dot ens.fr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-57871-4-5WbR7YGqa8@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).