From 241848fd7ac69fd1ff0a17203d824c305a384137 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Wed, 26 Sep 2018 09:19:38 +0000 Subject: [PATCH] [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 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 --- gcc/ada/ChangeLog | 11 +++++++++++ gcc/ada/checks.adb | 17 +++++++++++++++-- gcc/ada/exp_ch4.adb | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c8145cfb141..8a9d9e1db63 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,14 @@ +2018-09-26 Ed Schonberg + + * 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 * sem_spark.adb (Check_Loop_Statement): Fix a bug related to diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 2e61e5153bf..5cefbbd8415 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -3550,8 +3550,21 @@ package body Checks is Apply_Float_Conversion_Check (Expr, Target_Type); else - Apply_Scalar_Range_Check - (Expr, Target_Type, Fixed_Int => Conv_OK); + -- 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 diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 09a6cd0541e..a7aee9fcacf 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -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); -- 2.30.2