]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove redundant protection against empty lists
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 1 Feb 2023 12:24:43 +0000 (13:24 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 22 May 2023 08:44:09 +0000 (10:44 +0200)
Calls to List_Length on No_List intentionally return 0 (and likewise
call to First on No_List intentionally return Empty), so explicit guards
against No_List are unnecessary. Code cleanup; semantics is unaffected.

gcc/ada/

* exp_aggr.adb (Aggregate_Size): Remove redundant calls to
Present.
* exp_ch5.adb (Expand_N_If_Statement): Likewise.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_warn.adb (Find_Var): Likewise.

gcc/ada/exp_aggr.adb
gcc/ada/exp_ch5.adb
gcc/ada/sem_prag.adb
gcc/ada/sem_warn.adb

index 58831bd51cad8f8f3ba870c605db8af5044a3680..e4b1991f4102bf41cb2b2c97307bbc61fd83619c 100644 (file)
@@ -7397,7 +7397,7 @@ package body Exp_Aggr is
          Comp   : Node_Id;
          Choice : Node_Id;
          Lo, Hi : Node_Id;
-         Siz     : Int := 0;
+         Siz    : Int;
 
          procedure Add_Range_Size;
          --  Compute number of components specified by a component association
@@ -7422,11 +7422,9 @@ package body Exp_Aggr is
          end Add_Range_Size;
 
       begin
-         --  Aggregate is either all positional or all named.
+         --  Aggregate is either all positional or all named
 
-         if Present (Expressions (N)) then
-            Siz := List_Length (Expressions (N));
-         end if;
+         Siz := List_Length (Expressions (N));
 
          if Present (Component_Associations (N)) then
             Comp := First (Component_Associations (N));
index 0c89856b58bf61f23571f405e1d7f20a4b6ddc31..dfe1112f3419e2469a68f7f2f3dc3315d05948b6 100644 (file)
@@ -4743,7 +4743,6 @@ package body Exp_Ch5 is
         and then not Opt.Suppress_Control_Flow_Optimizations
         and then Nkind (N) = N_If_Statement
         and then No (Elsif_Parts (N))
-        and then Present (Else_Statements (N))
         and then List_Length (Then_Statements (N)) = 1
         and then List_Length (Else_Statements (N)) = 1
       then
index 36c1add5ea4878ecfe0d1b94735db98bfc12ed22..5fe5d6a2d0fb6fc7e9e86172609d431b3ff61ec9 100644 (file)
@@ -11699,29 +11699,24 @@ package body Sem_Prag is
 
       --  Preset arguments
 
-      Arg_Count := 0;
-      Arg1      := Empty;
+      Arg_Count := List_Length (Pragma_Argument_Associations (N));
+      Arg1      := First (Pragma_Argument_Associations (N));
       Arg2      := Empty;
       Arg3      := Empty;
       Arg4      := Empty;
       Arg5      := Empty;
 
-      if Present (Pragma_Argument_Associations (N)) then
-         Arg_Count := List_Length (Pragma_Argument_Associations (N));
-         Arg1 := First (Pragma_Argument_Associations (N));
-
-         if Present (Arg1) then
-            Arg2 := Next (Arg1);
+      if Present (Arg1) then
+         Arg2 := Next (Arg1);
 
-            if Present (Arg2) then
-               Arg3 := Next (Arg2);
+         if Present (Arg2) then
+            Arg3 := Next (Arg2);
 
-               if Present (Arg3) then
-                  Arg4 := Next (Arg3);
+            if Present (Arg3) then
+               Arg4 := Next (Arg3);
 
-                  if Present (Arg4) then
-                     Arg5 := Next (Arg4);
-                  end if;
+               if Present (Arg4) then
+                  Arg5 := Next (Arg4);
                end if;
             end if;
          end if;
index 834d48d311cbe439e3908b8272cad852515d9b64..5dd7c17d4e29e0b4968536e7676971dacdacf0f4 100644 (file)
@@ -353,7 +353,7 @@ package body Sem_Warn is
             begin
                --  One argument, so check the argument
 
-               if Present (PA) and then List_Length (PA) = 1 then
+               if List_Length (PA) = 1 then
                   if Nkind (First (PA)) = N_Parameter_Association then
                      Find_Var (Explicit_Actual_Parameter (First (PA)));
                   else