Hi Jerry!
Am 30.05.26 um 1:54 AM schrieb Jerry D:
The attached patch fixes this. Regression tested on x86_64.
OK for mainline and then backport to 16?
LGTM. OK for both.
Thanks for the patch!
Harald
Regards,
Jerry
---
fortran: fix ICE with procedure pointer declared in BLOCK
Procedure pointer declared inside a BLOCK construct in a program that has
contained procedures caused an ICE in convert_nonlocal_reference_op
(tree-nested.cc) because get_proc_pointer_decl set the proc pointer's
DECL_CONTEXT to NULL instead of the enclosing program function decl.
The root cause: the condition to call gfc_add_decl_to_function vs
gfc_add_decl_to_parent_function checked whether proc_name->backend_decl
matched current_function_decl. For a BLOCK namespace the proc_name has
FL_LABEL flavor and its backend_decl is never set, so the condition failed
and gfc_add_decl_to_parent_function was called. That function sets
DECL_CONTEXT to DECL_CONTEXT(current_function_decl), which is NULL for a
top-level program. The tree-nested pass then found no nesting level
matching target_context = NULL and crashed in the internal_error call
dereferencing the NULL target_context.
Fix: add the missing BLOCK namespace check (FL_LABEL flavor) so that
procedure pointers in BLOCK constructs are treated like regular variables
and added to the enclosing function via gfc_add_decl_to_function.
Assisted by: Claude Sonnet 4.6
PR fortran/105582
gcc/fortran/ChangeLog:
* trans-decl.cc (get_proc_pointer_decl): Add FL_LABEL check to
route BLOCK-construct procedure pointers to gfc_add_decl_to_function
rather than gfc_add_decl_to_parent_function.
gcc/testsuite/ChangeLog:
* gfortran.dg/block_proc_ptr_1.f90: New test.
---