From patchwork Tue Sep 3 19:57:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1157244 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-508259-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="VgFYtMLF"; 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 46NHmN224Hz9sNx for ; Wed, 4 Sep 2019 05:57:22 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=XJFFuRlpCE1m3YAWsod4NqnTyzVS6ZKRheJjkRU7XraJfY5ktlA9k 930dB7lcNnAJlfYlKtgV4lox0x9qm4TouLARa9h1vnKDpzS+7ahyRXABOfeEUmit xf30LQMJJmtXYdhE95+mDdskwtZ0tNmN8UrR9EH/SqoYxaPIZ5DhoU= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=rWkHHEQJyzzQkqWzE2wuLUFZik8=; b=VgFYtMLFUH/rt3uST958 Bj1Sf2gk6YRDnR7HtK/jQ/j14pSVWarR9Y1zz3utArYoRil/KKHk5JWISNLiIyfU eEHynBotTDMjd//SBny8pf7Xj5UILHGWe80igqpjLrssALwTodJ0h+syoh4w9IjA fSc2BYdgw6VlRZEkWRAhZrg= 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-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 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, 3 Sep 2019 12:57:11 -0700 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-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) 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. 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