The equality of arrays inside records always applies the predefined
equality, just like for elementary types. In Expand_Composite_Equality
we had some dedicated code for arrays inside records which was failing
to duplicate a similar code in Expand_N_Op_Eq, e.g. it was failing to
apply validity checks.
This patch removes this dedicated and unnecessarily duplicated code.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch4.adb (Expand_Composite_Equality): Handle arrays inside
records just like scalars; only records inside records need
dedicated handling.
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -2475,75 +2475,9 @@ package body Exp_Ch4 is
Full_Type := Underlying_Type (Full_Type);
end if;
- -- Case of array types
-
- if Is_Array_Type (Full_Type) then
-
- -- If the operand is an elementary type other than a floating-point
- -- type, then we can simply use the built-in block bitwise equality,
- -- since the predefined equality operators always apply and bitwise
- -- equality is fine for all these cases.
-
- if Is_Elementary_Type (Component_Type (Full_Type))
- and then not Is_Floating_Point_Type (Component_Type (Full_Type))
- then
- return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs);
-
- -- For composite component types, and floating-point types, use the
- -- expansion. This deals with tagged component types (where we use
- -- the applicable equality routine) and floating-point (where we
- -- need to worry about negative zeroes), and also the case of any
- -- composite type recursively containing such fields.
-
- else
- declare
- Comp_Typ : Entity_Id;
- Hi : Node_Id;
- Indx : Node_Id;
- Ityp : Entity_Id;
- Lo : Node_Id;
-
- begin
- -- Do the comparison in the type (or its full view) and not in
- -- its unconstrained base type, because the latter operation is
- -- more complex and would also require an unchecked conversion.
-
- if Is_Private_Type (Typ) then
- Comp_Typ := Underlying_Type (Typ);
- else
- Comp_Typ := Typ;
- end if;
-
- -- Except for the case where the bounds of the type depend on a
- -- discriminant, or else we would run into scoping issues.
-
- Indx := First_Index (Comp_Typ);
- while Present (Indx) loop
- Ityp := Etype (Indx);
-
- Lo := Type_Low_Bound (Ityp);
- Hi := Type_High_Bound (Ityp);
-
- if (Nkind (Lo) = N_Identifier
- and then Ekind (Entity (Lo)) = E_Discriminant)
- or else
- (Nkind (Hi) = N_Identifier
- and then Ekind (Entity (Hi)) = E_Discriminant)
- then
- Comp_Typ := Full_Type;
- exit;
- end if;
-
- Next_Index (Indx);
- end loop;
-
- return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Comp_Typ);
- end;
- end if;
-
-- Case of tagged record types
- elsif Is_Tagged_Type (Full_Type) then
+ if Is_Tagged_Type (Full_Type) then
Eq_Op := Find_Primitive_Eq (Typ);
pragma Assert (Present (Eq_Op));
@@ -2734,7 +2668,7 @@ package body Exp_Ch4 is
return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs, Bodies);
end if;
- -- Non-composite types (always use predefined equality)
+ -- Case of non-record types (always use predefined equality)
else
return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs);