From patchwork Wed Jan 15 16:37:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1223714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517454-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=DaobyYjc; 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 47yY0825PLz9sR0 for ; Thu, 16 Jan 2020 03:37:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=mx5deqw/KdWWVkF2vaVTrpd9uPgF86cayrvR5UetKa7pyRnmBO CYSmBoCgFAXt/mC0Pdy2N67mtx9LmkyXKuXOK7X6bmUpLq8P15eY3iW0hqgVd1LP xWzgPXZ+D16IVJrOEBM89ppyQ+LlWAsDqyhNfGBF9jJ1riKD/8nbzQEeU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=hCPfRqvbXmYy3QK83wpTHMeSst0=; b=DaobyYjchNQdl9I+0Vf8 AkKBNzDpcjqsb3p1LP0KWp0ue5wTRigFM/BFq2yhRMMOHz2O93TOPYL1uDMrnm6B zYPCNvjP4+yyr242NpjYm/N5PGJNkINKHrprY1Jms46v5JmdQ8Vk3MxlNjQ9N6L1 UCQE4Z0IyA3K/EVXVrQS9rg= Received: (qmail 55972 invoked by alias); 15 Jan 2020 16:37:34 -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 55940 invoked by uid 89); 15 Jan 2020 16:37:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.7 required=5.0 tests=AWL, BAYES_00, GARBLED_SUBJECT, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HTo:U*gerald, sk:binary, sk:binary- X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Jan 2020 16:37:23 +0000 IronPort-SDR: BJZu6EWTc5LzKoOtdJIrGgPaKYtEHvtjywHIdubTmDkrvtL410HHkMF1yKZfWWRkyAJe2treby wq9X6aozCwHd8kU7CAI1qno9JxHcEQw0EaElK5WmJUhQLJcjgmqGYmcuyvLscF3tNnEnag0AVP 5k7/+umkZnrQvOWo2tmmhF1cthS/KwC0kjlOEX2slM0VtXsToDxuAKLhcoGmtWwP3qJ99ikktz DU0YtqQ7Xr35lsYlIhXi4MzfdLj+p8m8Eyy4PQt+kfxD6JJqTyJ7EvpgKO9IRSsLSuoYbPpCow gRI= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 15 Jan 2020 08:37:20 -0800 IronPort-SDR: vgayJjvuvZHbVkfYhiWFfwrtHFrmeUQGVftYR3OngUxZhFsa7NNTKoRaXJ2b6LMbVRScQGm7Dy hiaEpKOk6L7HmpoZrhXySGAr417D/4A0s7lnS25+767XKJKT6l3zO/10+9etro3U6ngIObScGJ REVHJ69pXKlLXmG6y5bMt28qgpTHgol6sRrDgrlGsxoqA3jV8dDCMOowKLfMZ321eu+nAGSZ6m 02j11Sbc//vkxMUXQUakAoxJxSqpf9LIUk6mAxjkyLEQHgtBDjjn55QZv2Ff+0EfE0z0tUOJGh Mgs= To: gcc-patches , fortran , Gerald Pfeifer From: Tobias Burnus Subject: =?utf-8?q?=5BPatch=2C_Fortran_+_wwwdocs=5D_PR93253_=E2=80=93_Doc?= =?utf-8?q?ument_BOZ_changes=2C_make_it_friendlier_in_legacy_code?= Message-ID: <1f9fd9f3-8170-d654-33fe-4b2350ecea1e@codesourcery.com> Date: Wed, 15 Jan 2020 17:37:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 X-IsSubscribed: yes Fortran before 2013 only allowed binary-octal-hex values (BOZ literals) in DATA statements; Fortran 2013 extended it to support them also as argument to INT(), REAL() etc. — Additionally, various compilers (including gfortran) support more as (legacy) extension. Diagnostic: DATA vs. non DATA usage was/is diagnosed with -std=f95 ("Error: Fortran 2003: …"). Using "X" instead of "Z" for hexadecimals was/is diagnosed (accepted: before GCC 10 with -std=legacy, now with -fallow-invalid-boz). However, GCC 9 and older silently accepted nonstandard use, e.g. "print *, Z'A'" – even with -std=f2003/f2008! Since GCC 10, it is now rejected unless -fallow-invalid-boz is used. Main issue: While gfortran 10 still documents the BOZ extensions, neither the extension documentation nor the error message nor point to -fallow-invalid-boz – and the release notes is completely silent regarding BOZ. Hence, I included two patches: * The WWWDOCS patch now mentions the change in GCC 10. * The Fortran patch does: (a) Mention 'X' in the flag documentation (as it is not in an invalid context but just an invalid letter). (b) Tweak error message for 'X' to state how to fix it. (c) When both -std=legacy and -fallow-invalid-boz has been used, it no longer prints a warning; for -std=gnu and -std=f... (+ -fallow…) we still do. (d) If -std=legacy has been used without -fallow-invalid-boz, it now suggests to use -fallow…, but only if fixing is not possible. I hope with this patch, that using the compiler is more user friendly but still giving the intensive to actually fix the legacy code. Are the two patches OK – for wwwdocs and for the trunk, respectively? Tobias PR fortran/93253 * check.c (gfc_invalid_boz): With -std=legacy, suggest the new -fallow-invalid-boz flag. With -std=legacy and that flag, no longer warn. * gfortran.texi (BOZ literal constants): List another missing extension and refer to -fallow-invalid-boz. * lang.opt (fallow-invalid-boz): Also mention 'X' in the help text as it is not covered by the previous wording. * primary.c (match_boz_constant): Tweak wording such that it is clear how to fix the nonstandard use. PR fortran/93253 * fortran.dg/boz_7.f90: Updated dg-error. diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index c7f0187b377..f03764abaef 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -56,18 +56,30 @@ reset_boz (gfc_expr *x) gfc_invalid_boz() is a helper function to simplify error/warning generation. gfortran accepts the nonstandard 'X' for 'Z', and gfortran allows the BOZ indicator to appear as a suffix. If -fallow-invalid-boz - is used, then issue a warning; otherwise issue an error. */ + is used, then issue a warning (unless -std=legacy); otherwise issue an + error. */ bool gfc_invalid_boz (const char *msg, locus *loc) { if (flag_allow_invalid_boz) { - gfc_warning (0, msg, loc); + if (gfc_option.warn_std & GFC_STD_LEGACY) + gfc_warning (0, msg, loc); return false; } - gfc_error (msg, loc); + if (!(gfc_option.warn_std & GFC_STD_LEGACY)) + { + const char hint[] = ". Use %<-fallow-invalid-boz%> if you cannot fix it"; + size_t len = strlen (msg) + strlen (hint) + 1; + char *msg2 = (char *) alloca (len); + strcpy (msg2, msg); + strcat (msg2, hint); + gfc_error (msg2, loc); + } + else + gfc_error (msg, loc); return true; } diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 4cf8b3a5c24..98fc74f3e67 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -1863,9 +1863,11 @@ Fortran standard states that the treatment of the sign bit is processor dependent. Gfortran interprets the sign bit as a user would expect. As a deprecated extension, GNU Fortran allows hexadecimal BOZ literal -constants to be specified using the @code{X} prefix. The BOZ literal +constants to be specified using the @code{X} prefix. That the BOZ literal constant can also be specified by adding a suffix to the string, for -example, @code{Z'ABC'} and @code{'ABC'X} are equivalent. +example, @code{Z'ABC'} and @code{'ABC'X} are equivalent. And BOZ literals +outside @code{DATA} and the intrinsic functions listed in the Fortran +standard. Use @option{-fallow-invalid-boz} to enable the extension. @node Real array indices @subsection Real array indices diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 3858331bcc0..59523f74acf 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -387,7 +387,7 @@ All intrinsics procedures are available regardless of selected standard. fallow-invalid-boz Fortran RejectNegative Var(flag_allow_invalid_boz) -Allow a BOZ literal constant to appear in an invalid context. +Allow a BOZ literal constant to appear in an invalid context and with X instead of Z. fallow-leading-underscore Fortran Undocumented Var(flag_allow_leading_underscore) diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index e2b6fcb2106..07b8ac08ba2 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -433,7 +433,7 @@ match_boz_constant (gfc_expr **result) if (x_hex && gfc_invalid_boz ("Hexadecimal constant at %L uses " - "nonstandard syntax", &gfc_current_locus)) + "nonstandard X instead of Z", &gfc_current_locus)) return MATCH_ERROR; old_loc = gfc_current_locus; diff --git a/gcc/testsuite/gfortran.dg/boz_7.f90 b/gcc/testsuite/gfortran.dg/boz_7.f90 index 45fa7a7df19..d2a51ac03e2 100644 --- a/gcc/testsuite/gfortran.dg/boz_7.f90 +++ b/gcc/testsuite/gfortran.dg/boz_7.f90 @@ -7,6 +7,6 @@ ! integer :: k, m integer :: j = z'000abc' ! { dg-error "BOZ used outside a DATA statement" } -data k/x'0003'/ ! { dg-error "nonstandard syntax" } +data k/x'0003'/ ! { dg-error "nonstandard X instead of Z" } data m/'0003'z/ ! { dg-error "nonstandard postfix" } end