public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10092] tilegx: Fix infinite loop in gen-mul-tables generator
@ 2022-06-24 19:00 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2022-06-24 19:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8a5e4fb6f333a8581f232cf1f1839e1cd82b3011

commit r11-10092-g8a5e4fb6f333a8581f232cf1f1839e1cd82b3011
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 03c0cfd5a8b..227bf086e8c 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-24 19:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 19:00 [gcc r11-10092] tilegx: Fix infinite loop in gen-mul-tables generator Iain Buclaw

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