From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id AFC813858D35 for ; Tue, 29 Aug 2023 18:10:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFC813858D35 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-il1-x131.google.com with SMTP id e9e14a558f8ab-34de98e01d4so4100535ab.0 for ; Tue, 29 Aug 2023 11:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1693332638; x=1693937438; darn=sourceware.org; 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=GSg3444GE1Or3WLg2q1LOSdHTtElPAlbTS7oR0krPsAVimiugoe5GqaNLdCYHNbmKp OfJOCsa4/D4CIALdjWLZH75R6xayH7LONp2ot7OBnv+aCAxsUKOwPIA6xblV9OGZzExK r0NsXjTQIdi8GQKM92n2bZIserXJ/RoKMXlJIw35iTLRfl46XGaJlg/evdh40xsUK0O/ tJM8Phs9YRKTdFDwywlfXji++iP8x4vpLV7x8LRewgyGR6lLwY5ZuQS9jy5bFZUVpoLH R0jMKY/7f520RQWpyTy/F0zXEitX2hNwgs4Es/VeWAuIwqy3NECz6lBuOUOm/K8u5EGO xjSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693332638; x=1693937438; 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=Y4fwjeYuRqTNHGz0tjH7q8pK4l1k5lFfRsms03JroF7PofEcMOo2HPe2wPufFoqLo/ BFd/ic5AggdnUwN5HVRUNXn6y6YDY9p3J+B89VO4MG/PlbdP4wWFKk2SIC8oD0uRL/3X 6afgrddOcDjmyrMi7ijY4XEstMUVHgLkhOhvqkHd2ZI7PrPa1tVm0YAlTKzJpGdShC28 My+UCxPFeb5uK9WTqQCrBENwKAcy8Y1bSUyuqYPQlntM0JYJtMJHjwn70JdI6cGrFv1a chT6hyKa7l6zJC4jg4k4yoxa/w5jZafOSBrnGEV1B1iR2+9s5xiJ+/J6tc1S6o7IYE9b OxKQ== X-Gm-Message-State: AOJu0YwrPWbT401yhsyK0wiid7oSc1IKvH8huaVrnFm0715GyGWa0nW4 735BEBXTmYMoPIUzZjHOTSAropXqS/X7/G3swQ4TDA== X-Google-Smtp-Source: AGHT+IFxwbdzKVc5CPynTE1YsEJSE4/YFBg1/3uJE36eSW8ZSjMJwF2mYEsF1J+8rX3NGaJusy0G8Q== X-Received: by 2002:a92:c892:0:b0:34d:f063:228f with SMTP id w18-20020a92c892000000b0034df063228fmr86426ilo.23.1693332637951; Tue, 29 Aug 2023 11:10:37 -0700 (PDT) Received: from localhost.localdomain (75-166-150-212.hlrn.qwest.net. [75.166.150.212]) by smtp.gmail.com with ESMTPSA id u5-20020a92da85000000b0034cb0abb579sm3249091iln.49.2023.08.29.11.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 11:10:37 -0700 (PDT) From: Tom Tromey Date: Tue, 29 Aug 2023 12:10:37 -0600 Subject: [PATCH v3 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-v3-2-0d0256c6a6ed@adacore.com> References: <20230829-cleanup-array-op-v3-0-0d0256c6a6ed@adacore.com> In-Reply-To: <20230829-cleanup-array-op-v3-0-0d0256c6a6ed@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