]> gcc.gnu.org Git - gcc.git/commitdiff
tilegx: Fix infinite loop in gen-mul-tables generator
authorIain Buclaw <ibuclaw@gdcproject.org>
Wed, 22 Jun 2022 17:11:20 +0000 (19:11 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Fri, 24 Jun 2022 19:00:40 +0000 (21:00 +0200)
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)

gcc/config/tilepro/gen-mul-tables.cc

index 03c0cfd5a8babff11c8601f732b1fd018fc2f3c0..227bf086e8c93a9ce0b420758d9f149c6c4ed146 100644 (file)
@@ -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
This page took 0.058947 seconds and 5 git commands to generate.