re PR fortran/81735 (double free or corruption (fasttop) error (SIGABRT) with charact...
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 4 Nov 2017 09:07:09 +0000 (09:07 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 4 Nov 2017 09:07:09 +0000 (09:07 +0000)
2017-11-04  Paul Thomas  <pault@gcc.gnu.org>

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  <pault@gcc.gnu.org>

PR fortran/81735
* gfortran.dg/pr81735.f90: New test.

From-SVN: r254404

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr81735.f90 [new file with mode: 0644]

index f653267b8e6760dd8e747ee1b68261e85de71403..aa43ff4ebffa3c0fbb6473753d84498284c4191b 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-04  Paul Thomas  <pault@gcc.gnu.org>
+
+       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  <kargl@gcc.gnu.org>
 
        PR fortran/82796
index c21611c5d6c874ce5715d8ab5bb9b42c638cf95a..45d5119236a4ee58efbc820c19114182ba78be7b 100644 (file)
@@ -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)
index 87500b7ecee7702c20532208e00ab6d8c05993fe..10331b39929f57d84e6a3fa1827086afe155367d 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-04  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/81735
+       * gfortran.dg/pr81735.f90: New test.
+
 2017-11-03  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/82796
diff --git a/gcc/testsuite/gfortran.dg/pr81735.f90 b/gcc/testsuite/gfortran.dg/pr81735.f90
new file mode 100644 (file)
index 0000000..6aae203
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Contributed by Danila  <flashmozzg@gmail.com>
+!
+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" } }