From: Bob Duff Date: Wed, 12 Nov 2025 19:53:17 +0000 (-0500) Subject: ada: Follow-on for duplicate formal iterator names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebabae605093e5a31c37ef6e5e3e809f13501f70;p=thirdparty%2Fgcc.git 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 --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 10744945ca7..d9ef17ffabc 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);