From: Steve Baird <ba...@adacore.com>

Fix two bugs uncovered by a recent ACATS test C3A1005: a freezing problem
and a case where a user-defined equality function for an incomplete type
was incorrectly hidden from use-clause visibility by the "corresponding"
predefined op (which doesn't actually exist).

gcc/ada/ChangeLog:

        * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Don't freeze here
        if Has_Delayed_Freeze returns True.
        * sem_type.adb (Valid_Equality_Arg): Treat an incomplete type like
        a limited type because neither has an implicitly-defined equality
        primitive.
        (Covers): If either argument is an incomplete type
        whose full view is available, then look through to the full view.
        * sem_res.adb (Resolve_Actuals): If the actual parameter type is
        complete and the formal parameter type is not, then update the
        formal parameter type to use the complete view.

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

---
 gcc/ada/sem_ch6.adb  |  4 +++-
 gcc/ada/sem_res.adb  |  9 +++++++++
 gcc/ada/sem_type.adb | 15 +++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index c200871b852..8cf191d751b 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -4135,7 +4135,9 @@ package body Sem_Ch6 is
                Set_Is_Public (Body_Id, False);
             end if;
 
-            Freeze_Before (N, Body_Id);
+            if not Has_Delayed_Freeze (Body_Id) then
+               Freeze_Before (N, Body_Id);
+            end if;
          end if;
 
          if Nkind (N) /= N_Subprogram_Body_Stub then
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index c8652eed796..6b673a9c198 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -4658,6 +4658,15 @@ package body Sem_Res is
             A_Typ := Etype (A);
             F_Typ := Etype (F);
 
+            --  If A_Typ is complete and F_Typ is not, then adjust F_Typ
+
+            if Ekind (F_Typ) = E_Incomplete_Type
+              and then Present (Full_View (F_Typ))
+              and then not Is_Incomplete_Type (A_Typ)
+            then
+               F_Typ := Full_View (F_Typ);
+            end if;
+
             --  An actual cannot be an untagged formal incomplete type
 
             if Ekind (A_Typ) = E_Incomplete_Type
diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb
index b76c6efd9d9..75e7dafbc60 100644
--- a/gcc/ada/sem_type.adb
+++ b/gcc/ada/sem_type.adb
@@ -1228,6 +1228,18 @@ package body Sem_Type is
          return Has_Non_Limited_View (T2)
            and then Covers (T1, Get_Full_View (Non_Limited_View (T2)));
 
+      --  Coverage for incomplete types
+
+      elsif Ekind (T1) = E_Incomplete_Type
+        and then Present (Full_View (T1))
+      then
+         return Covers (Full_View (T1), T2);
+
+      elsif Ekind (T2) = E_Incomplete_Type
+        and then Present (Full_View (T2))
+      then
+         return Covers (T1, Full_View (T2));
+
       --  Ada 2005 (AI-412): Coverage for regular incomplete subtypes
 
       elsif Ekind (T1) = E_Incomplete_Subtype then
@@ -3586,6 +3598,9 @@ package body Sem_Type is
       if Is_Anonymous_Access_Type (T) then
          return Ada_Version >= Ada_2005;
 
+      elsif Is_Incomplete_Type (T) then
+         return False;
+
       elsif not Is_Limited_Type (T) then
          return True;
 
-- 
2.43.0

Reply via email to