diff mbox series

[COMMITTED,18/26] ada: Tweak container aggregate expansion code

Message ID 20240802071210.413366-18-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/26] ada: Fix detection of suspicious loop patterns | expand

Commit Message

Marc Poulhiès Aug. 2, 2024, 7:11 a.m. UTC
From: Ronan Desplanques <desplanques@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 59ed75e8d69..ed0dad1444b 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -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;