This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix comparison of decimal float zeroes (PR80692)
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, Ben Elliston <bje at gnu dot org>
- Date: Wed, 17 May 2017 18:36:38 +0000
- Subject: [PATCH] Fix comparison of decimal float zeroes (PR80692)
- Authentication-results: sourceware.org; auth=none
Decimal float negative zero should compare equal to positive zero.
Decimal float zeroes are encoded as value class "normal" (in real.c);
they need to be handled specially, but in this one case that does not
yet happen. This fixes it.
Bootstrapped and tested on powerpc64-linux {-m32,-m64}; also tested
the testcase separately (it fails before the test, except at -O0; it
passes after it).
Is this okay for trunk?
Segher
2017-05-17 Segher Boessenkool <segher@kernel.crashing.org>
PR middle-end/80692
* real.c (do_compare): Give decimal_do_compare preference over
comparing just the signs.
gcc/testsuite/
PR middle-end/80692
* gcc.c-torture/execute/pr80692.c: New testcase.
---
gcc/real.c | 6 +++---
gcc/testsuite/gcc.c-torture/execute/pr80692.c | 13 +++++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr80692.c
diff --git a/gcc/real.c b/gcc/real.c
index 97452a9..a5671b2 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -960,12 +960,12 @@ do_compare (const REAL_VALUE_TYPE *a, const REAL_VALUE_TYPE *b,
gcc_unreachable ();
}
- if (a->sign != b->sign)
- return -a->sign - -b->sign;
-
if (a->decimal || b->decimal)
return decimal_do_compare (a, b, nan_result);
+ if (a->sign != b->sign)
+ return -a->sign - -b->sign;
+
if (REAL_EXP (a) > REAL_EXP (b))
ret = 1;
else if (REAL_EXP (a) < REAL_EXP (b))
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80692.c b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
new file mode 100644
index 0000000..e653c71
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr80692.c
@@ -0,0 +1,13 @@
+/* { dg-require-effective-target dfp } */
+
+int main () {
+ _Decimal64 d64 = -0.DD;
+
+ if (d64 != 0.DD)
+ __builtin_abort ();
+
+ if (d64 != -0.DD)
+ __builtin_abort ();
+
+ return 0;
+}
--
1.9.3