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

fortran: Ensure function results passed as arguments are finalized

Fixes Fortran function result finalization for arguments in conditions and operators, complying with F2023.

This commit addresses a Fortran compilation issue where function results passed as actual arguments were not being properly finalized when used in specific contexts like operator operands or conditions. This violated the F2023 standard (7.5.6.3). The fix repositions the finalization step for such arguments to occur at the beginning of the ‘post block’ of the enclosing call, which is preserved across all expression types. It also refines logic to correctly count nested argument evaluations, ensuring finalization happens appropriately.

In Details

Fortran function results passed by value (not reference) require finalization. The gfc_conv_procedure_call function collects this finalization in a 'finalblock'. However, this block was only emitted for assignments, subroutine calls, and I/O, causing issues when the function result was an operand in an operator, intrinsic function, or condition. This commit modifies gfc_conv_procedure_call to move the finalization of non-reference function results to the post block, which is consistently preserved. It introduces actual_arg_level to track nesting during actual argument evaluation, ensuring t…

For Context
F2023
The 2023 revision of the Fortran programming language standard.
Finalization
In Fortran, a process that occurs for certain types (e.g., those with automatic or finalizable components) after their scope ends or they are no longer needed, to clean up resources.
Actual argument
The expression or variable passed from the calling procedure to the called procedure.
RTL
Register Transfer Language, an intermediate representation used within GCC.
Component
An element within a derived (record) type in Fortran.
Filed Under: fortrancompiler-backendF2023bugfix