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

Avoid use-before-definition within library unit subprograms.

The compiler now correctly inserts attribute-related subprograms for library units, preventing use-before-definition errors.

This change addresses a bug where Ada’s attribute subprograms were sometimes inserted incorrectly for library units, leading to crashes. The fix ensures that the compiler properly handles library unit subprogram bodies when generating attribute subprograms, avoiding cases where a procedure is called before its declaration is visible. This improves compiler stability and correctness when using attributes in Ada.

In Details

GCC's Ada front-end, specifically Expand_N_Attribute_Reference.Build_And_Insert_Type_Attr_Subp in exp_attr.adb, was failing to correctly place attribute-generated subprograms within the compilation unit's tree for library unit subprograms. This caused Glubsch (the internal representation of the program) to encounter a use-before-definition scenario during processing, leading to an assertion failure. The fix accounts for the specific context of library unit subprogram bodies, where the enclosing declaration list assumption no longer holds, and ensures proper tree insertion.

For Context

When you write code in Ada, the compiler sometimes needs to create special, hidden bits of code on your behalf, especially when you use language "attributes" (like ways to describe how data should be handled). This commit fixes a specific problem where the compiler would sometimes put these hidden pieces of code in the wrong place if your code was part of a 'library unit' (a reusable module of code without a main program). If this happened, the compiler would try to use that hidden code before it had officially been "declared," which is like trying to refer to a variable before you've told the computer it exists. This would cause the compiler to crash. The fix makes sure the compiler always puts these hidden code pieces in the right order and place, so compilation proceeds smoothly.

Filed Under: adacompiler-internalsbugfix