* [PATCH] c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510]
@ 2022-02-15 10:07 Jakub Jelinek
2022-02-15 23:45 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-02-15 10:07 UTC (permalink / raw)
To: Joseph S. Myers, Marek Polacek, Jason Merrill; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2022-02-15 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.
--- gcc/c-family/c-common.cc.jj 2022-02-04 14:36:53.998619364 +0100
+++ gcc/c-family/c-common.cc 2022-02-14 19:07:14.305068950 +0100
@@ -3174,7 +3174,11 @@ shorten_compare (location_t loc, tree *o
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))
--- gcc/testsuite/gcc.dg/dfp/pr104510.c.jj 2022-02-14 19:11:05.610860035 +0100
+++ gcc/testsuite/gcc.dg/dfp/pr104510.c 2022-02-14 19:10:42.819176224 +0100
@@ -0,0 +1,12 @@
+/* PR c/104510 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+float f;
+_Decimal64 d;
+
+int
+foo (void)
+{
+ return d > (_Decimal32) (_Decimal64) f;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510]
2022-02-15 10:07 [PATCH] c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510] Jakub Jelinek
@ 2022-02-15 23:45 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-02-15 23:45 UTC (permalink / raw)
To: Jakub Jelinek, Joseph S. Myers, Marek Polacek; +Cc: gcc-patches
On 2/15/22 05:07, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2022-02-15 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.
>
> --- gcc/c-family/c-common.cc.jj 2022-02-04 14:36:53.998619364 +0100
> +++ gcc/c-family/c-common.cc 2022-02-14 19:07:14.305068950 +0100
> @@ -3174,7 +3174,11 @@ shorten_compare (location_t loc, tree *o
> 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))
> --- gcc/testsuite/gcc.dg/dfp/pr104510.c.jj 2022-02-14 19:11:05.610860035 +0100
> +++ gcc/testsuite/gcc.dg/dfp/pr104510.c 2022-02-14 19:10:42.819176224 +0100
> @@ -0,0 +1,12 @@
> +/* PR c/104510 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +float f;
> +_Decimal64 d;
> +
> +int
> +foo (void)
> +{
> + return d > (_Decimal32) (_Decimal64) f;
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-15 23:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 10:07 [PATCH] c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510] Jakub Jelinek
2022-02-15 23:45 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).