GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Fix ICE for character pointer initialized to substring

GFortran resolves an internal compiler error caused by character pointers initialized to substrings lacking explicit length information.

This commit resolves an internal compiler error (ICE) in GFortran that occurred when a character pointer was initialized to a substring in its declaration, such as character(len=:), pointer :: p => t(2:4). The error happened because the substring’s character length was not being set correctly during resolution. The fix ensures the substring length is resolved, and also adjusts how temporary variables are created for deferred-length assignments to prevent assertion failures.

In Details

This patch for GFortran's Fortran front-end (in resolve.cc and frontend-passes.cc) fixes an ICE related to initializing character pointers with substrings (PR125763). The gfc_resolve_expr function previously failed to resolve the substring length when the variable's first reference was the substring itself. This resulted in fixup_charlen assigning a null length to the expression. The commit modifies gfc_resolve_expr to resolve the substring length in such cases. Additionally, it addresses an assertion failure in gfc_trans_deferred_vars by clearing the ts.deferred flag on fronten…

For Context
ICE
Internal Compiler Error. An unexpected condition encountered by the compiler during translation that prevents it from continuing.
Character pointer
In Fortran, a pointer that is associated with a character data type. It can point to a string or a substring.
Substring
A contiguous sequence of characters within a character string. In Fortran, substrings can be specified using slicing notation (e.g., string(start:end)).
Deferred-length
A characteristic of character variables in Fortran where the length is not fixed at compile time but is determined at runtime. Variables declared with len=: have deferred length.
LEN()
A Fortran intrinsic function that returns the length of a character expression or variable.
Filed Under: fortrangfortranpointerscompiler bugs