diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-09-26 09:19:38 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-09-26 09:19:38 +0000 |
commit | 241848fd7ac69fd1ff0a17203d824c305a384137 (patch) | |
tree | 67c44fcb4fcad12ad1611fa9be88c2c11ba6ab44 | |
parent | 2d9a8c0ba10d03608aa2add8cf9f33053ab8c421 (diff) | |
download | gcc-241848fd7ac69fd1ff0a17203d824c305a384137.zip gcc-241848fd7ac69fd1ff0a17203d824c305a384137.tar.gz gcc-241848fd7ac69fd1ff0a17203d824c305a384137.tar.bz2 |
[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
-rw-r--r-- | gcc/ada/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/ada/checks.adb | 17 | ||||
-rw-r--r-- | gcc/ada/exp_ch4.adb | 5 |
3 files changed, 31 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c8145cf..8a9d9e1 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -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 diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 2e61e51..5cefbbd 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 09a6cd0..a7aee9f 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); |