Hi,

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'.

This patch just copies the condition already used by the -DTILEPRO
generator code, which doesn't fall into the same trap.

OK for mainline?  OK for backporting to all open release branches?

Regards,
Iain.

---
gcc/ChangeLog:

        * config/tilepro/gen-mul-tables.cc (tilegx_emit): Adjust loop
        condition to avoid overflow.
---
 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 52183982f65..c125748a328 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -1192,11 +1192,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
-- 
2.34.1

Reply via email to