From 35b3fccbc2c15ada128b9cf3efa789872da384d9 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Wed, 28 May 2014 16:46:07 +0000 Subject: [PATCH] backport: double-int.c (div_and_round_double): Use the proper predicate to detect a negative quotient. Backport from mainline 2014-05-27 Eric Botcazou * double-int.c (div_and_round_double) : Use the proper predicate to detect a negative quotient. From-SVN: r211028 --- gcc/ChangeLog | 8 ++++++++ gcc/double-int.c | 2 +- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gnat.dg/overflow_fixed.adb | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gnat.dg/overflow_fixed.adb diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e38b55364786..a6df5af7e155 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-05-28 Eric Botcazou + + Backport from mainline + 2014-05-27 Eric Botcazou + + * double-int.c (div_and_round_double) : Use the proper + predicate to detect a negative quotient. + 2014-05-28 Georg-Johann Lay PR target/61044 diff --git a/gcc/double-int.c b/gcc/double-int.c index 918ce2273eca..53a69ad67a71 100644 --- a/gcc/double-int.c +++ b/gcc/double-int.c @@ -616,7 +616,7 @@ div_and_round_double (unsigned code, int uns, == (unsigned HOST_WIDE_INT) htwice) && (labs_den <= ltwice))) { - if (*hquo < 0) + if (quo_neg) /* quo = quo - 1; */ add_double (*lquo, *hquo, (HOST_WIDE_INT) -1, (HOST_WIDE_INT) -1, lquo, hquo); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 55ea1088e24c..da44bda52ffd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2014-05-28 Eric Botcazou + + Backport from mainline + 2014-05-27 Eric Botcazou + + * gnat.dg/overflow_fixed.adb: New test. + 2014-05-27 Eric Botcazou * gnat.dg/aliasing1.adb (dg-final): Robustify pattern matching. diff --git a/gcc/testsuite/gnat.dg/overflow_fixed.adb b/gcc/testsuite/gnat.dg/overflow_fixed.adb new file mode 100644 index 000000000000..6ece51523339 --- /dev/null +++ b/gcc/testsuite/gnat.dg/overflow_fixed.adb @@ -0,0 +1,19 @@ +-- { dg-do run } +-- { dg-options "-gnato -O" } + +procedure Overflow_Fixed is + + type Unsigned_8_Bit is mod 2**8; + + procedure Fixed_To_Eight (Value : Duration) is + Item : Unsigned_8_Bit; + begin + Item := Unsigned_8_Bit(Value); + raise Program_Error; + exception + when Constraint_Error => null; -- expected case + end; + +begin + Fixed_To_Eight (-0.5); +end; -- 2.47.2