aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2018-05-28 08:54:55 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-28 08:54:55 +0000
commit0c386027b7d086f4d8e0b7f5a3778db1d08e6a29 (patch)
treed597f254e7673fe8aaa665831c430e8809d697a0 /gcc/ada
parentc84205cd4fb4122a092207542c55a92b62bcb314 (diff)
downloadgcc-0c386027b7d086f4d8e0b7f5a3778db1d08e6a29.zip
gcc-0c386027b7d086f4d8e0b7f5a3778db1d08e6a29.tar.gz
gcc-0c386027b7d086f4d8e0b7f5a3778db1d08e6a29.tar.bz2
[Ada] Fix internal error on nested record types with representation clause
This fixes a long-standing issue with the expansion of equality functions generated for discriminated record types with variant part. In this case the front-end recursively expands equality functions for the composite sub-components, in particular the array sub-components. But it systematically uses the unconstrained base type for them, which leads to both a more complex equality function, because of the need to compare the bounds, and an additional unchecked conversion from type to base type. Now this unchecked conversion may block a further expansion of the array sub-component, for example if it is a large array of record types subject to a component clause that causes it not to start on a byte boundary, and thus may lead to an internal error downstream in the back-end. 2018-05-28 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): For a composite (or FP) component type, do not expand array equality using the unconstrained base type, except for the case where the bounds of the type depend on a discriminant. gcc/testsuite/ * gnat.dg/rep_clause6.adb, gnat.dg/rep_clause6.ads: New testcase. From-SVN: r260834
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/exp_ch4.adb26
2 files changed, 31 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 5460ca4..b10bd6e 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-28 Eric Botcazou <ebotcazou@adacore.com>
+
+ * exp_ch4.adb (Expand_Composite_Equality): For a composite (or FP)
+ component type, do not expand array equality using the unconstrained
+ base type, except for the case where the bounds of the type depend on a
+ discriminant.
+
2018-05-28 Ed Schonberg <schonberg@adacore.com>
* einfo.ads, einfo.adb (Needs_Activation_Record): New flag on
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index caa64b9..508123d 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -2428,12 +2428,34 @@ package body Exp_Ch4 is
-- 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
+ -- 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
- return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Full_Type);
+ declare
+ Comp_Typ : Entity_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.
+
+ if Size_Depends_On_Discriminant (Comp_Typ) then
+ Comp_Typ := Full_Type;
+ end if;
+
+ return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Comp_Typ);
+ end;
end if;
-- Case of tagged record types