From d0c4f314cfd1fcdf85fb8f2661a8a741447772f8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 5 Dec 2019 10:03:34 +0100 Subject: [PATCH] re PR fortran/92781 (ICE in convert_nonlocal_reference_op, at tree-nested.c:1065) 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 | 7 +++++++ gcc/fortran/trans-decl.c | 11 +++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr92781.f90 | 11 +++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr92781.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bd109f94cfb..2cdee32881e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-12-05 Jakub Jelinek + + 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 PR fortran/92754 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index e7424477427..fb153964136 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 75050022f0e..89066e87356 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-05 Jakub Jelinek + + PR fortran/92781 + * gfortran.dg/pr92781.f90: New test. + 2019-12-05 Paolo Carlini * 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 index 00000000000..67a1961205a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr92781.f90 @@ -0,0 +1,11 @@ +! PR fortran/92781 +! { dg-do compile } + +function foo () + character(:), allocatable :: foo + call bar () + foo = 'abc' +contains + subroutine bar + end +end -- 2.30.2