From d51bf619f723292fd1475deb58b7b14144495648 Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 7 Apr 2020 11:05:59 -0400 Subject: [PATCH] [Ada] ACATS C452005/C452006 memberships use wrong equality operation 2020-06-16 Arnaud Charlet 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. --- gcc/ada/exp_ch4.adb | 9 ++++++--- gcc/ada/sem_aux.adb | 9 +++++++++ gcc/ada/sem_aux.ads | 3 +++ gcc/ada/sem_ch4.adb | 10 +++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index f5ad90a4111..3d706bf9507 100644 --- a/gcc/ada/exp_ch4.adb +++ b/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; diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb index 0cd538ae9d5..dbff7d8e20c 100644 --- a/gcc/ada/sem_aux.adb +++ b/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 -- ---------------------- diff --git a/gcc/ada/sem_aux.ads b/gcc/ada/sem_aux.ads index 41ce3f0aad4..c15c2712e2a 100644 --- a/gcc/ada/sem_aux.ads +++ b/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 diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index 445122fd91e..fe8aed59768 100644 --- a/gcc/ada/sem_ch4.adb +++ b/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; -- 2.30.2