From patchwork Thu May 14 16:44:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1290487 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=afvYRIfH; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49NHSz1Sdgz9sV8 for ; Fri, 15 May 2020 02:44:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 885803971C41; Thu, 14 May 2020 16:44:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 885803971C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589474687; bh=v37SneOjM4MgAViNhTMVMkijgVannpCbhm+3a/LCPQo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=afvYRIfHCDYMoetrykkPQY+uW+mKPBs44FnRWukmFOBIPoaQLg9B/7/jf71pqbtrV 94VRrfA0klWllbA2cIDk39YpVEk6Xkin2MXWNhAR3W+LgIbbOubwkRfWcnGlqHrGyk AxBvsgG6bUesNzHwwOE9ooPeMIhusAiWFbLQDdhk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout3.netcologne.de (cc-smtpout3.netcologne.de [89.1.8.213]) by sourceware.org (Postfix) with ESMTPS id 106AB396EC34; Thu, 14 May 2020 16:44:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 106AB396EC34 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 7E34012F71; Thu, 14 May 2020 18:44:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 6EE8E11ECE; Thu, 14 May 2020 18:44:34 +0200 (CEST) Received: from [2001:4dd7:e664:0:a9e0:292e:c10d:1844] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5ebd7572-7104-7f0000012729-7f0000019b92-1 for ; Thu, 14 May 2020 18:44:34 +0200 Received: from linux-p51k.fritz.box (2001-4dd7-e664-0-a9e0-292e-c10d-1844.ipv6dyn.netcologne.de [IPv6:2001:4dd7:e664:0:a9e0:292e:c10d:1844]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Thu, 14 May 2020 18:44:32 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, libfortran, committed] Message-ID: Date: Thu, 14 May 2020 18:44:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 Content-Language: de-DE X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, I just committed as obvious a patch which fixed a hang on close with -pthread after a previous error on close with an invalid STATUS. The solution was obvious: Return early if an error occurred. I also managed to make some double ChangeLog entries (fixed with the next commit after), but hey - git doing strange and unforseen stuff is par for the course. My life has gotten a lot easier since I stopped worrying about that kind of stuff. I will also backport to the other affected branches. Regards Thomas Add early return for invalid STATUS for close. 2020-05-14 Thomas Koenig PR libfortran/95119 * io/close.c (close_status): Add CLOSE_INVALID. (st_close): Return early on invalid STATUS parameter. 2020-05-14 Thomas Koenig PR libfortran/95119 * testsuite/libgomp.fortran/close_errors_1.f90: New test. diff --git a/libgfortran/io/close.c b/libgfortran/io/close.c index 8aaa00393e7..17e064ba4e8 100644 --- a/libgfortran/io/close.c +++ b/libgfortran/io/close.c @@ -31,7 +31,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif typedef enum -{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED } +{ CLOSE_INVALID = - 1, CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED } close_status; static const st_option status_opt[] = { @@ -61,6 +61,12 @@ st_close (st_parameter_close *clp) find_option (&clp->common, clp->status, clp->status_len, status_opt, "Bad STATUS parameter in CLOSE statement"); + if (status == CLOSE_INVALID) + { + library_end (); + return; + } + u = find_unit (clp->common.unit); if (ASYNC_IO && u && u->au) diff --git a/libgomp/testsuite/libgomp.fortran/close_errors_1.f90 b/libgomp/testsuite/libgomp.fortran/close_errors_1.f90 new file mode 100644 index 00000000000..6edb7da4116 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/close_errors_1.f90 @@ -0,0 +1,19 @@ +! { dg-do run } +! PR 95115 - this used to hang with -pthread. Original test case by +! Bill Long. + +program test + character(len=16) my_status + character(len=1000) :: iomsg + open (unit=10, file='test.dat') + print *,42 + write (10, *) 'weird' + rewind (10) + read (10, *) my_status + close (10) + open (unit=10, file='test.dat') + close (unit=10, status=my_status, iostat=ios, iomsg=iomsg) + if (ios == 0) stop 1 + if (iomsg /= "Bad STATUS parameter in CLOSE statement") stop 2 + close (10, status='delete') +end program test