When iterating over list elements with First/Next there is no need to
detect empty or non-existing list, because First intentionally returns
Empty in those cases.

Cleanup of code related to Unchecked_Unions; behaviour is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * exp_ch4.adb (Variant_Is_Unconstrained_UU): Remove redundant
        check for empty list.
        * exp_disp.adb (Find_Entry_Index): Simplify by removing
        redundant check and counting from zero; fix type of a local
        variable.
        * sem_ch12.adb (Save_Global_Descendant): Remove an unnecessary
        special-case for empty lists.
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -8170,26 +8170,18 @@ package body Exp_Ch4 is
            (Variant : Node_Id) return Boolean
          is
             Clist : constant Node_Id := Component_List (Variant);
+            Comp  : Node_Id := First (Component_Items (Clist));
 
          begin
-            if Is_Empty_List (Component_Items (Clist)) then
-               return False;
-            end if;
-
             --  We only need to test one component
 
-            declare
-               Comp : Node_Id := First (Component_Items (Clist));
-
-            begin
-               while Present (Comp) loop
-                  if Component_Is_Unconstrained_UU (Comp) then
-                     return True;
-                  end if;
+            while Present (Comp) loop
+               if Component_Is_Unconstrained_UU (Comp) then
+                  return True;
+               end if;
 
-                  Next (Comp);
-               end loop;
-            end;
+               Next (Comp);
+            end loop;
 
             --  None of the components withing the variant were of
             --  unconstrained Unchecked_Union type.


diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb
--- a/gcc/ada/exp_disp.adb
+++ b/gcc/ada/exp_disp.adb
@@ -6640,28 +6640,25 @@ package body Exp_Disp is
       ----------------------
 
       function Find_Entry_Index (E : Entity_Id) return Uint is
-         Index     : Uint := Uint_1;
-         Subp_Decl : Entity_Id;
+         Index     : Uint := Uint_0;
+         Subp_Decl : Node_Id;
 
       begin
-         if Present (Decls)
-           and then not Is_Empty_List (Decls)
-         then
-            Subp_Decl := First (Decls);
-            while Present (Subp_Decl) loop
-               if Nkind (Subp_Decl) = N_Entry_Declaration then
-                  if Defining_Identifier (Subp_Decl) = E then
-                     return Index;
-                  end if;
+         Subp_Decl := First (Decls);
+         while Present (Subp_Decl) loop
+            if Nkind (Subp_Decl) = N_Entry_Declaration then
+               Index := Index + 1;
 
-                  Index := Index + 1;
+               if Defining_Identifier (Subp_Decl) = E then
+                  exit;
                end if;
 
-               Next (Subp_Decl);
-            end loop;
-         end if;
+            end if;
+
+            Next (Subp_Decl);
+         end loop;
 
-         return Uint_0;
+         return Index;
       end Find_Entry_Index;
 
       --  Local variables


diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -16169,16 +16169,11 @@ package body Sem_Ch12 is
             pragma Assert (D /= Union_Id (No_List));
             --  Because No_List = Empty, which is in Node_Range above
 
-            if Is_Empty_List (List_Id (D)) then
-               null;
-
-            else
-               N1 := First (List_Id (D));
-               while Present (N1) loop
-                  Save_References (N1);
-                  Next (N1);
-               end loop;
-            end if;
+            N1 := First (List_Id (D));
+            while Present (N1) loop
+               Save_References (N1);
+               Next (N1);
+            end loop;
 
          --  Element list or other non-node field, nothing to do
 


Reply via email to