diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2024-05-21 08:40:06 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2024-06-20 10:50:56 +0200 |
commit | e8e0306649a09f47c429b36b7fcf95eaff100095 (patch) | |
tree | 490aabc3a215b9c32f9c8a494190f5d8ccf3f698 /gcc/ada | |
parent | 980fddd8d90c97d44074021c6121a8d134e6c88c (diff) | |
download | gcc-e8e0306649a09f47c429b36b7fcf95eaff100095.zip gcc-e8e0306649a09f47c429b36b7fcf95eaff100095.tar.gz gcc-e8e0306649a09f47c429b36b7fcf95eaff100095.tar.bz2 |
ada: Fix composition of primitive equality for untagged records with variant part
In Ada 2012, primitive equality operators of untagged record types compose
like those of tagged record types, but this has never been implemented for
untagged record types with a variant part.
gcc/ada/
* exp_ch4.adb (Expand_Composite_Equality): In the untagged record
case, always look for a user-defined equality operator in Ada 2012.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/exp_ch4.adb | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 983f662..1674d6c 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -2329,6 +2329,28 @@ package body Exp_Ch4 is -- Case of untagged record types elsif Is_Record_Type (Full_Type) then + -- Equality composes in Ada 2012 for untagged record types. It also + -- composes for bounded strings, because they are part of the + -- predefined environment (see 4.5.2(32.1/1)). We could make it + -- compose for bounded strings by making them tagged, or by making + -- sure all subcomponents are set to the same value, even when not + -- used. Instead, we have this special case in the compiler, because + -- it's more efficient. + + if Ada_Version >= Ada_2012 or else Is_Bounded_String (Comp_Type) then + declare + Eq_Call : constant Node_Id := + Build_Eq_Call (Comp_Type, Loc, Lhs, Rhs); + + begin + if Present (Eq_Call) then + return Eq_Call; + end if; + end; + end if; + + -- Check whether a TSS has been created for the type + Eq_Op := TSS (Full_Type, TSS_Composite_Equality); if Present (Eq_Op) then @@ -2355,34 +2377,6 @@ package body Exp_Ch4 is Parameter_Associations => New_List (L_Exp, R_Exp)); end; - -- Equality composes in Ada 2012 for untagged record types. It also - -- composes for bounded strings, because they are part of the - -- predefined environment (see 4.5.2(32.1/1)). We could make it - -- compose for bounded strings by making them tagged, or by making - -- sure all subcomponents are set to the same value, even when not - -- used. Instead, we have this special case in the compiler, because - -- it's more efficient. - - elsif Ada_Version >= Ada_2012 or else Is_Bounded_String (Comp_Type) - then - -- If no TSS has been created for the type, check whether there is - -- a primitive equality declared for it. - - declare - Op : constant Node_Id := - Build_Eq_Call (Comp_Type, Loc, Lhs, Rhs); - - begin - -- Use user-defined primitive if it exists, otherwise use - -- predefined equality. - - if Present (Op) then - return Op; - else - return Make_Op_Eq (Loc, Lhs, Rhs); - end if; - end; - else return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs); end if; |