From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 981A538346AF; Tue, 10 May 2022 08:24:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 981A538346AF MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10683] c-family: Fix up shorten_compare for decimal vs. non-decimal float comparison [PR104510] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: fefb97a53606fad6060e217b9b642dbbd3a1e299 X-Git-Newrev: 83aea9cb28f729698a79e4262ef3a43a0fd79d4f Message-Id: <20220510082412.981A538346AF@sourceware.org> Date: Tue, 10 May 2022 08:24:12 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 08:24:12 -0000 https://gcc.gnu.org/g:83aea9cb28f729698a79e4262ef3a43a0fd79d4f commit r10-10683-g83aea9cb28f729698a79e4262ef3a43a0fd79d4f Author: Jakub Jelinek Date: Wed Feb 16 09:25:55 2022 +0100 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 PR c/104510 * c-common.c (shorten_compare): Convert original arguments to the original *restype_ptr when mixing binary and decimal float. * gcc.dg/dfp/pr104510.c: New test. (cherry picked from commit 6e74122f0de6748b3fd0ed9183090cd7c61fb53e) Diff: --- gcc/c-family/c-common.c | 6 +++++- gcc/testsuite/gcc.dg/dfp/pr104510.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 661a194fc89..ad8bdc34a56 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2980,7 +2980,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 00000000000..85f4e9707de --- /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; +}