[COMMITTED] ada: Allow calls to Number_Formals when no formals are present

Message ID 20230728073042.1852207-1-poulhies@adacore.com
State Unresolved
Headers
Series [COMMITTED] ada: Allow calls to Number_Formals when no formals are present |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Marc Poulhiès July 28, 2023, 7:30 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

It is much simpler and safer for the routine Number_Formals to accept
subprogram entities that have no formals.

gcc/ada/

	* einfo-utils.adb (Number_Formals): Change types in body.
	* einfo-utils.ads (Number_Formals): Change type in spec.
	* einfo.ads (Number_Formals): Change type in comment.
	* sem_ch13.adb (Is_Property_Function): Fix style in a caller of
	Number_Formals that was likely to crash because of missing guards.

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

---
 gcc/ada/einfo-utils.adb | 4 ++--
 gcc/ada/einfo-utils.ads | 2 +-
 gcc/ada/einfo.ads       | 2 +-
 gcc/ada/sem_ch13.adb    | 6 +++++-
 4 files changed, 9 insertions(+), 5 deletions(-)
  

Patch

diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb
index dad3a654743..7fe517124d9 100644
--- a/gcc/ada/einfo-utils.adb
+++ b/gcc/ada/einfo-utils.adb
@@ -2105,8 +2105,8 @@  package body Einfo.Utils is
    -- Number_Formals --
    --------------------
 
-   function Number_Formals (Id : E) return Pos is
-      N      : Int;
+   function Number_Formals (Id : E) return Nat is
+      N      : Nat;
       Formal : Entity_Id;
 
    begin
diff --git a/gcc/ada/einfo-utils.ads b/gcc/ada/einfo-utils.ads
index fee771c20f4..20ca470d7ac 100644
--- a/gcc/ada/einfo-utils.ads
+++ b/gcc/ada/einfo-utils.ads
@@ -227,7 +227,7 @@  package Einfo.Utils is
    function Next_Stored_Discriminant (Id : E) return Entity_Id;
    function Number_Dimensions (Id : E) return Pos;
    function Number_Entries (Id : E) return Nat;
-   function Number_Formals (Id : E) return Pos;
+   function Number_Formals (Id : E) return Nat;
    function Object_Size_Clause (Id : E) return Node_Id;
    function Parameter_Mode (Id : E) return Formal_Kind;
    function Partial_Refinement_Constituents (Id : E) return L;
diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads
index b356b76f0de..d7690d9f88a 100644
--- a/gcc/ada/einfo.ads
+++ b/gcc/ada/einfo.ads
@@ -3832,7 +3832,7 @@  package Einfo is
 
 --    Number_Formals (synthesized)
 --       Applies to subprograms and subprogram types. Yields the number of
---       formals as a value of type Pos.
+--       formals as a value of type Nat.
 
 --    Object_Size_Clause (synthesized)
 --       Applies to entities for types and subtypes. If an object size clause
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index 585c0f33d8b..7cd0800a56c 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -16544,7 +16544,11 @@  package body Sem_Ch13 is
             It : Interp;
 
             function Is_Property_Function (E : Entity_Id) return Boolean;
-            --  Implements RM 7.3.4 definition of "property function".
+            --  Implements RM 7.3.4 definition of "property function"
+
+            --------------------------
+            -- Is_Property_Function --
+            --------------------------
 
             function Is_Property_Function (E : Entity_Id) return Boolean is
             begin