From patchwork Tue Oct 1 23:10:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1170291 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-510025-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="A8Jrha1N"; 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 46jZkx1dzqz9sDB for ; Wed, 2 Oct 2019 09:11:02 +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:reply-to:mime-version:content-type; q=dns; s=default; b=f4Zfv5JHkPB4ZITrGATQ9OllEXGeJojD6Q1nbtHPdGg 717t2yaa/y7VOFQR4VJdyQ2NsZzjvD0FROCTERgJfTlSqvZ1NsMhIwN0dJNaERpr SRA6agra/X90pmucW3cmwDyR5AlDZ7XZQldaOC5FwuY/TmO+NXCg5HljU2dGc9sQ = 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:reply-to:mime-version:content-type; s=default; bh=VHru1ps7tpfEiyEx6V2y+fGtC1A=; b=A8Jrha1Nxu8hFj3NY eiHri48iXphGMmomO+r9k3LDtkaW4B4kXq74LsNE3zCmbsJ6gcoBzcaDQltbHFwc Xn8t6wPYsA+Apt2c1x9CXxlNKVsH6PDmxce3v6R7U6Br2f5keB9y6ZRRAJmG+BSO IZl7tiI40vzx5KnDxQe0BA5HQg= Received: (qmail 18334 invoked by alias); 1 Oct 2019 23:10:50 -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 18315 invoked by uid 89); 1 Oct 2019 23:10:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=Inquiry 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, 01 Oct 2019 23:10:49 +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 x91NAltu000078 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 1 Oct 2019 16:10:47 -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 x91NAlwN000077; Tue, 1 Oct 2019 16:10:47 -0700 (PDT) (envelope-from sgk) Date: Tue, 1 Oct 2019 16:10:47 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/91942 -- Inquiry parameter cannot be IO tag Message-ID: <20191001231047.GA68@troutmask.apl.washington.edu> Reply-To: sgk@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. OK to commit? If an inquiry parameter cannot appear in a file IO statement as a tag (see new testcase). The patch re-arranges the code to prevent an ICE due to 'result->symtree = NULL;', checks for a constant in a variable definition context, and takes a different exit route to get better error messages. 2019-10-01 Steven G. Kargl PR fortran/91942 * io.c (match_vtag): Check for non-NULL result->symtree. (match_out_tag): Check for invalid constant due to inquiry parameter. (match_filepos): Instead of a syntax error, go to cleanup to get better error messages. 2019-10-01 Steven G. Kargl PR fortran/91942 * gfortran.dg/pr91587.f90: Update dg-error regex. * gfortran.dg/pr91942.f90: New test. Index: gcc/fortran/io.c =================================================================== --- gcc/fortran/io.c (revision 276426) +++ gcc/fortran/io.c (working copy) @@ -1482,25 +1482,30 @@ match_vtag (const io_tag *tag, gfc_expr **v) return MATCH_ERROR; } - if (result->symtree->n.sym->attr.intent == INTENT_IN) + if (result->symtree) { - gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name); - gfc_free_expr (result); - return MATCH_ERROR; - } + bool impure; - bool impure = gfc_impure_variable (result->symtree->n.sym); - if (impure && gfc_pure (NULL)) - { - gfc_error ("Variable %s cannot be assigned in PURE procedure at %C", - tag->name); - gfc_free_expr (result); - return MATCH_ERROR; - } + if (result->symtree->n.sym->attr.intent == INTENT_IN) + { + gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name); + gfc_free_expr (result); + return MATCH_ERROR; + } - if (impure) - gfc_unset_implicit_pure (NULL); + impure = gfc_impure_variable (result->symtree->n.sym); + if (impure && gfc_pure (NULL)) + { + gfc_error ("Variable %s cannot be assigned in PURE procedure at %C", + tag->name); + gfc_free_expr (result); + return MATCH_ERROR; + } + if (impure) + gfc_unset_implicit_pure (NULL); + } + *v = result; return MATCH_YES; } @@ -1515,8 +1520,17 @@ match_out_tag (const io_tag *tag, gfc_expr **result) m = match_vtag (tag, result); if (m == MATCH_YES) - gfc_check_do_variable ((*result)->symtree); + { + if ((*result)->symtree) + gfc_check_do_variable ((*result)->symtree); + if ((*result)->expr_type == EXPR_CONSTANT) + { + gfc_error ("Expecting a variable at %L", &(*result)->where); + return MATCH_ERROR; + } + } + return m; } @@ -2845,7 +2859,7 @@ match_filepos (gfc_statement st, gfc_exec_op op) m = match_file_element (fp); if (m == MATCH_ERROR) - goto syntax; + goto cleanup; if (m == MATCH_NO) { m = gfc_match_expr (&fp->unit); Index: gcc/testsuite/gfortran.dg/pr91587.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91587.f90 (revision 276426) +++ gcc/testsuite/gfortran.dg/pr91587.f90 (working copy) @@ -2,9 +2,9 @@ ! PR fortran/91587 ! Code contributed by Gerhard Steinmetz program p - backspace(err=!) ! { dg-error "Syntax error in" } - flush(err=!) ! { dg-error "Syntax error in" } - rewind(err=!) ! { dg-error "Syntax error in" } + backspace(err=!) ! { dg-error "Invalid value for" } + flush(err=!) ! { dg-error "Invalid value for" } + rewind(err=!) ! { dg-error "Invalid value for" } end subroutine bar ! An other matcher runs, and gives a different error. Index: gcc/testsuite/gfortran.dg/pr91942.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91942.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr91942.f90 (working copy) @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/91942 +! Code contributed by Gerhard Steinmetz +program p + integer :: i + backspace (iostat=i%kind) ! { dg-error "Expecting a variable at" } + endfile (iostat=i%kind) ! { dg-error "Expecting END PROGRAM" } + flush (iostat=i%kind) ! { dg-error "Expecting a variable at" } + rewind (iostat=i%kind) ! { dg-error "Expecting a variable at" } +end