On 8/16/26 12:02 PM, Mikael Morin wrote:
Le 16/08/2026 à 02:29, Jerry D a écrit :
Attached is the patch I re-discovered while cleaning up worktrees.
Regression tested on x86_64.
OK for mainline?
Regards,
Jerry
---
gfc_get_symbol_decl has an assert meant to verify that a deferred-length
string's length variable lives in the same scope as the symbol it
belongs to. This is wrong when sym->backend_decl is itself the enclosing
function's FUNCTION_DECL. The correct comparison is
DECL_CONTEXT (length) == sym->backend_decl directly.
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 47b28c1d003..df5aef2fd86 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1848,10 +1848,15 @@ gfc_get_symbol_decl (gfc_symbol * sym)
gfc_add_decl_to_parent_function (length);
}
+ /* When the symbol's own backend_decl is a FUNCTION_DECL, its
+ DECL_CONTEXT is where that function itself is declared, not
+ where its locals live. */
gcc_assert (sym->backend_decl == current_function_decl
? DECL_CONTEXT (length) == current_function_decl
- : (DECL_CONTEXT (sym->backend_decl)
- == DECL_CONTEXT (length)));
+ : (TREE_CODE (sym->backend_decl) == FUNCTION_DECL
+ ? DECL_CONTEXT (length) == sym->backend_decl
+ : (DECL_CONTEXT (sym->backend_decl)
+ == DECL_CONTEXT (length))));
The first condition (sym->backend_decl == current_function_decl) is redundant
with the second one (TREE_CODE (sym->backend_decl) == FUNCTION_DECL); I think
the outer conditional can be removed completely.
OK with that change.
Agree, thanks for review, edit made. I will commit after a complete testsuite
check
Thanks again,
Jerry
---