https://gcc.gnu.org/g:5822a843ce51c6af030311af4f2de66727d480dd
commit r17-776-g5822a843ce51c6af030311af4f2de66727d480dd Author: Marc Poulhiès <[email protected]> Date: Fri Jan 23 12:12:47 2026 +0100 ada: fix: use correct scope when unnesting subprocedure By the original comment before this Analyze call, initially, the compiler was not creating any new entity, so scope information should be already there and correct. But now (~15y later), the Analyze call may indirectly create new entities (e.g. IType) that will use Current_Scope as their scope: this is incorrect and leads to a failed assertion in gcc-interface. This change correctly push/pop the current subp entity as the scope. gcc/ada/ChangeLog: * exp_unst.adb (Unnest_Subprogram): Push/Pop scope around Analyze call. Diff: --- gcc/ada/exp_unst.adb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_unst.adb b/gcc/ada/exp_unst.adb index 84db16ef3b88..0073e3f5832f 100644 --- a/gcc/ada/exp_unst.adb +++ b/gcc/ada/exp_unst.adb @@ -2266,18 +2266,16 @@ package body Exp_Unst is Insert_After (Ins, Asn); end if; - -- Analyze the assignment statement. We do - -- not need to establish the relevant scope - -- stack entries here, because we have - -- already set the correct entity references, - -- so no name resolution is required, and no - -- new entities are created, so we don't even - -- need to set the current scope. + -- Analyze the assignment statement. We set + -- the scope of the current subprogram, so + -- that newly created entities go in the + -- right entity chain. -- We analyze with all checks suppressed -- (since we do not expect any exceptions). - + Push_Scope (STJ.Ent); Analyze (Asn, Suppress => All_Checks); + Pop_Scope; end; Next_Elmt (Elmt);
