]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious compilation error with repeated loop index
authorJavier Miranda <miranda@adacore.com>
Thu, 6 Feb 2025 09:40:57 +0000 (09:40 +0000)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 5 Jun 2025 13:39:51 +0000 (15:39 +0200)
When multiple for-loop statements in the same scope use the
same index name to iterate through container elements, the
compiler reports a spurious error indicating a conflict
between index names.

gcc/ada/ChangeLog:

* exp_ch7.adb (Process_Object_Declaration): Avoid generating
duplicate names for master nodes.

gcc/ada/exp_ch7.adb

index 67af1d772631692b63bba84201b7a4050d837402..905094c7e404099f3f992273fb777270676e75f0 100644 (file)
@@ -2783,16 +2783,31 @@ package body Exp_Ch7 is
             Master_Node_Id :=
               Make_Defining_Identifier (Master_Node_Loc,
                 Chars => New_External_Name (Chars (Obj_Id), Suffix => "MN"));
+
             Master_Node_Decl :=
               Make_Master_Node_Declaration (Master_Node_Loc,
                 Master_Node_Id, Obj_Id);
 
             Push_Scope (Scope (Obj_Id));
+
+            --  Avoid generating duplicate names for master nodes
+
+            if Ekind (Obj_Id) = E_Loop_Parameter
+              and then
+                Present (Current_Entity_In_Scope (Chars (Master_Node_Id)))
+            then
+               Set_Chars (Master_Node_Id,
+                 New_External_Name (Chars (Obj_Id),
+                   Suffix => "MN",
+                   Suffix_Index => -1));
+            end if;
+
             if not Has_Strict_Ctrl_Objs or else Count = 1 then
                Prepend_To (Decls, Master_Node_Decl);
             else
                Insert_Before (Decl, Master_Node_Decl);
             end if;
+
             Analyze (Master_Node_Decl);
             Pop_Scope;