From: Iain Buclaw Date: Wed, 22 Jun 2022 17:11:20 +0000 (+0200) Subject: tilegx: Fix infinite loop in gen-mul-tables generator X-Git-Tag: releases/gcc-12.2.0~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16d4ccc27d97b1b6623f1e41e07f916e353e8839;p=thirdparty%2Fgcc.git 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 --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc index c9649fb9c70e..ff7c3c905bc9 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