https://gcc.gnu.org/g:828a5b2d8dc965c07b1b606d3bb25c5b2248aeb8

commit r17-1170-g828a5b2d8dc965c07b1b606d3bb25c5b2248aeb8
Author: Ronan Desplanques <[email protected]>
Date:   Tue Mar 31 10:50:44 2026 +0200

    ada: Rename Has_Private_Component function
    
    The expression "private component" is best reserved for components of
    protected objects' private sections. This renames a function from
    "Has_Private_Component" to a more explicit name because that function is
    not about the protected object component case.
    
    gcc/ada/ChangeLog:
    
            * sem_util.ads (Has_Private_Component): Rename into...
            (Is_Incompletely_Defined): ...this.
            * sem_util.adb (Has_Private_Component): Rename into...
            (Is_Incompletely_Defined): ...this.
            (Check_Fully_Declared): Adapt to above renaming.
            * exp_ch3.adb (Freeze_Type): Likewise.
            * freeze.adb (Check_And_Freeze_Type): Likewise.
            * sem_aggr.adb (Array_Aggr_Subtype): Likewise.
            * sem_ch12.adb (Instantiate_Type): Likewise.
            * sem_ch13.adb (Rep_Item_Too_Early): Likewise.
            * sem_ch3.adb (Access_Definition, Analyze_Full_Type_Declaration,
            Analyze_Subtype_Declaration, Build_Derived_Access_Type,
            Copy_And_Build, Complete_Private_Subtype, Constrain_Access,
            Constrain_Array, Build_Constrained_Access_Type, 
Constrain_Concurrent,
            Constrain_Corresponding_Record, Copy_Array_Subtype_Attributes,
            Derived_Type_Declaration): Likewise.
            * sem_ch6.adb (Create_Extra_Formals): Likewise.
            * sem_res.adb (Make_Call_Into_Operator): Likewise.

Diff:
---
 gcc/ada/exp_ch3.adb  |   4 +-
 gcc/ada/freeze.adb   |   2 +-
 gcc/ada/sem_aggr.adb |  16 +++----
 gcc/ada/sem_ch12.adb |   4 +-
 gcc/ada/sem_ch13.adb |   4 +-
 gcc/ada/sem_ch3.adb  |  29 ++++++------
 gcc/ada/sem_ch6.adb  |   2 +-
 gcc/ada/sem_res.adb  |   2 +-
 gcc/ada/sem_util.adb | 129 ++++++++++++++++++++++++++-------------------------
 gcc/ada/sem_util.ads |   9 ++--
 10 files changed, 102 insertions(+), 99 deletions(-)

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index e8bccb22872b..38aafbf75788 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -10109,10 +10109,10 @@ package body Exp_Ch3 is
                Build_Finalization_Collection (Def_Id);
 
             --  Also create a finalization collection when the designated type
-            --  contains a private component. It is assumed that the full view
+            --  is not completely defined. It is assumed that the full view
             --  will be controlled.
 
-            elsif Has_Private_Component (Desig_Type) then
+            elsif Is_Incompletely_Defined (Desig_Type) then
                Build_Finalization_Collection
                  (Typ            => Def_Id,
                   For_Private    => True,
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 13d3a7f2e34d..2b9ef460c362 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -9419,7 +9419,7 @@ package body Freeze is
             Check_Fully_Declared (Typ, N);
 
             if Error_Posted (N) then
-               if Has_Private_Component (Typ)
+               if Is_Incompletely_Defined (Typ)
                  and then not Is_Private_Type (Typ)
                then
                   Error_Msg_NE ("\\type& has private component", N, Typ);
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 5f6570f36f08..1d39bd7d8456 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -735,14 +735,14 @@ package body Sem_Aggr is
 
       Itype := Create_Itype (E_Array_Subtype, N);
 
-      Set_First_Rep_Item         (Itype, First_Rep_Item        (Typ));
-      Set_Convention             (Itype, Convention            (Typ));
-      Set_Depends_On_Private     (Itype, Has_Private_Component (Typ));
-      Set_Etype                  (Itype, Base_Type             (Typ));
-      Set_Has_Alignment_Clause   (Itype, Has_Alignment_Clause  (Typ));
-      Set_Is_Aliased             (Itype, Is_Aliased            (Typ));
-      Set_Is_Independent         (Itype, Is_Independent        (Typ));
-      Set_Depends_On_Private     (Itype, Depends_On_Private    (Typ));
+      Set_First_Rep_Item         (Itype, First_Rep_Item          (Typ));
+      Set_Convention             (Itype, Convention              (Typ));
+      Set_Depends_On_Private     (Itype, Is_Incompletely_Defined (Typ));
+      Set_Etype                  (Itype, Base_Type               (Typ));
+      Set_Has_Alignment_Clause   (Itype, Has_Alignment_Clause    (Typ));
+      Set_Is_Aliased             (Itype, Is_Aliased              (Typ));
+      Set_Is_Independent         (Itype, Is_Independent          (Typ));
+      Set_Depends_On_Private     (Itype, Depends_On_Private      (Typ));
 
       Copy_Suppress_Status (Index_Check,  Typ, Itype);
       Copy_Suppress_Status (Length_Check, Typ, Itype);
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index ae9f76d37912..fb0d06e348c6 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -15785,7 +15785,7 @@ package body Sem_Ch12 is
             Act_T := Full_View (Act_T);
             Set_Entity (Actual, Act_T);
 
-            if Has_Private_Component (Act_T) then
+            if Is_Incompletely_Defined (Act_T) then
                Error_Msg_N
                  ("premature use of type with private component", Actual);
             end if;
@@ -15803,7 +15803,7 @@ package body Sem_Ch12 is
          then
             Error_Msg_N ("premature use of private type", Actual);
 
-         elsif Has_Private_Component (Act_T) then
+         elsif Is_Incompletely_Defined (Act_T) then
             Error_Msg_N
               ("premature use of type with private component", Actual);
          end if;
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index a6a25aefc868..773fa64a3e8f 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -16783,10 +16783,10 @@ package body Sem_Ch13 is
            ("representation item must be after full type declaration", N);
          return True;
 
-      --  If the type has incomplete components, a representation clause is
+      --  If the type is not completely defined, a representation clause is
       --  illegal but stream attributes and Convention pragmas are correct.
 
-      elsif Has_Private_Component (T) then
+      elsif Is_Incompletely_Defined (T) then
          if Nkind (N) = N_Pragma then
             return False;
 
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 7e28881aeb0b..1cfe48db4d74 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -904,7 +904,7 @@ package body Sem_Ch3 is
       --  set, as required by gigi. This is necessary in the case of the
       --  Task_Body_Procedure.
 
-      if not Has_Private_Component (Desig_Type) then
+      if not Is_Incompletely_Defined (Desig_Type) then
          Layout_Type (Anon_Type);
       end if;
 
@@ -3421,7 +3421,7 @@ package body Sem_Ch3 is
 
       --  Some common processing for all types
 
-      Set_Depends_On_Private (T, Has_Private_Component (T));
+      Set_Depends_On_Private (T, Is_Incompletely_Defined (T));
       Check_Ops_From_Incomplete_Type;
 
       --  Both the declared entity, and its anonymous base type if one was
@@ -6291,7 +6291,7 @@ package body Sem_Ch3 is
       T := Etype (Id);
 
       Set_Is_Immediately_Visible   (Id, True);
-      Set_Depends_On_Private       (Id, Has_Private_Component (T));
+      Set_Depends_On_Private       (Id, Is_Incompletely_Defined (T));
       Set_Is_Descendant_Of_Address (Id, Is_Descendant_Of_Address (T));
 
       if Is_Interface (T) then
@@ -7362,7 +7362,7 @@ package body Sem_Ch3 is
       Set_Size_Info          (Derived_Type, Parent_Type);
       Copy_RM_Size           (To => Derived_Type, From => Parent_Type);
       Set_Depends_On_Private (Derived_Type,
-                              Has_Private_Component (Derived_Type));
+                              Is_Incompletely_Defined (Derived_Type));
       Conditional_Delay      (Derived_Type, Subt);
 
       if Is_Access_Subprogram_Type (Derived_Type)
@@ -8504,7 +8504,7 @@ package body Sem_Ch3 is
          Set_Is_Frozen             (Full_Der, False);
          Set_Freeze_Node           (Full_Der, Empty);
          Set_Depends_On_Private
-           (Full_Der, Has_Private_Component (Full_Der));
+           (Full_Der, Is_Incompletely_Defined (Full_Der));
          Set_Is_Public             (Full_Der, Is_Public (Derived_Type));
          Set_Is_Implicit_Full_View (Full_Der);
 
@@ -13655,7 +13655,7 @@ package body Sem_Ch3 is
       end if;
 
       Set_First_Rep_Item     (Full, First_Rep_Item (Full_Base));
-      Set_Depends_On_Private (Full, Has_Private_Component (Full));
+      Set_Depends_On_Private (Full, Is_Incompletely_Defined (Full));
 
       --  When prefixed calls are enabled for untagged types, the subtype
       --  shares the primitive operations of its base type. Do this even
@@ -14324,7 +14324,8 @@ package body Sem_Ch3 is
       Set_Size_Info                (Def_Id, T);
       Set_Is_Constrained           (Def_Id, Constraint_OK);
       Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
-      Set_Depends_On_Private       (Def_Id, Has_Private_Component (Def_Id));
+      Set_Depends_On_Private
+        (Def_Id, Is_Incompletely_Defined (Def_Id));
       Set_Is_Access_Constant       (Def_Id, Is_Access_Constant (T));
       Set_Can_Never_Be_Null        (Def_Id, Can_Never_Be_Null (T));
 
@@ -14493,7 +14494,7 @@ package body Sem_Ch3 is
                              (Def_Id, Is_FLB_Array_Subtype);
       Set_Is_Aliased         (Def_Id, Is_Aliased (T));
       Set_Is_Independent     (Def_Id, Is_Independent (T));
-      Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
+      Set_Depends_On_Private (Def_Id, Is_Incompletely_Defined (Def_Id));
 
       Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
       Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
@@ -14618,7 +14619,7 @@ package body Sem_Ch3 is
             Set_Etype                    (Itype, Base_Type      (Old_Type));
             Set_Size_Info                (Itype,                (Old_Type));
             Set_Directly_Designated_Type (Itype, Desig_Subtype);
-            Set_Depends_On_Private       (Itype, Has_Private_Component
+            Set_Depends_On_Private       (Itype, Is_Incompletely_Defined
                                                                 (Old_Type));
             Set_Is_Access_Constant       (Itype, Is_Access_Constant
                                                                 (Old_Type));
@@ -14958,7 +14959,7 @@ package body Sem_Ch3 is
          Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
          Set_First_Private_Entity (Def_Id, First_Private_Entity (T_Ent));
 
-         Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
+         Set_Depends_On_Private (Def_Id, Is_Incompletely_Defined (Def_Id));
          Set_Corresponding_Record_Type (Def_Id,
            Constrain_Corresponding_Record (Def_Id, T_Val, Related_Nod));
 
@@ -15011,7 +15012,7 @@ package body Sem_Ch3 is
            (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
       end if;
 
-      Set_Depends_On_Private      (T_Sub, Has_Private_Component (T_Sub));
+      Set_Depends_On_Private      (T_Sub, Is_Incompletely_Defined (T_Sub));
 
       if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
          Conditional_Delay (T_Sub, Corr_Rec);
@@ -15838,7 +15839,7 @@ package body Sem_Ch3 is
       Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
       Set_Treat_As_Volatile       (T1, Treat_As_Volatile       (T2));
       Set_Is_Constrained          (T1, Is_Constrained          (T2));
-      Set_Depends_On_Private      (T1, Has_Private_Component   (T2));
+      Set_Depends_On_Private      (T1, Is_Incompletely_Defined (T2));
       Inherit_Rep_Item_Chain      (T1,                          T2);
       Set_Convention              (T1, Convention              (T2));
       Set_Is_Limited_Composite    (T1, Is_Limited_Composite    (T2));
@@ -18235,7 +18236,7 @@ package body Sem_Ch3 is
 
       elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
               and then not Comes_From_Generic (Parent_Type))
-        or else Has_Private_Component (Parent_Type)
+        or else Is_Incompletely_Defined (Parent_Type)
       then
          --  The ancestor type of a formal type can be incomplete, in which
          --  case only the operations of the partial view are available in the
@@ -18247,7 +18248,7 @@ package body Sem_Ch3 is
             null;
 
          elsif No (Underlying_Type (Parent_Type))
-           or else Has_Private_Component (Parent_Type)
+           or else Is_Incompletely_Defined (Parent_Type)
          then
             Error_Msg_N
               ("premature derivation of derived or private type", Indic);
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 3016daf2c2f5..568b7d46db67 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -9471,7 +9471,7 @@ package body Sem_Ch6 is
               (Formal_Typ, Incomplete_View_From_Limited_With (Result_Subt));
             Set_Etype (Formal_Typ, Formal_Typ);
             Set_Depends_On_Private
-              (Formal_Typ, Has_Private_Component (Formal_Typ));
+              (Formal_Typ, Is_Incompletely_Defined (Formal_Typ));
             Set_Is_Public (Formal_Typ, Is_Public (Scope (Formal_Typ)));
             Set_Is_Access_Constant (Formal_Typ, False);
 
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 9a9ae4bc4ca2..08d45ebca33e 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -1821,7 +1821,7 @@ package body Sem_Res is
                      Orig_Type := Type_In_P (Is_Composite_Type'Access);
 
                      if Present (Orig_Type) then
-                        if Has_Private_Component (Orig_Type) then
+                        if Is_Incompletely_Defined (Orig_Type) then
                            Orig_Type := Empty;
                         else
                            Set_Etype (Act1, Orig_Type);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 9348bf87d7fa..0f576a3941c6 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -2612,12 +2612,11 @@ package body Sem_Util is
               ("premature usage of incomplete}", N, First_Subtype (T));
          end if;
 
-      --  The other case is a type with a private component (including itself)
-      --  that has not yet received a full declaration. But we exclude formal
+      --  The other case is an incompletely defined type. But we exclude formal
       --  types, as well as references in generic units to entities declared
       --  outside of them, and all references in spec expressions.
 
-      elsif Has_Private_Component (T)
+      elsif Is_Incompletely_Defined (T)
         and then not Is_Generic_Type (Root_Type (T))
         and then (not Is_Generic_Unit (Current_Scope)
                    or else Scope_Within_Or_Same (Scope (T), Current_Scope))
@@ -13750,67 +13749,6 @@ package body Sem_Util is
         N_Slice;
    end Has_Prefix;
 
-   ---------------------------
-   -- Has_Private_Component --
-   ---------------------------
-
-   function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
-      Btype     : Entity_Id := Base_Type (Type_Id);
-      Component : Entity_Id;
-
-   begin
-      if Error_Posted (Type_Id)
-        or else Error_Posted (Btype)
-      then
-         return False;
-      end if;
-
-      if Is_Class_Wide_Type (Btype) then
-         Btype := Root_Type (Btype);
-      end if;
-
-      if Is_Private_Type (Btype) then
-         declare
-            UT : constant Entity_Id := Underlying_Type (Btype);
-         begin
-            if No (UT) then
-               if No (Full_View (Btype)) then
-                  return not Is_Generic_Type (Btype)
-                            and then
-                         not Is_Generic_Type (Root_Type (Btype));
-               else
-                  return not Is_Generic_Type (Root_Type (Full_View (Btype)));
-               end if;
-            else
-               return not Is_Frozen (UT) and then Has_Private_Component (UT);
-            end if;
-         end;
-
-      elsif Is_Array_Type (Btype) then
-         return Has_Private_Component (Component_Type (Btype));
-
-      elsif Is_Record_Type (Btype) then
-         Component := First_Component (Btype);
-         while Present (Component) loop
-            if Has_Private_Component (Etype (Component)) then
-               return True;
-            end if;
-
-            Next_Component (Component);
-         end loop;
-
-         return False;
-
-      elsif Is_Protected_Type (Btype)
-        and then Present (Corresponding_Record_Type (Btype))
-      then
-         return Has_Private_Component (Corresponding_Record_Type (Btype));
-
-      else
-         return False;
-      end if;
-   end Has_Private_Component;
-
    --------------------------------
    -- Has_Relaxed_Initialization --
    --------------------------------
@@ -18676,6 +18614,69 @@ package body Sem_Util is
       return False;
    end Is_In_Context_Clause;
 
+   -----------------------------
+   -- Is_Incompletely_Defined --
+   -----------------------------
+
+   function Is_Incompletely_Defined (Type_Id : Entity_Id) return Boolean is
+      Btype     : Entity_Id := Base_Type (Type_Id);
+      Component : Entity_Id;
+
+   begin
+      if Error_Posted (Type_Id)
+        or else Error_Posted (Btype)
+      then
+         return False;
+      end if;
+
+      if Is_Class_Wide_Type (Btype) then
+         Btype := Root_Type (Btype);
+      end if;
+
+      if Is_Private_Type (Btype) then
+         declare
+            UT : constant Entity_Id := Underlying_Type (Btype);
+         begin
+            if No (UT) then
+               if No (Full_View (Btype)) then
+                  return not Is_Generic_Type (Btype)
+                            and then
+                         not Is_Generic_Type (Root_Type (Btype));
+               else
+                  return not Is_Generic_Type (Root_Type (Full_View (Btype)));
+               end if;
+            else
+               return
+                 not Is_Frozen (UT) and then Is_Incompletely_Defined (UT);
+            end if;
+         end;
+
+      elsif Is_Array_Type (Btype) then
+         return Is_Incompletely_Defined (Component_Type (Btype));
+
+      elsif Is_Record_Type (Btype) then
+         Component := First_Component (Btype);
+         while Present (Component) loop
+            if Is_Incompletely_Defined (Etype (Component)) then
+               return True;
+            end if;
+
+            Next_Component (Component);
+         end loop;
+
+         return False;
+
+      elsif Is_Protected_Type (Btype)
+        and then Present (Corresponding_Record_Type (Btype))
+      then
+         return
+           Is_Incompletely_Defined (Corresponding_Record_Type (Btype));
+
+      else
+         return False;
+      end if;
+   end Is_Incompletely_Defined;
+
    ---------------------------
    -- Is_Independent_Object --
    ---------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 9913e9410369..98a7ae8be51c 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1621,10 +1621,6 @@ package Sem_Util is
    function Has_Prefix (N : Node_Id) return Boolean;
    --  Return True if N has attribute Prefix
 
-   function Has_Private_Component (Type_Id : Entity_Id) return Boolean;
-   --  Check if a type has a (sub)component of a private type that has not
-   --  yet received a full declaration.
-
    function Has_Relaxed_Initialization (E : Entity_Id) return Boolean;
    --  Returns True iff entity E is subject to the Relaxed_Initialization
    --  aspect. Entity E can be either type, variable, constant, subprogram or
@@ -2259,6 +2255,11 @@ package Sem_Util is
    --  Returns True if N appears within the context clause of a unit, and False
    --  for any other placement.
 
+   function Is_Incompletely_Defined (Type_Id : Entity_Id) return Boolean;
+   --  Returns True iff Type_Id is incompletely defined. See RM 3.11.1 (8) for
+   --  the definition of "completely defined". Note that "incompletely defined"
+   --  is also used in the Ada RM, for example in RM 12.5.1 (1/5).
+
    function Is_Independent_Object (N : Node_Id) return Boolean;
    --  Determine whether arbitrary node N denotes a reference to an independent
    --  object as per RM C.6(8).

Reply via email to