From patchwork Thu Jun 15 12:07:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 776280 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wpMhk63ptz9s1h for ; Thu, 15 Jun 2017 22:08:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ymJweBis"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=gZ9Ec4OZSYfiPG1/MQYINsWhafKlnPEAJ7W8zs9mTjDbtn NreplN3uLJr+sUB2v4BwK+FeYzDKgJUT3AoN10wILWVVtOrr8pPO0P25+1tHpl0K I/h87FSeeAkFBQlu1eJl5upIFgVpyPXEMilCh/FAJRlWW0GFqnW0OsMVolV4o= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=UR1sq7bnvJdfCZtr7GWsViVFwQY=; b=ymJweBisPv7mAHgeU/so 6r7+ejNt5hcvvFZD+EwXdrQplYnmJsutrN+tyEPFBOdr8YZJ9e0TVIQZ9O7EDw+D CtUmhzIgoF70sgOSx7mflhhl7HjpebyN5X7PoqalPe6b0hEanViqJZ0x8lAoidkl h6GzkalV58WjdwZ6g24f5Es= Received: (qmail 116889 invoked by alias); 15 Jun 2017 12:07:54 -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 116848 invoked by uid 89); 15 Jun 2017 12:07:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=cured, weil, cures X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-yw0-f180.google.com Received: from mail-yw0-f180.google.com (HELO mail-yw0-f180.google.com) (209.85.161.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Jun 2017 12:07:48 +0000 Received: by mail-yw0-f180.google.com with SMTP id l75so4339971ywc.3; Thu, 15 Jun 2017 05:07:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=CbgS89S+fY5GOYckUpmAzDKAnzw1LpY50k4nHTC8V48=; b=FOry+IPDRPs73ubDjh/LKMN0gtrV3PLmgJ2GvdSYLOhAsHtUQbdl4Xw6X/F+z6dW+q wZrzNioGCov3E8Qoof19VRC2W4zusBLklFLuoij30zaHkpwuvI0FokxuM4b1HTYrpBLP uL6Pt2tq+kjY3izvgRNKR3xREh17qbHtPmYvG/hovZPG1quYs8DCoLYY4vmAao04F4Xj qybzQvq2uhBDi/IE1X0BF2uRMpL7dAQ+IQ5PlPzw++gRV2yPMgM1YeC08rQ1t6+r5UXP 7ufT83rnE2sQ+b444g4aBMn4C5/Xcoq4GShJpDxkHX5gwe7sZ4jTWldGlFhujDa9Mvjf 8GKQ== X-Gm-Message-State: AKS2vOyy/P+X9u+JCwa3nbKVSuTunY/+jZZHaIHCE3kvC8ON2vxLTSXQ o7pxLQcl7TQKu76jiglboPZOygnn1g9W X-Received: by 10.129.69.3 with SMTP id s3mr4554167ywa.202.1497528471903; Thu, 15 Jun 2017 05:07:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.174.2 with HTTP; Thu, 15 Jun 2017 05:07:51 -0700 (PDT) From: Janus Weil Date: Thu, 15 Jun 2017 14:07:51 +0200 Message-ID: Subject: [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result To: gfortran , gcc-patches Hi all, the attached patch fixes a runtime memory leak with procedure-pointer components (PPCs). gfortran correctly deallocates scalar allocatable function results (also for procedure pointers), but fails to do so for PPCs, which is cured by my patch. [Note: Since gfortran translates any type-bound procedure call into a PPC call internally, the patch also cures memory leaks with TBPs.] It regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2017-06-15 Janus Weil PR fortran/70983 * trans-expr.c (gfc_conv_procedure_call): Deallocate the result of scalar allocatable procedure-pointer components. 2017-06-15 Janus Weil PR fortran/70983 * gfortran.dg/proc_ptr_comp_51.f90: New test. Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 249130) +++ gcc/fortran/trans-expr.c (working copy) @@ -6132,7 +6132,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * after use. This necessitates the creation of a temporary to hold the result to prevent duplicate calls. */ if (!byref && sym->ts.type != BT_CHARACTER - && sym->attr.allocatable && !sym->attr.dimension && !comp) + && ((sym->attr.allocatable && !sym->attr.dimension && !comp) + || (comp && comp->attr.allocatable && !comp->attr.dimension))) { tmp = gfc_create_var (TREE_TYPE (se->expr), NULL); gfc_add_modify (&se->pre, tmp, se->expr);