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

Ada: Fix visibility bug in generic with precondition on formal subprogram

This commit fixes a visibility issue in Ada generics with preconditions on formal subprograms, ensuring correct analysis and resolution of references.

This commit resolves a visibility bug in Ada generics where a global entity referenced in the precondition of a formal subprogram might not be visible during instantiation. The fix ensures that the formal subprogram’s contract is analyzed within the generic template, capturing global references correctly. Additionally, it addresses an issue where references to other formals within contract aspect specifications were not being properly analyzed, leading to potential backend issues.

In Details

The changes in contracts.adb, sem_attr.adb, and sem_ch12.adb address the incorrect analysis of contracts for formal subprograms in generics. Specifically, Analyze_Contracts is updated to handle formal subprogram Nkinds, and Build_Subprogram_Wrappers is modified to use unanalyzed generic formals when copying aspect specifications, preventing issues with references to original formals during expansion.

For Context

Generics in Ada allow writing code that works with different types or subprograms. Preconditions are conditions that must be true before a subprogram is called. This commit fixes a bug where the compiler would incorrectly report visibility errors when a generic subprogram with a precondition was instantiated, particularly when the precondition referenced global entities or other formal parameters of the generic. This ensures that preconditions are correctly checked, preventing unexpected behavior.

Filed Under: adagenericsvisibilitypreconditions