]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix missing check for no-op conversion to fixed-point type
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 22 Jul 2019 13:58:32 +0000 (13:58 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 22 Jul 2019 13:58:32 +0000 (13:58 +0000)
This plugs a small loophole in the compiler for the case of a
multiplication or a division in a fixed-point type wrapped in a no-op
conversion, e.g. to the same fixed-point type.

The front-end fails to generate a range check for the operation.  This
used to be caught by the back-end, which would generate the range check,
but this is no longer the case because we now make sure to reset the
Do_Range_Check flag in all cases before invoking the back-end.

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

gcc/ada/

* exp_ch4.adb (Expand_N_Type_Conversion): Beef up comment.
(Fixup_Universal_Fixed_Operation): Set the base type instead of
the type of the enclosing type conversion on the operation.

gcc/testsuite/

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

From-SVN: r273695

gcc/ada/ChangeLog
gcc/ada/exp_ch4.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/fixedpnt6.adb [new file with mode: 0644]

index ef329453247bcaebed0566ece53245dc7ee33c36..e9b1c3fc168864c20b0221de66e63cd04a556d6a 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * exp_ch4.adb (Expand_N_Type_Conversion): Beef up comment.
+       (Fixup_Universal_Fixed_Operation): Set the base type instead of
+       the type of the enclosing type conversion on the operation.
+
 2019-07-22  Ed Schonberg  <schonberg@adacore.com>
 
        * exp_ch4.adb (Expand_N_In): Do not suggest the use of attribute
index 7ef75f602f40f95961693b214f41005c17fbb6fe..dc2146c50e5bbc19dacbb9e2465a248308b1396f 100644 (file)
@@ -12072,7 +12072,10 @@ package body Exp_Ch4 is
       --  Check: are these rules stated in sinfo??? if so, why restate here???
 
       --  The only remaining step is to generate a range check if we still have
-      --  a type conversion at this stage and Do_Range_Check is set.
+      --  a type conversion at this stage and Do_Range_Check is set. Note that
+      --  we need to deal with at most 8 out of the 9 possible cases of numeric
+      --  conversions here, because the float-to-integer case is entirely dealt
+      --  with by Apply_Float_Conversion_Check.
 
       if Nkind (N) = N_Type_Conversion
         and then Do_Range_Check (Expression (N))
@@ -12726,13 +12729,13 @@ package body Exp_Ch4 is
       if Nkind (Parent (Conv)) = N_Attribute_Reference
         and then Attribute_Name (Parent (Conv)) = Name_Round
       then
-         Set_Etype (N, Etype (Parent (Conv)));
+         Set_Etype (N, Base_Type (Etype (Parent (Conv))));
          Set_Rounded_Result (N);
 
       --  Normal case where type comes from conversion above us
 
       else
-         Set_Etype (N, Etype (Conv));
+         Set_Etype (N, Base_Type (Etype (Conv)));
       end if;
    end Fixup_Universal_Fixed_Operation;
 
index d8daa2dbddef441284c61ac24ae9546e1e0ddfa7..9d20101b427438953a2fce05dd05db0bae74d5ba 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-22  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/fixedpnt6.adb: New testcase.
+
 2019-07-22  Ed Schonberg  <schonberg@adacore.com>
 
        * gnat.dg/warn26.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/fixedpnt6.adb b/gcc/testsuite/gnat.dg/fixedpnt6.adb
new file mode 100644 (file)
index 0000000..01c1747
--- /dev/null
@@ -0,0 +1,21 @@
+--  { dg-do run }
+--  { dg-options "-O0" }
+
+procedure Fixedpnt6 is
+
+  type T is delta 0.125 range -2.0 .. 1.875;
+
+  function Mult (A, B : T) return T is
+  begin
+    return T (A * B);
+  end;
+
+  R : T;
+
+begin
+  R := Mult (T'Last, T'Last);
+  raise Program_Error;
+exception
+   when Constraint_Error =>
+      null;
+end;