+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
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
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);