Before this commit, the following program would make the compiler crash:

procedure Main is
   ConstantString1 : aliased String := "Class1";
   My_Access : access String := ConstantString1'Access;
begin
   if "Class1" = My_Access then
      null;
   end if;
end Main;

This was because when an access type was given on the right side of an
operator, GNAT assumed that an interpretation for the operator existed.
This assumption resulted in no error being thrown and Gigi crashing when
encountering the malformed tree.

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

gcc/ada/

        * sem_ch4.adb (Find_Non_Universal_Interpretations): Check if
        types are compatible before adding interpretation.
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;
-      else
+      elsif Has_Compatible_Type (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