[Ada] Missing front-end code for constraint checks on fixed point exprs

This patch ensures that the front-end generates constraint checks for
some operations that previously depended on gigi for the corresponding
check. The patch also resets the Do_Range_Check flag so that it never
appears in the tree presented to gigi.

2018-09-26  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* checks.adb (Apply_Type_Conversion_Checks): Do not generate a
	range check on the expression of the conversion if it involves a
	fixed-point type, as such conversions are handled specially
	during expansion.
	* exp_ch4.adb (Expand_N_Type_Conversion): In a conversion from
	Fixed to Integer, use the base type of the expression to ensure
	that the caller will generate the proper constraint check when
	needed.

From-SVN: r264632
This commit is contained in:
Ed Schonberg 2018-09-26 09:19:38 +00:00 committed by Pierre-Marie de Rodat
parent 2d9a8c0ba1
commit 241848fd7a
3 changed files with 31 additions and 2 deletions

View file

@ -1,3 +1,14 @@
2018-09-26 Ed Schonberg <schonberg@adacore.com>
* checks.adb (Apply_Type_Conversion_Checks): Do not generate a
range check on the expression of the conversion if it involves a
fixed-point type, as such conversions are handled specially
during expansion.
* exp_ch4.adb (Expand_N_Type_Conversion): In a conversion from
Fixed to Integer, use the base type of the expression to ensure
that the caller will generate the proper constraint check when
needed.
2018-09-26 Maroua Maalej <maalej@adacore.com>
* sem_spark.adb (Check_Loop_Statement): Fix a bug related to

View file

@ -3550,9 +3550,22 @@ package body Checks is
Apply_Float_Conversion_Check (Expr, Target_Type);
else
-- Conversions involving fixed-point types are expanded
-- separately, and do not need a Range_Check flag, except
-- in SPARK_Mode, where the explicit constraint check will
-- not be generated.
if SPARK_Mode = On
or else (not Is_Fixed_Point_Type (Expr_Type)
and then not Is_Fixed_Point_Type (Target_Type))
then
Apply_Scalar_Range_Check
(Expr, Target_Type, Fixed_Int => Conv_OK);
else
Set_Do_Range_Check (Expression (N), False);
end if;
-- If the target type has predicates, we need to indicate
-- the need for a check, even if Determine_Range finds that
-- the value is within bounds. This may be the case e.g for

View file

@ -11694,6 +11694,11 @@ package body Exp_Ch4 is
elsif Is_Integer_Type (Etype (N)) then
Expand_Convert_Fixed_To_Integer (N);
-- The result of the conversion might need a range check,
-- so do not assume that the result is in bounds.
Set_Etype (N, Base_Type (Target_Type));
else
pragma Assert (Is_Floating_Point_Type (Etype (N)));
Expand_Convert_Fixed_To_Float (N);