From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23139 invoked by alias); 10 Jul 2013 20:02:56 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23075 invoked by uid 55); 10 Jul 2013 20:02:45 -0000 From: "sgk at troutmask dot apl.washington.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/57871] gfortran -freal-4-real-16 gives wrong result for selected_real_kind(1) Date: Wed, 10 Jul 2013 20:02:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: REOPENED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-07/txt/msg00624.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57871 --- Comment #3 from Steve Kargl --- 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.