diff mbox series

[Ada] ACATS C452005/C452006 memberships use wrong equality operation

Message ID 20200616130745.GA86973@adacore.com
State New
Headers show
Series [Ada] ACATS C452005/C452006 memberships use wrong equality operation | expand

Commit Message

Pierre-Marie de Rodat June 16, 2020, 1:07 p.m. UTC
ACATS tests C452005 and C452006 show that GNAT is using the wrong
equality operation for non record/non limited types as defined in RM
4.5.2 (28.1/4).

This is actually a follow up/complement of the previous change for
ACATS B452001 against RM 4.5.2(4.1/4).

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

2020-06-16  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* sem_aux.ads, sem_aux.adb (Is_Record_Or_Limited_Type): New
	function.
	* exp_ch4.adb, sem_ch4.adb (Analyze_Membership_Op,
	Expand_Set_Membership.Make_Cond): Choose between primitive and
	predefined equality for membership tests.
diff mbox series

Patch

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -12717,10 +12717,13 @@  package body Exp_Ch4 is
                 Left_Opnd  => L,
                 Right_Opnd => R);
 
-            --  We reset the Entity since we do not want to bypass the operator
-            --  resolution.
+            if Is_Record_Or_Limited_Type (Etype (Alt)) then
 
-            Set_Entity (Cond, Empty);
+               --  We reset the Entity in order to use the primitive equality
+               --  of the type, as per RM 4.5.2 (28.1/4).
+
+               Set_Entity (Cond, Empty);
+            end if;
          end if;
 
          return Cond;

--- gcc/ada/sem_aux.adb
+++ gcc/ada/sem_aux.adb
@@ -1330,6 +1330,15 @@  package body Sem_Aux is
                                N_Protected_Definition);
    end Is_Protected_Operation;
 
+   -------------------------------
+   -- Is_Record_Or_Limited_Type --
+   -------------------------------
+
+   function Is_Record_Or_Limited_Type (Typ : Entity_Id) return Boolean is
+   begin
+      return Is_Record_Type (Typ) or else Is_Limited_Type (Typ);
+   end Is_Record_Or_Limited_Type;
+
    ----------------------
    -- Nearest_Ancestor --
    ----------------------

--- gcc/ada/sem_aux.ads
+++ gcc/ada/sem_aux.ads
@@ -362,6 +362,9 @@  package Sem_Aux is
    --  Given a subprogram or entry, determines whether E is a protected entry
    --  or subprogram.
 
+   function Is_Record_Or_Limited_Type (Typ : Entity_Id) return Boolean;
+   --  Return True if Typ requires is a record or limited type.
+
    function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id;
    --  Given a subtype Typ, this function finds out the nearest ancestor from
    --  which constraints and predicates are inherited. There is no simple link

--- gcc/ada/sem_ch4.adb
+++ gcc/ada/sem_ch4.adb
@@ -3018,10 +3018,14 @@  package body Sem_Ch4 is
                Op := Make_Op_Ne (Loc, Left_Opnd  => L, Right_Opnd => R);
             end if;
 
-            --  We reset the Entity since we do not want to bypass the operator
-            --  resolution.
+            if Is_Record_Or_Limited_Type (Etype (L)) then
+
+               --  We reset the Entity in order to use the primitive equality
+               --  of the type, as per RM 4.5.2 (28.1/4).
+
+               Set_Entity (Op, Empty);
+            end if;
 
-            Set_Entity (Op, Empty);
             Rewrite (N, Op);
             Analyze (N);
             return;