[Ada] Link error due to negated intrinsic comparison
authorHristian Kirtchev <kirtchev@adacore.com>
Thu, 11 Jul 2019 08:01:49 +0000 (08:01 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 11 Jul 2019 08:01:49 +0000 (08:01 +0000)
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.

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.

From-SVN: r273385

gcc/ada/ChangeLog
gcc/ada/sem_res.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/equal9.adb [new file with mode: 0644]

index 79ee0b11ed4e8efc5ed08f46374cc734a78b586c..9d5a50f163f66d2bae71d49376dc1ca40f28411b 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-11  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * sem_res.adb (Resolve_Op_Not): Do not rewrite an equality
+       operator into a function call when the operator is intrinsic.
+
 2019-07-11  Thomas Quinot  <quinot@adacore.com>
 
        * sem_prag.adb (Analyze_Pragma, case pragma Check): Do not call
index 78cbac09e36881e5263146300462057423f23ba7..c17b28d2a5e49fb9144beaa12dbe625abf229528 100644 (file)
@@ -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
index 66d1e3ed5bec8e722ee2bd7ba279cacf1bebca4d..a761f79f7a2fd4fdc2e8f2039c6e3d3050919891 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-11  Hristian Kirtchev  <kirtchev@adacore.com>
+
+       * gnat.dg/equal9.adb: New testcase.
+
 2019-07-11  Thomas Quinot  <quinot@adacore.com>
 
        * gnat.dg/scos1.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/equal9.adb b/gcc/testsuite/gnat.dg/equal9.adb
new file mode 100644 (file)
index 0000000..aa60d5b
--- /dev/null
@@ -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;