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

Fortran: Fix array constructor issues with character length expressions.

Resolves bugs in Fortran array constructors related to character length expressions and dangling charlens.

This commit addresses two issues in Fortran’s array constructor handling of character length expressions. The first fixes a problem with trans-array.cc by adding a check for INTEGER_CST. The second, more extensive fix, improves how character lengths (charlens) are tracked during parsing to prevent them from being left dangling, ensuring proper cleanup and avoiding memory issues.

In Details

This commit refactors Fortran's handling of character lengths (charlens) during parsing, particularly within decl.cc, gfortran.h, and symbol.cc. It introduces a gfc_charlen struct with a namespace pointer and integrates it into the undo mechanism (gfc_undo_change_set) to track charlens created during parsing. This allows gfc_remove_saved_charlen and related functions to correctly free these resources, fixing issues related to dangling charlens and potential double-frees. The trans-array.cc change adds a guard to trans_array_constructor to handle INTEGER_CST in array constr…

For Context
array constructor
A Fortran language construct used to create arrays, often by specifying a list of values, e.g., (/ 1, 2, 3 /).
character length expression
In Fortran, an expression that determines the length of a character string. This can be a constant, a variable, or a more complex expression evaluated at runtime.
charlen
Abbreviation for 'character length', referring to the mechanism GCC's Fortran frontend uses to manage the lengths of character variables and strings.
dangling charlen
A character length that has been allocated or tracked but is no longer needed or correctly managed, potentially leading to memory leaks or incorrect behavior.
INTEGER_CST
An internal representation within GCC for an integer constant value.
Filed Under: fortrancompiler bugparsing