]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tweak container aggregate expansion code
authorRonan Desplanques <desplanques@adacore.com>
Mon, 15 Jul 2024 08:22:29 +0000 (10:22 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 2 Aug 2024 07:08:08 +0000 (09:08 +0200)
This patch makes a minor modification to Expand_Container_Aggregate
in order to silence a GNAT SAS false positive.

gcc/ada/

* exp_aggr.adb (Expand_Container_Aggregate): Remove variables.
(To_Int): New function.
(Add_Range_Size): Use newly introduced function.

gcc/ada/exp_aggr.adb

index 59ed75e8d6957878bafc39d3a7c83791441cc0ca..ed0dad1444b3c12a133d330dfe002081e0c92dab 100644 (file)
@@ -6642,8 +6642,6 @@ package body Exp_Aggr is
 
       Choice_Lo     : Node_Id := Empty;
       Choice_Hi     : Node_Id := Empty;
-      Int_Choice_Lo : Int;
-      Int_Choice_Hi : Int;
 
       Is_Indexed_Aggregate : Boolean := False;
 
@@ -6696,32 +6694,38 @@ package body Exp_Aggr is
          --------------------
 
          procedure Add_Range_Size is
-            Range_Int_Lo : Int;
-            Range_Int_Hi : Int;
+            function To_Int (Expr : N_Subexpr_Id) return Int;
+            --  Return the Int value corresponding to the bound Expr
 
-         begin
-            --  The bounds of the discrete range are integers or enumeration
-            --  literals
+            ------------
+            -- To_Int --
+            ------------
 
-            if Nkind (Lo) = N_Integer_Literal then
-               Range_Int_Lo := UI_To_Int (Intval (Lo));
-               Range_Int_Hi := UI_To_Int (Intval (Hi));
+            function To_Int (Expr : N_Subexpr_Id) return Int is
+            begin
+               --  The bounds of the discrete range are integers or enumeration
+               --  literals
+               return UI_To_Int
+                 ((if Nkind (Expr) = N_Integer_Literal then
+                     Intval (Expr)
+                   else
+                     Enumeration_Pos (Expr)));
+            end To_Int;
 
-            else
-               Range_Int_Lo := UI_To_Int (Enumeration_Pos (Lo));
-               Range_Int_Hi := UI_To_Int (Enumeration_Pos (Hi));
-            end if;
+            --  Local variables
+
+            Range_Int_Lo : constant Int := To_Int (Lo);
+            Range_Int_Hi : constant Int := To_Int (Hi);
 
+         begin
             Siz := Siz + Range_Int_Hi - Range_Int_Lo + 1;
 
-            if No (Choice_Lo) or else Range_Int_Lo < Int_Choice_Lo then
+            if No (Choice_Lo) or else Range_Int_Lo < To_Int (Choice_Lo) then
                Choice_Lo   := Lo;
-               Int_Choice_Lo := Range_Int_Lo;
             end if;
 
-            if No (Choice_Hi) or else Range_Int_Hi > Int_Choice_Hi then
+            if No (Choice_Hi) or else Range_Int_Hi > To_Int (Choice_Hi) then
                Choice_Hi   := Hi;
-               Int_Choice_Hi := Range_Int_Hi;
             end if;
          end Add_Range_Size;