From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] PR fortran/91650 -- BOZ cannot be an output IO list item
Date: Tue, 03 Sep 2019 19:57:00 -0000 [thread overview]
Message-ID: <20190903195711.GA67168@troutmask.apl.washington.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 677 bytes --]
The attached patch has been tested on x86_64-*-freebsd.
I plan to commit this patch tomorrow if there are no objections.
A BOZ literal constant cannot appear in an output IO list. By
default, the patch will generate an error. The -fallow-invalid-boz
option can be used to degrade the error into an warning. The
resulting executable then has historic broken gfortran behavior.
2019-09-03 Steven G. Kargl <kargl@gcvc.gnu.org>
PR fortran/91650
* io.c (match_io_element): An output IO list item cannot be a BOZ.
2019-09-03 Steven G. Kargl <kargl@gcvc.gnu.org>
PR fortran/91650
* gfortran.dg/pr91650_1.f90: New test.
* gfortran.dg/pr91650_2.f90: Ditto.
--
Steve
[-- Attachment #2: pr91650.diff --]
[-- Type: text/x-diff, Size: 2076 bytes --]
Index: gcc/fortran/io.c
===================================================================
--- gcc/fortran/io.c (revision 275343)
+++ gcc/fortran/io.c (working copy)
@@ -3675,6 +3675,15 @@ match_io_element (io_kind k, gfc_code **cpp)
if (m == MATCH_NO)
gfc_error ("Expected expression in %s statement at %C",
io_kind_name (k));
+
+ if (m == MATCH_YES && expr->ts.type == BT_BOZ)
+ {
+ if (gfc_invalid_boz ("BOZ literal constant at %L cannot appear in "
+ "an output IO list", &gfc_current_locus))
+ return MATCH_ERROR;
+ if (!gfc_boz2int (expr, gfc_max_integer_kind))
+ return MATCH_ERROR;
+ };
}
if (m == MATCH_YES && k == M_READ && gfc_check_do_variable (expr->symtree))
Index: gcc/testsuite/gfortran.dg/pr91650_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91650_1.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91650_1.f90 (working copy)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/91650
+! Code contributed by Gerhard Steinmetz.
+program p
+ print *, b'10110' ! { dg-error "cannot appear in an output IO list" }
+ print *, o'10110' ! { dg-error "cannot appear in an output IO list" }
+ print *, z'10110' ! { dg-error "cannot appear in an output IO list" }
+end
Index: gcc/testsuite/gfortran.dg/pr91650_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91650_2.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91650_2.f90 (working copy)
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-fallow-invalid-boz" }
+! PR fortran/91650
+! Code contributed by Gerhard Steinmetz.
+program p
+ character(len=60) str
+ write(str,*) b'10110' ! { dg-warning "cannot appear in an output IO list" }
+ if (trim(adjustl(str)) /= '22') stop 1
+ write(str,*) o'10110' ! { dg-warning "cannot appear in an output IO list" }
+ if (trim(adjustl(str)) /= '4168') stop 2
+ write(str,*) z'10110' ! { dg-warning "cannot appear in an output IO list" }
+ if (trim(adjustl(str)) /= '65808') stop 3
+end
reply other threads:[~2019-09-03 19:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190903195711.GA67168@troutmask.apl.washington.edu \
--to=sgk@troutmask.apl.washington.edu \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@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).