On Fri, 5 Mar 2021, Tobias Burnus wrote: > Nested functions are permitted for C but not C++ as extension. > They are also permitted for Fortran, which generates DECL_CONTEXT > == NAMESPACE_DECL for module variables. > > That causes the gcc_assert (decl_function_context (decl) == info->context) > to fail in tree-nested.c's lookup_field_for_decl. > > The call happens in convert_local_reference_stmt for: > 2524 case GIMPLE_ASSIGN: > 2525 if (gimple_clobber_p (stmt)) > 2528 if (DECL_P (lhs) > 2529 && !use_pointer_in_frame (lhs) > 2530 && lookup_field_for_decl (info, lhs, NO_INSERT)) > > The latter runs into the assert mentioned above. And the > '= {CLOBBER}' occurs in gfortran due to the intent(out). > > As additional ingredient, a nested (internal) procedure involved, > obviously as otherwise tree-nested.c wouldn't be involved. > > The patch fixes the assert and in terms of the assert it makes > sense, but I am not sure whether there are assumptions > elsewhere which are wrong for NAMESPACE_DECL.
I think the bug is elsewhere. We're not expecting non-local (non-auto) variables to be queried with lookup_field_for_decl. I think a reasonable fix would be sth like (also see convert_local_reference_op on how it processes decls). diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index addd6eef9ab..5619ebc85d4 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -2526,6 +2526,7 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, { tree lhs = gimple_assign_lhs (stmt); if (DECL_P (lhs) + && auto_var_p (lhs) && !use_pointer_in_frame (lhs) && lookup_field_for_decl (info, lhs, NO_INSERT)) { > OK for mainline? GCC 10? > > Tobias > > ----------------- > Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank > Thürauf > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)