From patchwork Sat Oct 6 11:22:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 189680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A60A22C0156 for ; Sat, 6 Oct 2012 21:22:30 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1350127350; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=q5xGNK3cqLhuEJjrH9mBs5BoN64=; b=EbqWgCvCSM1dTXw 1cW/22x9HGIkZ6RNQaAB1ieZEdTGZnkPrgLxA9DT4r6rP0atKK70OkltzOakKZn7 k3VfJzdzGH/DQNPA0hDaweejJ4hNZqSXKV/PRIP74LOy6HYa0zcW2nAeuP+hK9JY WmbpNPepi3b0Lsz884wosHrKhq7s= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=TXConrXAGg+si416x4ZHwA5AwyCHltO777b255WJBidtqKdso3kkie7awt30RP yHa3zdqsRp8Amz/OZw8LMlKfSxjPEKdhLz5ZrXkhDCXe9IKYAvUc6lSEiemN/KTb 0389NefFbhSdcLtNaJMN3sjvhYkDwveHLRP7B51UuJUAY=; Received: (qmail 22208 invoked by alias); 6 Oct 2012 11:22:26 -0000 Received: (qmail 22195 invoked by uid 22791); 6 Oct 2012 11:22:25 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 06 Oct 2012 11:22:17 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 101BB130EB; Sat, 6 Oct 2012 13:22:15 +0200 (CEST) Received: from [192.168.0.106] (xdsl-78-35-159-94.netcologne.de [78.35.159.94]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id CF55311D8A; Sat, 6 Oct 2012 13:22:13 +0200 (CEST) Message-ID: <50701465.3040104@netcologne.de> Date: Sat, 06 Oct 2012 13:22:13 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 MIME-Version: 1.0 To: fortran@gcc.gnu.org, gcc-patches Subject: Re: [patch, fortran] PR 54833 Don't wrap calls to free(a) in if (a != NULL) References: <507004CC.2000702@netcologne.de> In-Reply-To: <507004CC.2000702@netcologne.de> 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 I wrote: > the attached patch removes wrapping calls to free(a) by > if (a != NULL) for some cases. It is not complete, because > automatic deallocation of allocatable structure components > is not yet covered. I accidentally posted an old version, which had a bug in coarrays (basically was just missing an "else"). Regression-tested. OK for trunk? Thomas 2012-10-06 Thomas König PR fortran/54833 * trans.c (gfc_call_free): Do not wrap the call to __builtin_free in check for NULL. (gfc_deallocate_with_status): For automatic deallocation without status for non-coarrays, don't wrap call to __builtin_free in check for NULL. 2012-10-06 Thomas König PR fortran/54833 * gfortran.dg/auto_dealloc_3.f90: New test. Index: trans.c =================================================================== --- trans.c (Revision 191857) +++ trans.c (Arbeitskopie) @@ -814,26 +814,23 @@ gfc_allocate_allocatable (stmtblock_t * block, tre } -/* Free a given variable, if it's not NULL. */ +/* Free a given variable. If it is NULL, free takes care of this + automatically. */ tree gfc_call_free (tree var) { stmtblock_t block; - tree tmp, cond, call; + tree call; if (TREE_TYPE (var) != TREE_TYPE (pvoid_type_node)) var = fold_convert (pvoid_type_node, var); gfc_start_block (&block); var = gfc_evaluate_now (var, &block); - cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node, var, - build_int_cst (pvoid_type_node, 0)); call = build_call_expr_loc (input_location, builtin_decl_explicit (BUILT_IN_FREE), 1, var); - tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond, call, - build_empty_stmt (input_location)); - gfc_add_expr_to_block (&block, tmp); + gfc_add_expr_to_block (&block, call); return gfc_finish_block (&block); } @@ -861,11 +858,10 @@ gfc_call_free (tree var) } } - In this front-end version, status doesn't have to be GFC_INTEGER_4. - Moreover, if CAN_FAIL is true, then we will not emit a runtime error, - even when no status variable is passed to us (this is used for - unconditional deallocation generated by the front-end at end of - each procedure). + In this front-end version, status doesn't have to be GFC_INTEGER_4. If + CAN_FAIL is true, no status variable is passed and we are not dealing with + a coarray, we will simply call free(). This is used for unconditional + deallocation generated by the front-end at end of each procedure. If a runtime-message is possible, `expr' must point to the original expression being deallocated for its locus and variable name. @@ -890,6 +886,14 @@ gfc_deallocate_with_status (tree pointer, tree sta STRIP_NOPS (pointer); } + else if (can_fail && status == NULL_TREE) + { + tmp = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_FREE), 1, + fold_convert (pvoid_type_node, pointer)); + return tmp; + } + cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, pointer, build_int_cst (TREE_TYPE (pointer), 0));