public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10866] tilegx: Fix infinite loop in gen-mul-tables generator
Date: Fri, 24 Jun 2022 19:01:30 +0000 (GMT)	[thread overview]
Message-ID: <20220624190130.F1B74385C31B@sourceware.org> (raw)

https://gcc.gnu.org/g:a99706355ce51a464a2e74f81009b16a22f48691

commit r10-10866-ga99706355ce51a464a2e74f81009b16a22f48691
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Wed Jun 22 19:11:20 2022 +0200

    tilegx: Fix infinite loop in gen-mul-tables generator
    
    Since around GCC 10, the condition `j < (INTMAX_MAX / 10)' will get
    optimized into `j != 922337203685477580', which will result in an
    infinite loop for certain inputs of `j'.
    
    Copy the condition already used by the -DTILEPRO generator code, which
    doesn't fall into this trap.
    
    gcc/ChangeLog:
    
            * config/tilepro/gen-mul-tables.cc (tilegx_emit): Adjust loop
            condition to avoid overflow.
    
    (cherry picked from commit c0ad48527c314a1e9354b7c26718b56ed4abc92c)

Diff:
---
 gcc/config/tilepro/gen-mul-tables.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index 2a345023aea..b57e6b125ec 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -1190,11 +1190,11 @@ tilegx_emit (long long multiplier, int num_ops)
     long long next_pow10;
 
     while (((j * 10) < abs_multiplier)
-	   && (j < (INTMAX_MAX / 10)))
+	   && (j < (j * 10)))
       j = j * 10;
 
     prev_pow10 = j;
-    next_pow10 = (j > (INTMAX_MAX / 10)) ? 0 : j * 10;
+    next_pow10 = j * 10;
 
     if ((abs_multiplier - prev_pow10 <= 100)
 	|| (next_pow10


                 reply	other threads:[~2022-06-24 19:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220624190130.F1B74385C31B@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).