From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 45BCA3870C07 for ; Wed, 21 Jul 2021 16:16:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45BCA3870C07 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16LG5Cp5113860; Wed, 21 Jul 2021 12:16:09 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com with ESMTP id 39xpne0ndp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jul 2021 12:16:09 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16LGCXNE001403; Wed, 21 Jul 2021 16:16:09 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01dal.us.ibm.com with ESMTP id 39upudn1ng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Jul 2021 16:16:08 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16LGG7nv21037472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Jul 2021 16:16:07 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 90E536A051; Wed, 21 Jul 2021 16:16:07 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 629466A054; Wed, 21 Jul 2021 16:16:07 +0000 (GMT) Received: from Bills-MacBook-Pro.local (unknown [9.211.140.71]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 21 Jul 2021 16:16:07 +0000 (GMT) Reply-To: wschmidt@linux.ibm.com Subject: Re: [PATCH 10/55] rs6000: Main function with stubs for parsing and output From: Bill Schmidt To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org References: <20210719191524.GP1583@gate.crashing.org> <96c1f140-9600-86a6-276f-2ac8c3fbec38@linux.ibm.com> <20210720232227.GB1583@gate.crashing.org> <81520718-d8be-d63e-0ee6-6fe21ea4fea4@linux.ibm.com> <20210721154313.GG1583@gate.crashing.org> Message-ID: <38853c98-b51b-d093-f3e4-bfbc5192c279@linux.ibm.com> Date: Wed, 21 Jul 2021 11:16:06 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-TM-AS-GCONF: 00 X-Proofpoint-GUID: _rwX1Ku8JOANMlIgaCii9X9yxw_hLVTD X-Proofpoint-ORIG-GUID: _rwX1Ku8JOANMlIgaCii9X9yxw_hLVTD X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-21_09:2021-07-21, 2021-07-21 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 impostorscore=0 phishscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107210094 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 21 Jul 2021 16:16:11 -0000 On 7/21/21 11:08 AM, Bill Schmidt wrote: > On 7/21/21 10:43 AM, Segher Boessenkool wrote: >> On Tue, Jul 20, 2021 at 08:51:58PM -0500, Bill Schmidt wrote: >>> On 7/20/21 6:22 PM, Segher Boessenkool wrote: >>>> On Tue, Jul 20, 2021 at 05:19:54PM -0500, Bill Schmidt wrote: >>>>> See the main function.  All three files are guaranteed to have been >>>>> opened for writing when this is called, but some of them may have >>>>> already been closed.  So the fclose calls may fail to do anything, but >>>>> the unlinks will always delete the output files. This is done to avoid >>>>> leaving garbage lying around after a parsing failure. >>>> That is much worse actually! From the C spec: >>>> The value of a pointer to a FILE object is indeterminate after the >>>> associated file is closed >>>> so this is undefined behaviour. >>>> >>>> Please fix that? Just assign 0 after closing, and guard the fclose on >>>> error with that? >>> No, you're misunderstanding. >>> >>> unlink doesn't use a pointer to a FILE object.  It takes a string >>> representing the path and deletes that name from the filesystem. If >>> nobody has the file open, the file is then deleted. >> Ah, "the fclose calls may fail to do anything" confused me. That should >> never happen (it can get an error, maybe you meant that?) >> >>> In this case the files are all always closed before unlink is called. >>> The names are removed from the filesystem, and the files are deleted. >>> If somehow the file managed to remain open (really impossible), the file >>> would not be deleted, but the name would be.  No undefined behavior. >> Calling fclose on the same FILE * twice is UB. You said you do that, >> but that is probably not true? > That is unfortunately true.  I guess I'll have to track which files have > been closed, or otherwise make this cleaner.  I had misremembered that > duplicate fclose was ignored. :/ I'll just move all the fclose calls to the end and avoid the problem. Bill > > Bill > >> >> Segher