https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127880

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Eric Botcazou
<[email protected]>:

https://gcc.gnu.org/g:877ce5e4ec4476be2167def58e35b393bd4e5e82

commit r16-9785-g877ce5e4ec4476be2167def58e35b393bd4e5e82
Author: Gary Dismukes <[email protected]>
Date:   Wed Jan 7 20:23:55 2026 +0000

    Ada: Visibility bug in instantiation with precondition on formal subprogram

    The compiler may issue an error saying that a global entity referenced in
    the precondition of a formal subprogram is not visible when the containing
    generic is instantiated at a place where the entity is not directly
visible.
    This was due to the formal subprogram's contract not having been analyzed
    in the generic template.  As a result, the nodes with global references
were
    not properly captured (by Save_Global_References).

    An additional problem was exposed, which was that references within
    contract aspect specifications of generic formals to other formals of the
    same generic were not being properly analyzed/resolved, due to copying
    the aspect specifications of the already-analyzed copy of the generic
    formal when building subprogram wrappers for the contracts.  This could
    lead to blowups in the back end due to references to the original formals
    occurring in the expansion of the instantiation.  This is addressed by
    copying the aspect specifications of the unanalyzed formals rather than
    those that were analyzed in the copy of the generic template.

    gcc/ada/
            PR ada/127880
            * contracts.adb (Analyze_Contracts): Add cases for formal
subprogram
            Nkinds so that Analyze_Entry_Or_Subprogram_Contract will be called
            for them.
            * sem_attr.adb (Analyze_Attribute_Old_Result): Account for the
cases
            of formal subprogram Nkinds, allowing Old attributes for those.
            * sem_ch12.adb (Build_Subprogram_Wrappers): Add a formal for
passing
            the unanalyzed generic formal, and use it for copying any aspect
            specifications of the generic formal rather than copying the
analyzed
            generic formal's aspects.
            (Analyze_One_Association): Pass Assoc.Un_Formal as an additional
            actual in the call to Build_Subprogram_Wrappers.

Reply via email to