GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: ICE with %LEN of deferred-length character in ASSOCIATE

Fixes an ICE in Fortran when querying the length or kind of deferred-length character variables within an ASSOCIATE construct.

An internal compiler error (ICE) occurred in the Fortran frontend when a %LEN or %KIND inquiry was made on a deferred-length character variable inside an ASSOCIATE construct. This was due to the inquiry’s result retaining a ‘deferred’ flag, which caused a segfault when later processed. The fix clears this flag and correctly handles the character length for such inquiries, also resolving an issue where inquiries on ASSOCIATE names incorrectly reverted the type to CHARACTER.

In Details

The Fortran frontend's gfc_get_symbol_decl segfaulted due to a dangling deferred flag on an INTEGER expression resulting from a %LEN or %KIND inquiry on a deferred-length CHARACTER type. The resolve_variable function also incorrectly reset the typespec of an associate-name expression, causing ICEs. This commit cleans up the type information after inquiries on deferred-length characters.

For Context
ICE
Internal Compiler Error. A severe error within the compiler's logic that prevents compilation and typically indicates a bug in the compiler itself.
deferred-length character
A character string whose maximum length is not known at compile time, typically determined at runtime. This is common in modern Fortran for functions returning strings or for dynamically allocated character variables.
ASSOCIATE construct
A Fortran control construct that allows defining local names for parts of expressions or variables, simplifying complex assignments or references.
%LEN
A Fortran inquiry function that returns the declared length of a character variable.
%KIND
In Fortran, specifies the properties of a numeric type, such as precision or range. An inquiry can also be made about the kind of a character type.
Filed Under: fortrancompiler bugice