From 77dacf9da6fe475efc87d63d7ea6fde66f097afc Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 4 Nov 2017 09:07:09 +0000 Subject: [PATCH] re PR fortran/81735 (double free or corruption (fasttop) error (SIGABRT) with character(:) and custom return type with allocatable) 2017-11-04 Paul Thomas PR fortran/81735 * trans-decl.c (gfc_trans_deferred_vars): Do a better job of a case where 'tmp' was used unititialized and remove TODO. 2017-11-04 Paul Thomas PR fortran/81735 * gfortran.dg/pr81735.f90: New test. From-SVN: r254404 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-decl.c | 9 ++++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr81735.f90 | 25 +++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr81735.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f653267b8e6..aa43ff4ebff 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-11-04 Paul Thomas + + PR fortran/81735 + * trans-decl.c (gfc_trans_deferred_vars): Do a better job of a + case where 'tmp' was used unititialized and remove TODO. + 2017-11-03 Steven G. Kargl PR fortran/82796 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index c21611c5d6c..45d5119236a 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -4584,7 +4584,10 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) && sym->ts.u.cl->passed_length) tmp = gfc_null_and_pass_deferred_len (sym, &init, &loc); else - gfc_restore_backend_locus (&loc); + { + gfc_restore_backend_locus (&loc); + tmp = NULL_TREE; + } /* Deallocate when leaving the scope. Nullifying is not needed. */ @@ -4636,10 +4639,6 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) } gfc_add_init_cleanup (block, gfc_finish_block (&init), tmp); - /* TODO find out why this is necessary to stop double calls to - free. Somebody is reusing the expression in 'tmp' because - it is being used unititialized. */ - tmp = NULL_TREE; } } else if (sym->ts.type == BT_CHARACTER && sym->ts.deferred) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 87500b7ecee..10331b39929 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-04 Paul Thomas + + PR fortran/81735 + * gfortran.dg/pr81735.f90: New test. + 2017-11-03 Steven G. Kargl PR fortran/82796 diff --git a/gcc/testsuite/gfortran.dg/pr81735.f90 b/gcc/testsuite/gfortran.dg/pr81735.f90 new file mode 100644 index 00000000000..6aae203aa0f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr81735.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! +! Contributed by Danila +! +program fooprog + implicit none + type FooType + integer, allocatable :: x + end type FooType + + type(FooType), pointer :: bar + + bar => foo() + +contains + function foo() result(res) + type(FooType), pointer :: res + + character(:), allocatable :: rt + rt = "" + res => null() + end function foo +end program fooprog +! { dg-final { scan-tree-dump-times "__builtin_free" 1 "original" } } -- 2.30.2