From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127119 invoked by alias); 3 Sep 2019 19:57:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127097 invoked by uid 89); 3 Sep 2019 19:57:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy= X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Sep 2019 19:57:13 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id x83JvB0H067224 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 3 Sep 2019 12:57:11 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x83JvB2p067223; Tue, 3 Sep 2019 12:57:11 -0700 (PDT) (envelope-from sgk) Date: Tue, 03 Sep 2019 19:57:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/91650 -- BOZ cannot be an output IO list item Message-ID: <20190903195711.GA67168@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="VS++wcV0S1rZb1Fb" Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) X-SW-Source: 2019-09/txt/msg00150.txt.bz2 --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 677 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 PR fortran/91650 * io.c (match_io_element): An output IO list item cannot be a BOZ. 2019-09-03 Steven G. Kargl PR fortran/91650 * gfortran.dg/pr91650_1.f90: New test. * gfortran.dg/pr91650_2.f90: Ditto. -- Steve --VS++wcV0S1rZb1Fb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pr91650.diff" Content-length: 2076 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 --VS++wcV0S1rZb1Fb--