[COMMITTED] ada: Ignore unconstrained components as inputs for Depends

Message ID 20231219143050.455490-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Ignore unconstrained components as inputs for Depends |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès Dec. 19, 2023, 2:30 p.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

The current wording of SPARK RM 6.1.5(5) about the inputs for the
Depends contract doesn't mention "a record with at least one
unconstrained component".

gcc/ada/

	* sem_prag.adb (Is_Unconstrained_Or_Tagged_Item): Update comment
	and body.

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

---
 gcc/ada/sem_prag.adb | 38 ++------------------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index db20f20b9f1..a2e705110de 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -283,8 +283,7 @@  package body Sem_Prag is
    function Is_Unconstrained_Or_Tagged_Item (Item : Entity_Id) return Boolean;
    --  Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
    --  pragma Depends. Determine whether the type of dependency item Item is
-   --  tagged, unconstrained array, unconstrained record or a record with at
-   --  least one unconstrained component.
+   --  tagged, unconstrained array or unconstrained record.
 
    procedure Record_Possible_Body_Reference
      (State_Id : Entity_Id;
@@ -32957,36 +32956,7 @@  package body Sem_Prag is
    function Is_Unconstrained_Or_Tagged_Item
      (Item : Entity_Id) return Boolean
    is
-      function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean;
-      --  Determine whether record type Typ has at least one unconstrained
-      --  component.
-
-      ---------------------------------
-      -- Has_Unconstrained_Component --
-      ---------------------------------
-
-      function Has_Unconstrained_Component (Typ : Entity_Id) return Boolean is
-         Comp : Entity_Id;
-
-      begin
-         Comp := First_Component (Typ);
-         while Present (Comp) loop
-            if Is_Unconstrained_Or_Tagged_Item (Comp) then
-               return True;
-            end if;
-
-            Next_Component (Comp);
-         end loop;
-
-         return False;
-      end Has_Unconstrained_Component;
-
-      --  Local variables
-
       Typ : constant Entity_Id := Etype (Item);
-
-   --  Start of processing for Is_Unconstrained_Or_Tagged_Item
-
    begin
       if Is_Tagged_Type (Typ) then
          return True;
@@ -32995,11 +32965,7 @@  package body Sem_Prag is
          return True;
 
       elsif Is_Record_Type (Typ) then
-         if Has_Discriminants (Typ) and then not Is_Constrained (Typ) then
-            return True;
-         else
-            return Has_Unconstrained_Component (Typ);
-         end if;
+         return Has_Discriminants (Typ) and then not Is_Constrained (Typ);
 
       elsif Is_Private_Type (Typ) and then Has_Discriminants (Typ) then
          return True;