diff mbox series

[Committed] Fix PR97439

Message ID 20201022105215.19800-1-krebbel@linux.ibm.com
State New
Headers show
Series [Committed] Fix PR97439 | expand

Commit Message

Andreas Krebbel Oct. 22, 2020, 10:52 a.m. UTC
decimal_real_maxval misses to set the sign flag in the REAL_VALUE_TYPE.

Bootstrapped and regression tested on IBM Z.

Committed to head, gcc-10, gcc-9, and gcc-8 branches.

gcc/ChangeLog:

	PR rtl-optimization/97439
	* dfp.c (decimal_real_maxval): Set the sign flag in the
	generated number.

gcc/testsuite/ChangeLog:

	* gcc.dg/dfp/pr97439.c: New test.
---
 gcc/dfp.c                          |  2 ++
 gcc/testsuite/gcc.dg/dfp/pr97439.c | 27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/dfp/pr97439.c
diff mbox series

Patch

diff --git a/gcc/dfp.c b/gcc/dfp.c
index fef39a5ce39..4a0f68e5d83 100644
--- a/gcc/dfp.c
+++ b/gcc/dfp.c
@@ -740,4 +740,6 @@  decimal_real_maxval (REAL_VALUE_TYPE *r, int sign, machine_mode mode)
   decimal_real_from_string (r, max);
   if (sign)
     decimal128SetSign ((decimal128 *) r->sig, 1);
+
+  r->sign = sign;
 }
diff --git a/gcc/testsuite/gcc.dg/dfp/pr97439.c b/gcc/testsuite/gcc.dg/dfp/pr97439.c
new file mode 100644
index 00000000000..7fcf834043c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/pr97439.c
@@ -0,0 +1,27 @@ 
+// { dg-do run }
+// { dg-options "-O1" }
+
+static int
+foo(_Decimal128 x, _Decimal128 y)
+{
+  if (x > y)
+    return 1;
+
+  return 0;
+}
+
+int __attribute__((noinline))
+bar(_Decimal128 x)
+{
+  return foo (x, -1.0DL * __builtin_infd32());
+}
+
+int
+main (void)
+{
+  int res = bar (0.0DL);
+  if (res != 1)
+    __builtin_abort ();
+
+  return 0;
+}