diff options
| -rw-r--r-- | gcc/ada/exp_ch5.adb | 11 |
1 files changed, 7 insertions, 4 deletions
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); |
