aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-02-16 09:25:55 +0100
committerJakub Jelinek <jakub@redhat.com>2022-02-16 09:25:55 +0100
commit6e74122f0de6748b3fd0ed9183090cd7c61fb53e (patch)
treec8f92acf34bcbdc234a074047a01e330dd1fbdb2 /gcc
parent875e493bf5eb04c11bc3846a6bfee47a6f183e3f (diff)
downloadgcc-6e74122f0de6748b3fd0ed9183090cd7c61fb53e.zip
gcc-6e74122f0de6748b3fd0ed9183090cd7c61fb53e.tar.gz
gcc-6e74122f0de6748b3fd0ed9183090cd7c61fb53e.tar.bz2
c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510]
The comment in shorten_compare says: /* If either arg is decimal float and the other is float, fail. */ but the callers of shorten_compare don't expect anything like failure as a possibility from the function, callers require that the function promotes the operands to the same type, whether the original selected *restype_ptr one or some shortened. So, if we choose not to shorten, we should still promote to the original *restype_ptr. 2022-02-16 Jakub Jelinek <jakub@redhat.com> PR c/104510 * c-common.cc (shorten_compare): Convert original arguments to the original *restype_ptr when mixing binary and decimal float. * gcc.dg/dfp/pr104510.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-common.cc6
-rw-r--r--gcc/testsuite/gcc.dg/dfp/pr104510.c12
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index bf0749b..7203d76 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -3174,7 +3174,11 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
else if (real1 && real2
&& (DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop0)))
|| DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (primop1)))))
- return NULL_TREE;
+ {
+ type = *restype_ptr;
+ primop0 = op0;
+ primop1 = op1;
+ }
else if (real1 && real2
&& (TYPE_PRECISION (TREE_TYPE (primop0))
diff --git a/gcc/testsuite/gcc.dg/dfp/pr104510.c b/gcc/testsuite/gcc.dg/dfp/pr104510.c
new file mode 100644
index 0000000..85f4e97
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/pr104510.c
@@ -0,0 +1,12 @@
+/* PR c/104510 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+float f;
+_Decimal64 d;
+
+int
+foo (void)
+{
+ return d > (_Decimal32) (_Decimal64) f;
+}