A previous patch fixed crashes on comparisons of string literals with
access to strings by making sure that resolution of operations was only
performed when operand types are actually compatible.

However, the check was incomplete. Indeed, using only
Has_Compatible_Type does not cover the case where the right operand's
type covers the left operand's, which caused programs such as the
following to fail:

procedure tmp is
   type Root is tagged null record;
   type Child is new Root with null record;
   type Grandchild is new Child with null record;

   GC : access Grandchild;
   CC : access Child'Class;
begin
   if GC = CC then
     null;
   end if;
end tmp;

The fix is trivial: when the type of the right operand covers the type
of the left one, allow resolution of the operation.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * sem_ch4.adb (Finc_Non_Universal_Interpretations): Fix check.
diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -6626,7 +6626,7 @@ package body Sem_Ch4 is
                Get_Next_Interp (Index, It);
             end loop;
          end if;
-      elsif Has_Compatible_Type (R, T1) then
+      elsif Has_Compatible_Type (R, T1) or else Covers (Etype (R), T1) then
          Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
       end if;
    end Find_Non_Universal_Interpretations;


Reply via email to