aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJanus Weil <janus@gcc.gnu.org>2017-06-15 23:17:48 +0200
committerJanus Weil <janus@gcc.gnu.org>2017-06-15 23:17:48 +0200
commitd0e7a9fdfc21c858d4131052cf38dea4fa8f44b2 (patch)
treec714a49a98e3543614a3e46469c23e577386d96d /gcc
parent0356a0749bed3e294fcee1ad1d47a1f681189e38 (diff)
downloadgcc-d0e7a9fdfc21c858d4131052cf38dea4fa8f44b2.zip
gcc-d0e7a9fdfc21c858d4131052cf38dea4fa8f44b2.tar.gz
gcc-d0e7a9fdfc21c858d4131052cf38dea4fa8f44b2.tar.bz2
re PR fortran/80983 ([F03] memory leak when calling procedure-pointer component with allocatable result)
2017-06-15 Janus Weil <janus@gcc.gnu.org> PR fortran/80983 * 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/80983 * gfortran.dg/proc_ptr_comp_51.f90: New test. From-SVN: r249227
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/trans-expr.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/proc_ptr_comp_51.f9035
4 files changed, 48 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index ec28113..8e9e9a6 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-15 Janus Weil <janus@gcc.gnu.org>
+
+ PR fortran/80983
+ * trans-expr.c (gfc_conv_procedure_call): Deallocate the result of
+ scalar allocatable procedure-pointer components.
+
2017-06-10 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/80988
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 6af287e..acd0428 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6132,7 +6132,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
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);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a79f533..34b6a9d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-15 Janus Weil <janus@gcc.gnu.org>
+
+ PR fortran/80983
+ * gfortran.dg/proc_ptr_comp_51.f90: New test.
+
2017-06-15 Thomas Preud'homme <thomas.preudhomme@arm.com>
PR lto/69866
diff --git a/gcc/testsuite/gfortran.dg/proc_ptr_comp_51.f90 b/gcc/testsuite/gfortran.dg/proc_ptr_comp_51.f90
new file mode 100644
index 0000000..530872b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/proc_ptr_comp_51.f90
@@ -0,0 +1,35 @@
+! { 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" } }