From patchwork Thu Oct 19 14:42:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 155627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp433388vqb; Thu, 19 Oct 2023 07:43:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3UgdHCvuzPuQRGPV5nFgrqY9+00kT6BFIpIHT+/y8eemNQ6BOv2J/+iKj28+2MAf++qr1 X-Received: by 2002:a81:80c4:0:b0:598:5bb5:1801 with SMTP id q187-20020a8180c4000000b005985bb51801mr2054086ywf.50.1697726587728; Thu, 19 Oct 2023 07:43:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697726587; cv=pass; d=google.com; s=arc-20160816; b=Hg8Pheiywy7dm7rhn9St3pvLTHuxXjQ+9lMnB7tch4LpQypqkFea67f7408zSZREYz ObEgJkksOvYMlSO7r5wQXiUj6XG5sNE6h1lSdExzAW5qQ3M6kezETZzjZjqiYkvW2pgf U3bEJF7lcBGSOYYdE4ZDe9I+7/baBcTPESoD7qsFLf4QzhCsiKXZS/yy/z3cgmWImaRN Lv5jtHT0D2oOO1Ws25SkKw5KHzA/vxwV3uyxMgoqqIoHjYf/awsBP0jZeR9PninT/m4K oXffjFbmKnRKK868Weu2TZv3sWy3nQ8q9VhpLzO3CcxqOar9LV7rLFHrYq1xyVBRcoOI GeLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=4b5SHVx+lFhsGNkMNN2qitluAa5rsmot9V+Zx7d0Wb0=; fh=TQgQFHlWkFxdBV4U28EkGDBgG4nPpypv77B7Up3yEzk=; b=pj1ociNyDKxbdIP/HD8vmfb6kPCr+YRL9n+RBbqBsMah7VHLKhGIpLPeaj2LD7n4Ko s2EjjwfJstQVYt8aQyHl0KGlUO2sPeLEkpglwtrjoLjaQ1ehs0eDRosJLYkW2zzA5Kgc 8JRGyd587Rc8pbMKRj5wfGLs3Rb7hYLlpfF/12IET2cg7upixuvXOoWNCQt7lJ88rlMY +8GrTcaisZnFrk9AQzvY1h0qW+Ql/8P+b4tzUsYIW9piZyY2sT/e3nmzbzYqMmtkUdRO Ityd+10BJNyaTCyafIRf24mwostxgL/PbhSllG432a1n9UC6S/6eLK0n7C8eJdZB2MZE +nlA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Prla3Yp6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i7-20020ad44ba7000000b0064b78e57cf8si1701108qvw.38.2023.10.19.07.43.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:43:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Prla3Yp6; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94B19385771C for ; Thu, 19 Oct 2023 14:43:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 68015385841F for ; Thu, 19 Oct 2023 14:42:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68015385841F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 68015385841F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697726526; cv=none; b=cdgrqvYZGCevQcmGNPf55agZNdEZgflilhGIKaWLRx5qERdAo7/153fxHreIOZJt+nfEctRt6ULD04Qn1CsQIR8eKqqFvWgQxr5i/Vh4L0MDY2yVWPAYxMbyPRlp/m8Y7GzCQqh8SuRZFhqyftpjyPnjgOX6xbdn8+Y0qDlH/H8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697726526; c=relaxed/simple; bh=MYabLQ7mDOrngFXaEzmslfk5KZZewx8dpINC+x8HI+U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Rs53cAKUxAmXQhhpK+v7792mKofXCQ74bmhvQOQL941dqrYO8SmQI/LBcQotcq7WuRK/ZrSCZaXWa01x/K5xmjgNMSNcQVHvZlYfQmMN5n7RngvDJhRhiTWGe7NLsOGiCiZjrs2EqD59OBGWkOiaHAO+VHGGN0CxWqvUrKLFU0U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31fa15f4cc6so6809480f8f.2 for ; Thu, 19 Oct 2023 07:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1697726524; x=1698331324; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4b5SHVx+lFhsGNkMNN2qitluAa5rsmot9V+Zx7d0Wb0=; b=Prla3Yp67s21sfOIoUXWupvx6zSTmSE6mUIfurr+6mVgZ8wt3PC4f12qFbzrXybnjE x/1uo5lf5nDMZPdoTECwgPZmVFbOZtvj7ltwCWy2f2k+pJtF7nK2Yh0OU52felKQ1MOO GahUy/ldfOYjQrOxd2cMFMu+IZYTi+91Y3joIPMJwOJobO4nNVSrr139xvN8rXgxVieP 75EgfWtAlvVHiL8010ecbx3cm97na4f38YkwqP3BqXiBlGX1bLfJocifNKHqqUi3tcib /5+HrlMxlzHoNbT/iKW0pMJ1EQqPWR547A1uGKqzLDWHURNlGXd9ILHtM/cO05RUbj0V aFNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726524; x=1698331324; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4b5SHVx+lFhsGNkMNN2qitluAa5rsmot9V+Zx7d0Wb0=; b=rRZqKbcuKntOxEmzXIIldllwvXPBS1KAGQKp9bd7P/8cjKWkvkaAsuGc0yecLzBbL0 c8H7pdvtKRnQt/pSR55HLzFz7As6pUPI1kNjg8dnG/PDxontK5TWtpsbLpO96Z/lS+FO nj0GCmCNmhpItxUzRvlvpCLuGy2SpH+LvFEkbeleAhvhXx+11DpSZOJzBE8GqecvI+Qe xnSYCowJfNe6/UOJT6D2nCBHuEXm4FnrdjShlen3hF3qbh0K0F7Nf+H6+PUMNBBT0rXl xCl8+Aleo1SbY5LaHDwZ8FSa8DbLrcrHJBjJiGjP07SuBnODs4LAZdIEI1DOOoIx++bB b0zw== X-Gm-Message-State: AOJu0Yx3Kva6eS7vRGIZFZzT2X3Q7DPQspFyCshM9cNpdEvCV0YoCeIm JnOr2UeVRtYea5wEm3sL6JCNK+FK8Nw8bWQnoD0fiw== X-Received: by 2002:adf:fd4d:0:b0:32d:84a3:f3fe with SMTP id h13-20020adffd4d000000b0032d84a3f3femr1468856wrs.41.1697726524189; Thu, 19 Oct 2023 07:42:04 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:b43b:dc95:363f:b759]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0032d8ce46caasm955388wrs.93.2023.10.19.07.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:42:03 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Sheri Bernstein Subject: [COMMITTED] ada: Refactor code to remove GNATcheck violation Date: Thu, 19 Oct 2023 16:42:02 +0200 Message-ID: <20231019144202.339662-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195354601299151 X-GMAIL-MSGID: 1780195354601299151 From: Sheri Bernstein Rewrite for loop containing an exit (which violates GNATcheck rule Exits_From_Conditional_Loops), to use a while loop which contains the exit criteria in its condition. Also, move special case of first time through loop, to come before loop. gcc/ada/ * libgnat/s-imagef.adb (Set_Image_Fixed): Refactor loop. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/s-imagef.adb | 75 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/gcc/ada/libgnat/s-imagef.adb b/gcc/ada/libgnat/s-imagef.adb index 3f6bfa20cb2..6194a3163de 100644 --- a/gcc/ada/libgnat/s-imagef.adb +++ b/gcc/ada/libgnat/s-imagef.adb @@ -307,6 +307,9 @@ package body System.Image_F is YY : Int := Y; -- First two operands of the scaled divide + J : Natural; + -- Loop index + begin -- Set the first character like Image @@ -317,59 +320,61 @@ package body System.Image_F is Ndigs := 0; end if; - for J in 1 .. N loop - exit when XX = 0; + -- First round of scaled divide + if XX /= 0 then Scaled_Divide (XX, YY, Z, Q, R => XX, Round => False); + if Q /= 0 then + Set_Image_Integer (Q, Digs, Ndigs); + end if; - if J = 1 then - if Q /= 0 then - Set_Image_Integer (Q, Digs, Ndigs); - end if; - - Scale := Scale + D; + Scale := Scale + D; - -- Prepare for next round, if any + -- Prepare for next round, if any - YY := 10**Maxdigs; + YY := 10**Maxdigs; + end if; - else - pragma Assert (-10**Maxdigs < Q and then Q < 10**Maxdigs); + J := 2; + while J <= N and then XX /= 0 loop + Scaled_Divide (XX, YY, Z, Q, R => XX, Round => False); - Len := 0; - Set_Image_Integer (abs Q, Buf, Len); + pragma Assert (-10**Maxdigs < Q and then Q < 10**Maxdigs); - pragma Assert (1 <= Len and then Len <= Maxdigs); + Len := 0; + Set_Image_Integer (abs Q, Buf, Len); - -- If no character but the space has been written, write the - -- minus if need be, since Set_Image_Integer did not do it. + pragma Assert (1 <= Len and then Len <= Maxdigs); - if Ndigs <= 1 then - if Q /= 0 then - if Ndigs = 0 then - Digs (1) := '-'; - end if; + -- If no character but the space has been written, write the + -- minus if need be, since Set_Image_Integer did not do it. - Digs (2 .. Len + 1) := Buf (1 .. Len); - Ndigs := Len + 1; + if Ndigs <= 1 then + if Q /= 0 then + if Ndigs = 0 then + Digs (1) := '-'; end if; - -- Or else pad the output with zeroes up to Maxdigs + Digs (2 .. Len + 1) := Buf (1 .. Len); + Ndigs := Len + 1; + end if; - else - for K in 1 .. Maxdigs - Len loop - Digs (Ndigs + K) := '0'; - end loop; + -- Or else pad the output with zeroes up to Maxdigs - for K in 1 .. Len loop - Digs (Ndigs + Maxdigs - Len + K) := Buf (K); - end loop; + else + for K in 1 .. Maxdigs - Len loop + Digs (Ndigs + K) := '0'; + end loop; - Ndigs := Ndigs + Maxdigs; - end if; + for K in 1 .. Len loop + Digs (Ndigs + Maxdigs - Len + K) := Buf (K); + end loop; - Scale := Scale + Maxdigs; + Ndigs := Ndigs + Maxdigs; end if; + + Scale := Scale + Maxdigs; + J := J + 1; end loop; -- If no digit was output, this is zero