re PR fortran/92781 (ICE in convert_nonlocal_reference_op, at tree-nested.c:1065)
authorJakub Jelinek <jakub@redhat.com>
Thu, 5 Dec 2019 09:03:34 +0000 (10:03 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 5 Dec 2019 09:03:34 +0000 (10:03 +0100)
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: r278988

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

index bd109f94cfbcdc7951b464abfcbaee38e1aa8580..2cdee32881e6c4474c2d8df88310cac9645b6b42 100644 (file)
@@ -1,3 +1,10 @@
+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-12-04  Tobias Burnus  <tobias@codesourcery.com>
 
        PR fortran/92754
index e74244774272ed10bc1015fadfaba07b0397e436..fb1539641362b8a8fe84a9717031a1c31eff2fd5 100644 (file)
@@ -1631,15 +1631,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 75050022f0ed3a4fb50c52a6d82f2acc146efbfd..89066e87356ba85d6391d904621854b061e90b95 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/92781
+       * gfortran.dg/pr92781.f90: New test.
+
 2019-12-05  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * g++.dg/diagnostic/functional-cast-to-array-type-1.C: New.
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