diff mbox series

[COMMITTED] ada: Prevent calculation of negative stack counts

Message ID 20240507080044.38255-1-poulhies@adacore.com
State New
Headers show
Series [COMMITTED] ada: Prevent calculation of negative stack counts | expand

Commit Message

Marc Poulhiès May 7, 2024, 8 a.m. UTC
From: Piotr Trojanek <trojanek@adacore.com>

Negative numbers of stack counts have no meaning.

gcc/ada/

	* lib.ads, lib.adb (Primary_Stack_Count, Sec_Stack_Count,
	Increment_Primary_Stack_Count, Increment_Sec_Stack_Count,
	Unit_Record): Stack counts are never negative.
	* ali.ads (Unit_Record): Likewise.
	* bindgen.adb (Num_Primary_Stacks, Num_Sec_Stacks): Likewise.
	* exp_ch3.adb (Count_Default_Sized_Task_Stacks): Likewise.
	* sem_util.ads, sem_util.adb (Number_Of_Elements_In_Array):
	Likewise.

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

---
 gcc/ada/ali.ads      |  4 ++--
 gcc/ada/bindgen.adb  |  4 ++--
 gcc/ada/exp_ch3.adb  |  2 +-
 gcc/ada/lib.adb      | 12 ++++++------
 gcc/ada/lib.ads      | 12 ++++++------
 gcc/ada/sem_util.adb |  4 ++--
 gcc/ada/sem_util.ads |  2 +-
 7 files changed, 20 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/ali.ads b/gcc/ada/ali.ads
index 23c744433a3..67b8fcd1b80 100644
--- a/gcc/ada/ali.ads
+++ b/gcc/ada/ali.ads
@@ -482,11 +482,11 @@  package ALI is
       --  Indicates whether a package body or a spec has a library-level
       --  finalization routine.
 
-      Primary_Stack_Count : Int;
+      Primary_Stack_Count : Nat;
       --  Indicates the number of task objects declared in this unit that have
       --  default sized primary stacks.
 
-      Sec_Stack_Count : Int;
+      Sec_Stack_Count : Nat;
       --  Indicates the number of task objects declared in this unit that have
       --  default sized secondary stacks.
    end record;
diff --git a/gcc/ada/bindgen.adb b/gcc/ada/bindgen.adb
index bffd1344212..fc834e3a9b6 100644
--- a/gcc/ada/bindgen.adb
+++ b/gcc/ada/bindgen.adb
@@ -57,11 +57,11 @@  package body Bindgen is
    Num_Elab_Calls : Nat := 0;
    --  Number of generated calls to elaboration routines
 
-   Num_Primary_Stacks : Int := 0;
+   Num_Primary_Stacks : Nat := 0;
    --  Number of default-sized primary stacks the binder needs to allocate for
    --  task objects declared in the program.
 
-   Num_Sec_Stacks : Int := 0;
+   Num_Sec_Stacks : Nat := 0;
    --  Number of default-sized primary stacks the binder needs to allocate for
    --  task objects declared in the program.
 
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index e9fab87365c..f934dbfddaa 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6738,7 +6738,7 @@  package body Exp_Ch3 is
                --  Then multiply the result by the size of the array
 
                declare
-                  Quantity : constant Int := Number_Of_Elements_In_Array (Typ);
+                  Quantity : constant Nat := Number_Of_Elements_In_Array (Typ);
                   --  Number_Of_Elements_In_Array is non-trival, consequently
                   --  its result is captured as an optimization.
 
diff --git a/gcc/ada/lib.adb b/gcc/ada/lib.adb
index ebd6bc99040..c465828c562 100644
--- a/gcc/ada/lib.adb
+++ b/gcc/ada/lib.adb
@@ -173,12 +173,12 @@  package body Lib is
       return Units.Table (U).OA_Setting;
    end OA_Setting;
 
-   function Primary_Stack_Count (U : Unit_Number_Type) return Int is
+   function Primary_Stack_Count (U : Unit_Number_Type) return Nat is
    begin
       return Units.Table (U).Primary_Stack_Count;
    end Primary_Stack_Count;
 
-   function Sec_Stack_Count  (U : Unit_Number_Type) return Int is
+   function Sec_Stack_Count  (U : Unit_Number_Type) return Nat is
    begin
       return Units.Table (U).Sec_Stack_Count;
    end Sec_Stack_Count;
@@ -1034,8 +1034,8 @@  package body Lib is
    -- Increment_Primary_Stack_Count --
    -----------------------------------
 
-   procedure Increment_Primary_Stack_Count (Increment : Int) is
-      PSC : Int renames Units.Table (Current_Sem_Unit).Primary_Stack_Count;
+   procedure Increment_Primary_Stack_Count (Increment : Nat) is
+      PSC : Nat renames Units.Table (Current_Sem_Unit).Primary_Stack_Count;
    begin
       PSC := PSC + Increment;
    end Increment_Primary_Stack_Count;
@@ -1044,8 +1044,8 @@  package body Lib is
    -- Increment_Sec_Stack_Count --
    -------------------------------
 
-   procedure Increment_Sec_Stack_Count (Increment : Int) is
-      SSC : Int renames Units.Table (Current_Sem_Unit).Sec_Stack_Count;
+   procedure Increment_Sec_Stack_Count (Increment : Nat) is
+      SSC : Nat renames Units.Table (Current_Sem_Unit).Sec_Stack_Count;
    begin
       SSC := SSC + Increment;
    end Increment_Sec_Stack_Count;
diff --git a/gcc/ada/lib.ads b/gcc/ada/lib.ads
index ee06cde2727..93ff1b13531 100644
--- a/gcc/ada/lib.ads
+++ b/gcc/ada/lib.ads
@@ -463,8 +463,8 @@  package Lib is
    function No_Elab_Code_All (U : Unit_Number_Type) return Boolean;
    function OA_Setting       (U : Unit_Number_Type) return Character;
    function Primary_Stack_Count
-                             (U : Unit_Number_Type) return Int;
-   function Sec_Stack_Count  (U : Unit_Number_Type) return Int;
+                             (U : Unit_Number_Type) return Nat;
+   function Sec_Stack_Count  (U : Unit_Number_Type) return Nat;
    function Source_Index     (U : Unit_Number_Type) return Source_File_Index;
    function Unit_File_Name   (U : Unit_Number_Type) return File_Name_Type;
    function Unit_Name        (U : Unit_Number_Type) return Unit_Name_Type;
@@ -686,11 +686,11 @@  package Lib is
    --  source unit, the criterion being that Get_Source_Unit yields the
    --  same value for each argument.
 
-   procedure Increment_Primary_Stack_Count (Increment : Int);
+   procedure Increment_Primary_Stack_Count (Increment : Nat);
    --  Increment the Primary_Stack_Count field for the current unit by
    --  Increment.
 
-   procedure Increment_Sec_Stack_Count (Increment : Int);
+   procedure Increment_Sec_Stack_Count (Increment : Nat);
    --  Increment the Sec_Stack_Count field for the current unit by Increment
 
    function Increment_Serial_Number return Nat;
@@ -861,8 +861,8 @@  private
       Ident_String           : Node_Id;
       Main_Priority          : Int;
       Main_CPU               : Int;
-      Primary_Stack_Count    : Int;
-      Sec_Stack_Count        : Int;
+      Primary_Stack_Count    : Nat;
+      Sec_Stack_Count        : Nat;
       Serial_Number          : Nat;
       Version                : Word;
       Error_Location         : Source_Ptr;
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index ebfe27a9bea..bee078e6df5 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -25372,12 +25372,12 @@  package body Sem_Util is
    -- Number_Of_Elements_In_Array --
    ---------------------------------
 
-   function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
+   function Number_Of_Elements_In_Array (T : Entity_Id) return Nat is
       Indx : Node_Id;
       Typ  : Entity_Id;
       Low  : Node_Id;
       High : Node_Id;
-      Num  : Int := 1;
+      Num  : Nat := 1;
 
    begin
       pragma Assert (Is_Array_Type (T));
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index db02d39fdee..83e824b3838 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -2785,7 +2785,7 @@  package Sem_Util is
    --   2) N is a comparison operator, one of the operands is null, and the
    --      type of the other operand is a descendant of System.Address.
 
-   function Number_Of_Elements_In_Array (T : Entity_Id) return Int;
+   function Number_Of_Elements_In_Array (T : Entity_Id) return Nat;
    --  Returns the number of elements in the array T if the index bounds of T
    --  is known at compile time. If the bounds are not known at compile time,
    --  the function returns the value zero.