https://gcc.gnu.org/g:ebabae605093e5a31c37ef6e5e3e809f13501f70
commit r16-5479-gebabae605093e5a31c37ef6e5e3e809f13501f70 Author: Bob Duff <[email protected]> Date: Wed Nov 12 14:53:17 2025 -0500 ada: Follow-on for duplicate formal iterator names A previous fix titled "Avoid incorrect errors for duplicate formal iterator names" caused regressions. This patch cleans it up. In particular, the previous patch involved calling Preanalyze on a block statement in order to get the scope created, and then later calling Analyze on the same block statement. This caused certain temps created inside the block statement to be incorrectly duplicated. The fix here is to avoid setting the Statements of the block until after it has been preanalyzed. gcc/ada/ChangeLog: * exp_ch5.adb (Expand_Formal_Container_Loop): Preanalyze block with empty statements; then set the statements later before doing Analyze of the block. Diff: --- gcc/ada/exp_ch5.adb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 10744945ca7b..d9ef17ffabc2 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -4548,17 +4548,20 @@ package body Exp_Ch5 is Declarations => New_List (Init_Decl), Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, - Statements => New_List (New_Loop)))); + Statements => Empty_List))); -- The loop parameter is declared by an object declaration (Init_Decl), -- but within the loop we must prevent user assignments to it, so we -- analyze Init_Decl and reset the entity kind, before analyzing the - -- rest of the loop. First Preanalyze the block statement, to set its - -- Identifier, and then push that as the scope in which to analyze - -- Init_Decl. + -- rest of the loop. First Preanalyze the (empty) block statement, + -- to set its Identifier, and then push that as the scope in which + -- to analyze Init_Decl. Fill in the Statements after preanalysis; + -- otherwise we incorrectly duplicate whatever temps are created + -- for the loop. Preanalyze (N); Push_Scope (Entity (Identifier (N))); + Set_Statements (Handled_Statement_Sequence (N), New_List (New_Loop)); Analyze (Init_Decl); Init_Name := Defining_Identifier (Init_Decl);
