]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/92781 (ICE in convert_nonlocal_reference_op, at tree-nested...
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 17:36:08 +0000 (18:36 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 17:36:08 +0000 (18:36 +0100)
Backported from mainline
2019-12-05  Jakub Jelinek  <jakub@redhat.com>

PR fortran/92781
* trans-decl.c (gfc_get_symbol_decl): If sym->backend_decl is
current_function_decl, add length to current rather than parent
function and expect DECL_CONTEXT (length) to be current_function_decl.

* gfortran.dg/pr92781.f90: New test.

From-SVN: r279667

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

index 06d23432503925a9a9a7039faa05d6b21685f118..2ed008964cbe9b36a1789db0d08ca5e6a81ec09e 100644 (file)
@@ -1,6 +1,13 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/92781
+       * trans-decl.c (gfc_get_symbol_decl): If sym->backend_decl is
+       current_function_decl, add length to current rather than parent
+       function and expect DECL_CONTEXT (length) to be current_function_decl.
+
        2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/91944
index 27613f761e3ccfbede2340302277f469db2bf47c..71f751de76ff46eb101b7d7ca490cf367e3bdbfa 100644 (file)
@@ -1611,15 +1611,18 @@ gfc_get_symbol_decl (gfc_symbol * sym)
              /* Add the string length to the same context as the symbol.  */
              if (DECL_CONTEXT (length) == NULL_TREE)
                {
-                 if (DECL_CONTEXT (sym->backend_decl)
-                     == current_function_decl)
+                 if (sym->backend_decl == current_function_decl
+                     || (DECL_CONTEXT (sym->backend_decl)
+                         == current_function_decl))
                    gfc_add_decl_to_function (length);
                  else
                    gfc_add_decl_to_parent_function (length);
                }
 
-             gcc_assert (DECL_CONTEXT (sym->backend_decl)
-                         == DECL_CONTEXT (length));
+             gcc_assert (sym->backend_decl == current_function_decl
+                         ? DECL_CONTEXT (length) == current_function_decl
+                         : (DECL_CONTEXT (sym->backend_decl)
+                            == DECL_CONTEXT (length)));
 
              gfc_defer_symbol_init (sym);
            }
index c7b96bb4395a4e16d4136b793852e6a138a12ebe..af36fed2ae28c87808c5938107993179f381eaeb 100644 (file)
@@ -1,6 +1,11 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/92781
+       * gfortran.dg/pr92781.f90: New test.
+
        2019-12-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/92756
diff --git a/gcc/testsuite/gfortran.dg/pr92781.f90 b/gcc/testsuite/gfortran.dg/pr92781.f90
new file mode 100644 (file)
index 0000000..67a1961
--- /dev/null
@@ -0,0 +1,11 @@
+! PR fortran/92781
+! { dg-do compile }
+
+function foo ()
+  character(:), allocatable :: foo
+  call bar ()
+  foo = 'abc'
+contains
+  subroutine bar
+  end
+end