]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Use larger type for membership test of universal value
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 3 Dec 2022 14:30:22 +0000 (15:30 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 6 Dec 2022 13:58:48 +0000 (14:58 +0100)
commitd1ab8eddca918f342b06a66fedb8fbc06c5532ab
treeb7d9e0f6b0e6d09fa2bf84689db9ac3f295c1c6c
parentf459afaa679956df1f3c0243a87583e4d4b43a2e
ada: Use larger type for membership test of universal value

When a membership test is applied to a nonstatic expression of a universal
type, for example an attribute whose type is universal_integer and whose
prefix is not static, the operation is performed using the tested type that
is determined by the choice list.  In particular, a check that the value of
the expression lies in the range of the tested type may be generated before
the test is actually performed.

This goes against the spirit of membership tests, which are typically used
to guard a specific operation and ought not to fail a check in doing so.

Therefore the resolution of the operands of membership tests is changed in
this case to use the universal type instead of the tested type. The final
computation of the type used to actually perform the test is left to the
expander, which already has the appropriate circuitry.

This nevertheless requires fixing an irregularity in the expansion of the
subtype_mark form of membership tests, which was dependent on the presence
of predicates for the subtype; the confusing name of a routine used by this
expansion is also changed in the process.

gcc/ada/

* exp_ch4.adb (Expand_N_In) <Substitute_Valid_Check>: Rename to...
<Substitute_Valid_Test>: ...this.
Use Is_Entity_Name to test for the presence of entity references.
Do not warn or substitute a valid test for a test with a mark for
a subtype that is predicated.
Apply the same transformation for a test with a mark for a subtype
that is predicated as for a subtype that is not.
Remove useless return statement.
* sem_res.adb (Resolve_Membership_Op): Perform a special resolution
if the left operand is of a universal numeric type.
gcc/ada/exp_ch4.adb
gcc/ada/sem_res.adb