[Ada] ICE handling discriminant-dependent index constraint for access component
authorSteve Baird <baird@adacore.com>
Fri, 29 Jul 2022 22:54:19 +0000 (15:54 -0700)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 6 Sep 2022 07:14:20 +0000 (09:14 +0200)
commit152f968e86d14bbebe3e69286dd7a9257e3ca174
tree2a71f82cd9e396d197c925a3e6a10ce38bd20da1
parentec95a21b5246af342fd91c9fe99022c1f2e9d7bf
[Ada] ICE handling discriminant-dependent index constraint for access component

The compiler would fail with an internal error in some cases involving
a discriminated record type that provides a discriminant-dependent index
constraint for the subtype of a component of an access-to-array type when a
dereference of that component of some object is mentioned in a pre- or
postcondition expression.

gcc/ada/

* sem_ch4.adb
(Analyze_Selected_Component): Define new Boolean-valued function,
Constraint_Has_Unprefixed_Discriminant_Reference, which takes a
subtype that is subject to a discriminant-dependent constraint and
returns True if any of the constraint values are unprefixed
discriminant names. Usually, the Etype of a selected component
node is set to Etype of the component. However, in the case of an
access-to-array component for which this predicate returns True,
we instead use the base type of the Etype of the component.
Normally such problematic discriminant references are addressed by
calling Build_Actual_Subtype_Of_Component, but that doesn't work
if Full_Analyze is False.
gcc/ada/sem_ch4.adb