Hi! The following testcases ICE, because when tree-nested.c replaces various decls in the functions with local or nonlocal alternative decls and makes the old ones DECL_IGNORED_P, decls inside of NAMELIST_DECL NAMELIST_DECL_ASSOCIATED_DECL aren't replaced and thus debug info can't be generated for the namelist.
Fixed by adjusting them. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-01-17 Jakub Jelinek <ja...@redhat.com> PR fortran/59440 * tree-nested.c (convert_nonlocal_reference_stmt, convert_local_reference_stmt): For NAMELIST_DECLs in gimple_bind_vars of GIMPLE_BIND stmts, adjust associated decls. * gfortran.dg/pr59440-1.f90: New test. * gfortran.dg/pr59440-2.f90: New test. * gfortran.dg/pr59440-3.f90: New test. --- gcc/tree-nested.c.jj 2014-01-03 11:41:01.000000000 +0100 +++ gcc/tree-nested.c 2014-01-17 10:17:58.287209744 +0100 @@ -1331,6 +1331,25 @@ convert_nonlocal_reference_stmt (gimple_ if (!optimize && gimple_bind_block (stmt)) note_nonlocal_block_vlas (info, gimple_bind_block (stmt)); + for (tree var = gimple_bind_vars (stmt); var; var = DECL_CHAIN (var)) + if (TREE_CODE (var) == NAMELIST_DECL) + { + /* Adjust decls mentioned in NAMELIST_DECL. */ + tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var); + tree decl; + unsigned int i; + + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl) + { + if (TREE_CODE (decl) == VAR_DECL + && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) + continue; + if (decl_function_context (decl) != info->context) + CONSTRUCTOR_ELT (decls, i)->value + = get_nonlocal_debug_decl (info, decl); + } + } + *handled_ops_p = false; return NULL_TREE; @@ -1787,6 +1806,36 @@ convert_local_reference_stmt (gimple_stm *handled_ops_p = false; return NULL_TREE; + case GIMPLE_BIND: + for (tree var = gimple_bind_vars (stmt); var; var = DECL_CHAIN (var)) + if (TREE_CODE (var) == NAMELIST_DECL) + { + /* Adjust decls mentioned in NAMELIST_DECL. */ + tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var); + tree decl; + unsigned int i; + + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl) + { + if (TREE_CODE (decl) == VAR_DECL + && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) + continue; + if (decl_function_context (decl) == info->context + && !use_pointer_in_frame (decl)) + { + tree field = lookup_field_for_decl (info, decl, NO_INSERT); + if (field) + { + CONSTRUCTOR_ELT (decls, i)->value + = get_local_debug_decl (info, decl, field); + } + } + } + } + + *handled_ops_p = false; + return NULL_TREE; + default: /* For every other statement that we are not interested in handling here, let the walker traverse the operands. */ --- gcc/testsuite/gfortran.dg/pr59440-1.f90.jj 2014-01-17 10:19:41.038685480 +0100 +++ gcc/testsuite/gfortran.dg/pr59440-1.f90 2014-01-17 10:19:05.000000000 +0100 @@ -0,0 +1,23 @@ +! PR fortran/59440 +! { dg-do compile } +! { dg-options "-O2 -g" } + +module pr59440 + implicit none + type t + integer :: grid = 0 + end type t +contains + subroutine read_nml (nnml, s) + integer, intent(in) :: nnml + type(t), intent(out) :: s + integer :: grid + namelist /N/ grid + call read_nml_type_2 + s%grid = grid + contains + subroutine read_nml_type_2 + read (nnml, nml=N) + end subroutine read_nml_type_2 + end subroutine read_nml +end module pr59440 --- gcc/testsuite/gfortran.dg/pr59440-2.f90.jj 2014-01-17 10:19:44.725667756 +0100 +++ gcc/testsuite/gfortran.dg/pr59440-2.f90 2014-01-17 10:19:20.000000000 +0100 @@ -0,0 +1,16 @@ +! PR fortran/59440 +! { dg-do compile } +! { dg-options "-O2 -g" } + +subroutine foo (nnml, outv) + integer, intent(in) :: nnml + integer, intent(out) :: outv + integer :: grid + namelist /N/ grid + read (nnml, nml=N) + call bar +contains + subroutine bar + outv = grid + end subroutine bar +end subroutine foo --- gcc/testsuite/gfortran.dg/pr59440-3.f90.jj 2014-01-17 10:19:46.910654994 +0100 +++ gcc/testsuite/gfortran.dg/pr59440-3.f90 2014-01-17 10:19:23.000000000 +0100 @@ -0,0 +1,16 @@ +! PR fortran/59440 +! { dg-do compile } +! { dg-options "-O2 -g" } + +subroutine foo (nnml, outv) + integer, intent(in) :: nnml + integer, intent(out) :: outv + integer :: grid + call bar + outv = grid +contains + subroutine bar + namelist /N/ grid + read (nnml, nml=N) + end subroutine bar +end subroutine foo Jakub