* [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
@ 2017-06-15 12:07 Janus Weil
2017-06-15 13:33 ` Thomas Koenig
0 siblings, 1 reply; 5+ messages in thread
From: Janus Weil @ 2017-06-15 12:07 UTC (permalink / raw)
To: gfortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 772 bytes --]
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 <janus@gcc.gnu.org>
PR fortran/70983
* trans-expr.c (gfc_conv_procedure_call): Deallocate the result of
scalar allocatable procedure-pointer components.
2017-06-15 Janus Weil <janus@gcc.gnu.org>
PR fortran/70983
* gfortran.dg/proc_ptr_comp_51.f90: New test.
[-- Attachment #2: pr80983.diff --]
[-- Type: text/plain, Size: 745 bytes --]
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);
[-- Attachment #3: proc_ptr_comp_51.f90 --]
[-- Type: text/x-fortran, Size: 824 bytes --]
! { dg-do compile }
!
! PR 80983: [F03] memory leak when calling procedure-pointer component with allocatable result
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
program test
implicit none
type :: concrete_type
procedure (alloc_integer), pointer, nopass :: alloc
end type
procedure (alloc_integer), pointer :: pp
type(concrete_type) :: concrete
print *, alloc_integer() ! case #1: plain function
pp => alloc_integer
print *, pp() ! case #2: procedure pointer
concrete % alloc => alloc_integer
print *, concrete % alloc() ! case #3: procedure-pointer component
contains
function alloc_integer() result(res)
integer, allocatable :: res
allocate(res, source=13)
end function
end
! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
2017-06-15 12:07 [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result Janus Weil
@ 2017-06-15 13:33 ` Thomas Koenig
2017-06-15 21:18 ` Janus Weil
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Koenig @ 2017-06-15 13:33 UTC (permalink / raw)
To: Janus Weil, gfortran, gcc-patches
Hi Janus,
> It regtests cleanly on x86_64-linux-gnu. Ok for trunk?
OK.
Thanks for the patch!
Regards
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
2017-06-15 13:33 ` Thomas Koenig
@ 2017-06-15 21:18 ` Janus Weil
2017-06-16 9:11 ` Christophe Lyon
0 siblings, 1 reply; 5+ messages in thread
From: Janus Weil @ 2017-06-15 21:18 UTC (permalink / raw)
To: Thomas Koenig; +Cc: gfortran, gcc-patches
2017-06-15 15:33 GMT+02:00 Thomas Koenig <tkoenig@netcologne.de>:
> Hi Janus,
>
>> It regtests cleanly on x86_64-linux-gnu. Ok for trunk?
>
>
> OK.
>
> Thanks for the patch!
Thanks, Thomas! Committed as r249227.
Cheers,
Janus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
2017-06-15 21:18 ` Janus Weil
@ 2017-06-16 9:11 ` Christophe Lyon
2017-06-16 10:16 ` Janus Weil
0 siblings, 1 reply; 5+ messages in thread
From: Christophe Lyon @ 2017-06-16 9:11 UTC (permalink / raw)
To: Janus Weil; +Cc: Thomas Koenig, gfortran, gcc-patches
Hi,
On 15 June 2017 at 23:18, Janus Weil <janus@gcc.gnu.org> wrote:
> 2017-06-15 15:33 GMT+02:00 Thomas Koenig <tkoenig@netcologne.de>:
>> Hi Janus,
>>
>>> It regtests cleanly on x86_64-linux-gnu. Ok for trunk?
>>
>>
>> OK.
>>
>> Thanks for the patch!
>
> Thanks, Thomas! Committed as r249227.
>
There's a problem with the new test. It says:
gfortran.dg/proc_ptr_comp_51.f90 -O : dump file does not exist
UNRESOLVED: gfortran.dg/proc_ptr_comp_51.f90 -O
scan-tree-dump-times original "__builtin_free" 3
You probably either want to add:
! { dg-options "-fdump-tree-original" }
or to remove:
! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
Thanks,
Christophe
> Cheers,
> Janus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result
2017-06-16 9:11 ` Christophe Lyon
@ 2017-06-16 10:16 ` Janus Weil
0 siblings, 0 replies; 5+ messages in thread
From: Janus Weil @ 2017-06-16 10:16 UTC (permalink / raw)
To: Christophe Lyon; +Cc: Thomas Koenig, gfortran, gcc-patches
2017-06-16 11:11 GMT+02:00 Christophe Lyon <christophe.lyon@linaro.org>:
> Hi,
>
> On 15 June 2017 at 23:18, Janus Weil <janus@gcc.gnu.org> wrote:
>> 2017-06-15 15:33 GMT+02:00 Thomas Koenig <tkoenig@netcologne.de>:
>>> Hi Janus,
>>>
>>>> It regtests cleanly on x86_64-linux-gnu. Ok for trunk?
>>>
>>>
>>> OK.
>>>
>>> Thanks for the patch!
>>
>> Thanks, Thomas! Committed as r249227.
>>
>
> There's a problem with the new test. It says:
> gfortran.dg/proc_ptr_comp_51.f90 -O : dump file does not exist
> UNRESOLVED: gfortran.dg/proc_ptr_comp_51.f90 -O
> scan-tree-dump-times original "__builtin_free" 3
>
> You probably either want to add:
> ! { dg-options "-fdump-tree-original" }
> or to remove:
> ! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
Thanks for your attention, Christophe. I wanted the first of these two
options, but apparently forgot that line ... :(
Fixed with r249243.
Cheers,
Janus
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-16 10:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-15 12:07 [Patch, Fortran, F03] PR 80983: memory leak when calling procedure-pointer component with allocatable result Janus Weil
2017-06-15 13:33 ` Thomas Koenig
2017-06-15 21:18 ` Janus Weil
2017-06-16 9:11 ` Christophe Lyon
2017-06-16 10:16 ` Janus Weil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).