Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (révision 116013) +++ gcc/fortran/trans-decl.c (copie de travail) @@ -884,7 +884,15 @@ if (TREE_CODE (length) == VAR_DECL && DECL_CONTEXT (length) == NULL_TREE) { - gfc_add_decl_to_function (length); + /* Add the string length to the same context as the symbol. */ + if (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)); + gfc_defer_symbol_init (sym); } } Index: gcc/testsuite/gfortran.dg/assumed_charlen_function_4.f90 =================================================================== --- gcc/testsuite/gfortran.dg/assumed_charlen_function_4.f90 (révision 0) +++ gcc/testsuite/gfortran.dg/assumed_charlen_function_4.f90 (révision 0) @@ -0,0 +1,17 @@ +! { dg-do compile } +! Tests the fix for PR28600 in which the declaration for the +! character length n, would be given the DECL_CONTEXT of 'gee' +! thus causing an ICE. +! +! Contributed by Francois-Xavier Coudert +! +subroutine bar(s, n) + integer n + character s*(n) + character*3, dimension(:), pointer :: m + s = "" +contains + subroutine gee + m(1) = s(1:3) + end subroutine gee +end subroutine bar