From patchwork Wed Jun 22 17:30:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 55288 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 591D738327F3 for ; Wed, 22 Jun 2022 17:31:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 591D738327F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655919080; bh=fLiO4c1l6e2iampxqsq/BioLweD3Q1vyQrtw+4ERDSU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FhcziPvIua+19Wqbb/gEse4WCj9nwuW+ErzkIqZEja5Qp5rS6K5x3RMUjHFXh82ZL +cYMZY6Q8bSQk64lcGwGmPtVSHgt+e+BbNg0bg55AZRilrrETC4q/sbNxUMjDWX65e M8lf5V4DC7GKbT+l0/N3p65pAKi9bB68wm2qw0SA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by sourceware.org (Postfix) with ESMTPS id D8F69383569F for ; Wed, 22 Jun 2022 17:30:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8F69383569F Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4LSr534Tzsz9sQ8; Wed, 22 Jun 2022 19:30:47 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator Date: Wed, 22 Jun 2022 19:30:45 +0200 Message-Id: <20220622173045.1253663-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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