[Ada] Plug small loophole in Generate_Range_Check
commit67460d45757a79cdc91fdde1dc1b1a18e4aba6b2
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 23 Jul 2019 08:13:32 +0000 (23 08:13 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 23 Jul 2019 08:13:32 +0000 (23 08:13 +0000)
tree0876647d905aa74a9b990478eec99495ac5572c6
parenta7191e01187b6ff6429699f09fed8f3fbb018b74
[Ada] Plug small loophole in Generate_Range_Check

The Generate_Range_Check routine is responsible for generating range
checks in the scalar case.  It automatically deals with possible
overflow in the process when the source and the target base types are
different.

However there is one case where overflow is not dealt with correctly,
namely when the target base type is narrower than the source base type
and both are floating-point types. In this case, the routine will
convert the source type to the target base type without checking for
overflow. In practice this does not matter much because the conversion
would yield an infinity on overflow, which would then fail the
subsequent range check. However it's more correct to have a proper
overflow check with -gnateF than relying on the infinity.

2019-07-23  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* checks.adb (Convert_And_Check_Range): Add Suppress parameter
and pass it in the call to Insert_Actions.  Rename local
variable.
(Generate_Range_Check): Minor comment fixes.  Pass Range_Check
in the first call to Convert_And_Check_Range and All_Checks in
the second call.
* exp_ch4.adb (Expand_N_Type_Conversion): Reset the
Do_Overflow_Check flag in the float-to-float case too if there
is also a range check.

gcc/testsuite/

* gnat.dg/range_check5.adb: New testcase.

From-SVN: r273725
gcc/ada/ChangeLog
gcc/ada/checks.adb
gcc/ada/exp_ch4.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/range_check5.adb [new file with mode: 0644]