From patchwork Sun Sep 17 20:42:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 814700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-462339-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IQz/WZGM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xwLfn4TVvz9s7m for ; Mon, 18 Sep 2017 06:42:24 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=wzrvvFrSVCfthHwlwWRWpWAreci6ACvSMLPAy1qebW8hlc NRM6+O0AStG17l7heoSJGIV1EkcHkmelbAQlFB7QzDwju+SYcO68HgfihZCl372u dv4NHM7Cnxi7jltQW8NXvtxBAZtM7k7tz8K0pILrsoobPnp45jxIgGmzNs4D8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=rZWqrhAXhPRh0pYBOemK0UVFaoc=; b=IQz/WZGMx7a7rpNCHl0e d0js4U1kUJV/S+CDsUDAXgbUxYd3zqFGRhaRkEUT7N10hBebAoYMh1Vagd4m7Z9G p3uwz+OpTJfIkuwl+oeJitTiJYubtwsV5HuIGSyFIn9asJHjH4typnuQ4Rhh7mlM mzXvIaqEUVzBt1m8HOvd+Ds= Received: (qmail 129636 invoked by alias); 17 Sep 2017 20:42:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129610 invoked by uid 89); 17 Sep 2017 20:42:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=dislikes, dollar X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 17 Sep 2017 20:42:04 +0000 Received: by mail-yw0-f171.google.com with SMTP id x131so4027174ywa.10; Sun, 17 Sep 2017 13:42:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=t7BRRhBnMA8PReN5ixQ9Ss5h+vswaTMtXPXsmxniwn4=; b=d3d0Jn6MYOLk3BdhihZa1Ay+5qlKcCHBwv/qjGPeRHe1J+A2T1TNBQIOeSBo3XTZOo 5txagS9cAp8narm/YOKldi8HNS6pvneFNSwLb+cFevDTvAgoNoO97F1/3XZxk9xd6mAm TBrxh9SVZMWYK9AFkfP8fTgbCmgvxnLNy9EdkqCa70USMX0MwI9smmIVCRH95XUvrWI+ rjUhMFbLE/SdKhnlcluOPK05p0Z/KVAx76sm1aUOEJD7nnLFP6Kau6t51ceWPmnliWKY L414B7lNCpI5iDp9udc8DWALcRaQXZ66i19anuugtnPqgh5CJTzkQCJwFE5uWdZwThQs XqVA== X-Gm-Message-State: AHPjjUhqEDTGYuIZ0aocrRNgWQtG0/fO9mjyTDYhvI3or33EeMW/tgsq 3pQXupVyMNIyoyxaLT+VHylxMM0KCB8RcpRj2BjP/w== X-Google-Smtp-Source: AOwi7QADqxcp6yaU7vdcL6V6C572PoubKm/K+m32BWS1z61ZAU3sMS4YROKRyHAH67WMcKTsJ772sR7nYoJWF8F0N6E= X-Received: by 10.37.15.4 with SMTP id 4mr10330823ybp.49.1505680922344; Sun, 17 Sep 2017 13:42:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.162.148 with HTTP; Sun, 17 Sep 2017 13:42:01 -0700 (PDT) From: Janus Weil Date: Sun, 17 Sep 2017 22:42:01 +0200 Message-ID: Subject: [Patch, Fortran] PR 82143: add a -fdefault-real-16 flag To: gfortran , gcc-patches Hi all, attached is a (technically) simple patch that implements the compiler flag "-fdefault-real-16" for gfortran. I know that there is some opposition against this, but I am proposing it anyway, because I do think it is useful after all. My reasoning is as follows: 1) Despite tons of -freal-X-real-Y flags, there currently is no way to only promote the default real kind to real(16). 2) Since a variable of default REAL kind does not specify a KIND value explicitly, it is quite natural for a compiler to control this by means of flags. 3) gfortran already has -fdefault-real-8 (which is used in lots of real-world codes AFAIK) and does support quad-precision variables. 4) Other compilers do have flags for this as well (e.g. ifort's "-real-size 128" etc). 5) I know that it is possible, any maybe cleaner, to declare variables with explicit kinds instead of relying on compiler flags, but for large and historically grown codes it is not always straightforward to do this right away. 6) The patch does not modify the default behavior of gfortran. 7) No one who dislikes such compiler flags is forced to use them. 8) I don't see how this flag can cause any harm. It adds additional possibilities of using the compiler and thus makes gfortran more powerful (and more compatible with other compilers). The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2017-09-17 Janus Weil PR fortran/82143 * lang.opt: Add the option -fdefault-real-16. * invoke.texi: Add documentation for -fdefault-real-16. * trans-types.c (gfc_init_kinds): Implement -fdefault-real-16. 2017-09-17 Janus Weil PR fortran/82143 * gfortran.dg/promotion_3.f90: New test case. Index: gcc/fortran/invoke.texi =================================================================== --- gcc/fortran/invoke.texi (revision 252892) +++ gcc/fortran/invoke.texi (working copy) @@ -120,7 +120,7 @@ by type. Explanations are in the following sectio -fd-lines-as-comments @gol -fdec -fdec-structure -fdec-intrinsic-ints -fdec-static -fdec-math @gol -fdefault-double-8 -fdefault-integer-8 @gol --fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol +-fdefault-real-8 -fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol -ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol -ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol -fmax-identifier-length -fmodule-private -ffixed-form -fno-range-check @gol @@ -404,6 +404,14 @@ the default width of @code{DOUBLE PRECISION} to 16 @code{-fdefault-double-8} is given, too. Unlike @option{-freal-4-real-8}, it does not promote variables with explicit kind declaration. +@item -fdefault-real-16 +@opindex @code{fdefault-real-16} +Set the default real type to a 16 byte wide type. This option also affects +the kind of non-double real constants like @code{1.0}, and does promote +the default width of @code{DOUBLE PRECISION} to 16 bytes if possible, unless +@code{-fdefault-double-8} is given. Unlike @option{-freal-4-real-16}, +it does not promote variables with explicit kind declaration. + @item -fdefault-double-8 @opindex @code{fdefault-double-8} Set the @code{DOUBLE PRECISION} type to an 8 byte wide type. Do nothing if this Index: gcc/fortran/lang.opt =================================================================== --- gcc/fortran/lang.opt (revision 252892) +++ gcc/fortran/lang.opt (working copy) @@ -460,6 +460,10 @@ fdefault-real-8 Fortran Var(flag_default_real) Set the default real kind to an 8 byte wide type. +fdefault-real-16 +Fortran Var(flag_default_real_16) +Set the default real kind to an 16 byte wide type. + fdollar-ok Fortran Var(flag_dollar_ok) Allow dollar signs in entity names. Index: gcc/fortran/trans-types.c =================================================================== --- gcc/fortran/trans-types.c (revision 252892) +++ gcc/fortran/trans-types.c (working copy) @@ -538,6 +538,14 @@ gfc_init_kinds (void) gfc_default_real_kind = 8; } + else if (flag_default_real_16) + { + if (!saw_r16) + gfc_fatal_error ("REAL(KIND=16) is not available for " + "%<-fdefault-real-16%> option"); + + gfc_default_real_kind = 16; + } else if (flag_real4_kind == 8) { if (!saw_r8) @@ -577,7 +585,7 @@ gfc_init_kinds (void) if (flag_default_real && flag_default_double && saw_r8) gfc_default_double_kind = 8; - else if (flag_default_real && saw_r16) + else if ((flag_default_real || flag_default_real_16) && saw_r16) gfc_default_double_kind = 16; else if (flag_real8_kind == 4) {