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

Ada: Fixes function result adjustment on secondary stack for allocators.

Corrects how Ada function results are adjusted on the secondary stack when used with allocators, fixing a regression in recent optimization.

A recent optimization in GCC’s Ada front-end introduced a regression where function calls returning on the secondary stack were not correctly adjusted when used in an allocator. This commit fixes Expand_Ctrl_Function_Call to ensure that if a qualified expression of an allocator is a call returning on the secondary stack, the result is properly copied to the allocated memory by calling Adjust if the type is controlled.

In Details

In Ada, when a function call returns its result on the secondary stack (a temporary stack space), and this result is then used as part of an allocator for a controlled type, the Adjust procedure must be called to correctly manage the controlled type's state. A regression in the mainline and 16 branches caused Expand_Ctrl_Function_Call to return early for such allocator expressions, bypassing the necessary Adjust call. This patch rectifies this by ensuring Adjust is invoked when appropriate.

For Context
secondary stack
A temporary stack area used by the compiler for specific purposes, such as holding function call results or intermediate values, to manage memory and calling conventions.
allocator
In Ada, a function or procedure that creates and initializes an object of a specific type, particularly when dealing with dynamically allocated objects.
controlled type
An Ada type that has associated primitive operations (like Adjust, Finalize, Read, Write) for managing its internal state, especially for types that involve dynamic memory allocation or resource management.
Adjust
A primitive operation for Ada controlled types. It is responsible for correctly updating the state of a controlled object when it is copied or assigned, especially to handle resource management.
Filed Under: adaregressionoptimization