[Ada] Link error due to negated intrinsic comparison

Message ID 20190711080343.GA95135@adacore.com
State New
Headers show
Series
  • [Ada] Link error due to negated intrinsic comparison
Related show

Commit Message

Pierre-Marie de Rodat July 11, 2019, 8:03 a.m.
This patch corrects the resolution of operator "not" when the expression
being negated is an equality operator to prevent the transformation of
an intrinsic equality operator into a function call.

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

2019-07-11  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Op_Not): Do not rewrite an equality
	operator into a function call when the operator is intrinsic.

gcc/testsuite/

	* gnat.dg/equal9.adb: New testcase.

Patch

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -10091,15 +10091,20 @@  package body Sem_Res is
 
          declare
             Opnd : constant Node_Id := Right_Opnd (N);
+            Op_Id : Entity_Id;
+
          begin
             if B_Typ = Standard_Boolean
               and then Nkind_In (Opnd, N_Op_Eq, N_Op_Ne)
               and then Is_Overloaded (Opnd)
             then
                Resolve_Equality_Op (Opnd, B_Typ);
+               Op_Id := Entity (Opnd);
 
-               if Ekind (Entity (Opnd)) = E_Function then
-                  Rewrite_Operator_As_Call (Opnd, Entity (Opnd));
+               if Ekind (Op_Id) = E_Function
+                 and then not Is_Intrinsic_Subprogram (Op_Id)
+               then
+                  Rewrite_Operator_As_Call (Opnd, Op_Id);
                end if;
 
                if not Inside_A_Generic or else Is_Entity_Name (Opnd) then

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/equal9.adb
@@ -0,0 +1,26 @@ 
+--  { dg-do run }
+
+with Ada.Text_IO; use Ada.Text_IO;
+with System;      use System;
+
+procedure Equal9 is
+   Val : Address := Null_Address;
+begin
+   if Val = Null_Address then
+      Put_Line ("= OK");
+   else
+      raise Program_Error;
+   end if;
+
+   if Val /= Null_Address then
+      raise Program_Error;
+   else
+      Put_Line ("/= OK");
+   end if;
+
+   if not (Val = Null_Address) then
+      raise Program_Error;
+   else
+      Put_Line ("not = OK");
+   end if;
+end Equal9;