From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id F1B74385C31B; Fri, 24 Jun 2022 19:01:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1B74385C31B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10866] tilegx: Fix infinite loop in gen-mul-tables generator X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 6dd4d545617f094aa97566570bc1a04b73302a56 X-Git-Newrev: a99706355ce51a464a2e74f81009b16a22f48691 Message-Id: <20220624190130.F1B74385C31B@sourceware.org> Date: Fri, 24 Jun 2022 19:01:30 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 19:01:31 -0000 https://gcc.gnu.org/g:a99706355ce51a464a2e74f81009b16a22f48691 commit r10-10866-ga99706355ce51a464a2e74f81009b16a22f48691 Author: Iain Buclaw 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