GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ada

Ada: Fix finalization of renamed function call at library level

This commit fixes a regression where renaming a controlled function call at the library level could lead to a dangling reference.

This commit addresses a regression that caused incorrect finalization when a controlled function call was renamed at the library level. The compiler would create a dangling reference to a temporary object on the elaboration routine’s stack, leading to potential errors. The fix ensures that the renaming is handled correctly by either bailing out in Expand_Ctrl_Function_Call or rewriting the renaming as a regular object declaration in Expand_N_Object_Renaming_Declaration.

In Details

The issue occurs in the context of controlled types and renaming declarations at the library level. The fix involves modifications to exp_ch6.adb and exp_ch8.adb to handle the case where the renamed entity is a controlled function call whose result is not returned on the secondary stack. This avoids a dangling reference to a temporary created during elaboration.

For Context

In Ada, controlled types require special handling during object creation and destruction. Renaming a function call at the library level, particularly one involving controlled types, can lead to complications in how the compiler manages memory. This commit fixes a bug where the compiler could create a dangling reference, which is a pointer to memory that has already been freed, potentially leading to program crashes or unpredictable behavior.

Filed Under: adafinalizationcontrolled typesregression