From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id 613563858C53 for ; Tue, 29 Aug 2023 15:34:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 613563858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-79268f36c49so160553739f.2 for ; Tue, 29 Aug 2023 08:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1693323285; x=1693928085; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8wFRkX++q6HUGDMi/CCymbqn/Y6wnnftsZiVm8K6ByY=; b=RKNYWMCAfFu+vkW+9br+faj86GGWuj7GcLhToI/U9icW4DYzH54AWt6y4e0P2S+jSL xtaZN9q3IMa+ARW8Fg8SmLwqanl3TOO91zCaI9+ZavIExHz4ZPnaAxdFKCoT6S0HnMCz Hsr1u4cZw10C3z8H0fjlCEGSX8ooXVLeZOmEYIhnmsoTQc1MgujE1rEPiLz+k4i2mqaC NBZKo0Df0/nbdfBsVa74ubeEI1rbWFZzoLvtKiT///gTFRfRN7kGocWilDrwtz9CNklj beISW7u51QnBt7WACKb4I2U6hb2iNRdX2GAEMjpXZPWAmmefJe4qjryMhQ+1DtFoB2iv qx3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693323285; x=1693928085; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8wFRkX++q6HUGDMi/CCymbqn/Y6wnnftsZiVm8K6ByY=; b=VHOiXQhVte4GhxqtKWFxLcKnxOSNWoIemRSljqVoZt0505vMyqu7pH8A3lXK5WyWoF fKPOi2xWJXmgr93rKyyMjKH4v4XwLBuBPr81Vz+vyoBZ+do35Q5E3nGoR5nKMQpycGPQ 5KmUpTS8BipinjFRhZXWxNLAq8ypdTZVtHhr98ZQn/WBZ+1dkH/ZJQbvLAr5m25JF7vZ DFUkwOBOGMOqF7QewtDGrHBQd+rmTlpl/l1iI/0yfifclPYa4isf8t8Z7Rc37AnydjCd EBI5cJZLLCBYu+flJCjJOUODajCe2a5OrM2TbpMEfgHYrzeSFxua6gqYtlW6I46uiHG0 fBKQ== X-Gm-Message-State: AOJu0YzctDI9/mzcChJSAVwzbg1Xq6r0YnHoxfgrPP1Ec12/bu/6fw8A Is0YMFXc261CW7szkhAPq6aI2w== X-Google-Smtp-Source: AGHT+IHV94SxrwA7pZ08tSolftT0vJNDTaZnW3A0Egjg1ULqPBAcJC1g5W+fF0RJeqYovP/B43bRoQ== X-Received: by 2002:a05:6e02:686:b0:34c:cc37:3064 with SMTP id o6-20020a056e02068600b0034ccc373064mr16758877ils.15.1693323285644; Tue, 29 Aug 2023 08:34:45 -0700 (PDT) Received: from localhost.localdomain (75-166-150-212.hlrn.qwest.net. [75.166.150.212]) by smtp.gmail.com with ESMTPSA id i6-20020a92c946000000b0034cac5ced38sm3177387ilq.13.2023.08.29.08.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 08:34:45 -0700 (PDT) From: Tom Tromey Date: Tue, 29 Aug 2023 09:34:40 -0600 Subject: [PATCH v2 2/7] Declare 'tem' in loop header in array_operation::evaluate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230829-cleanup-array-op-v2-2-3035458b0443@adacore.com> References: <20230829-cleanup-array-op-v2-0-3035458b0443@adacore.com> In-Reply-To: <20230829-cleanup-array-op-v2-0-3035458b0443@adacore.com> To: gdb-patches@sourceware.org Cc: John Baldwin X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.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 List-Id: This changes array_operation::evaluate to declare the 'tem' variable in the loop header, rather than at the top of the function. This is cleaner and easier to reason about. I also changed 'nargs' to be 'const'. Reviewed-by: John Baldwin --- gdb/eval.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index 00b9231a5b9..63c414e546e 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2397,11 +2397,10 @@ array_operation::evaluate (struct type *expect_type, struct expression *exp, enum noside noside) { - int tem; int tem2 = std::get<0> (m_storage); int tem3 = std::get<1> (m_storage); const std::vector &in_args = std::get<2> (m_storage); - int nargs = tem3 - tem2 + 1; + const int nargs = tem3 - tem2 + 1; struct type *type = expect_type ? check_typedef (expect_type) : nullptr; if (expect_type != nullptr @@ -2429,7 +2428,7 @@ array_operation::evaluate (struct type *expect_type, } index = low_bound; memset (array->contents_raw ().data (), 0, expect_type->length ()); - for (tem = nargs; --nargs >= 0;) + for (int tem = 0; tem < nargs; ++tem) { struct value *element; @@ -2467,7 +2466,7 @@ array_operation::evaluate (struct type *expect_type, error (_("(power)set type with unknown size")); memset (valaddr, '\0', type->length ()); int idx = 0; - for (tem = 0; tem < nargs; tem++) + for (int tem = 0; tem < nargs; tem++) { LONGEST range_low, range_high; struct type *range_low_type, *range_high_type; @@ -2516,7 +2515,7 @@ array_operation::evaluate (struct type *expect_type, } std::vector argvec (nargs); - for (tem = 0; tem < nargs; tem++) + for (int tem = 0; tem < nargs; tem++) { /* Ensure that array expressions are coerced into pointer objects. */ -- 2.40.1