From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10906 invoked by alias); 10 Jul 2013 17:42:09 -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 10870 invoked by uid 48); 10 Jul 2013 17:42:05 -0000 From: "kargl at gcc dot 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: Wed, 10 Jul 2013 17:42: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: kargl at gcc dot gnu.org 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: bug_status cf_reconfirmed_on cc resolution everconfirmed 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/msg00616.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57871 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Last reconfirmed| |2013-07-10 CC| |kargl at gcc dot gnu.org Resolution|INVALID |--- Ever confirmed|0 |1 --- Comment #2 from kargl at gcc dot gnu.org --- (In reply to Dominique d'Humieres from comment #1) > > gfortran 4.8.1 -freal-4-real-16 gives real(16) kind with > > selected_real_kind(1) but it ought to give real(8) because that is > > the smallest decimal precision available with that compiler option. > > and your example does exactly that: Closing as INVALID. I think that you may have been a little too hasty in closing this PR. The issue lies in the code for selected_real_kind. 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) for (i = 0; gfc_real_kinds[i].kind != 0; i++) { if (gfc_real_kinds[i].precision >= precision) found_precision = 1; if (gfc_real_kinds[i].range >= range) found_range = 1; if (gfc_real_kinds[i].radix >= radix) found_radix = 1; if (gfc_real_kinds[i].precision >= precision && gfc_real_kinds[i].range >= range && gfc_real_kinds[i].radix >= radix && gfc_real_kinds[i].kind < kind) kind = gfc_real_kinds[i].kind; } 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).