From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eI5cAWq1RmMXYQoAWB0awg (envelope-from ) for ; Wed, 12 Oct 2022 08:39:06 -0400 Received: by simark.ca (Postfix, from userid 112) id 023EE1E112; Wed, 12 Oct 2022 08:39:06 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Vi+DeFVp; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A69371E0D3 for ; Wed, 12 Oct 2022 08:39:05 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5798F3850431 for ; Wed, 12 Oct 2022 12:39:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5798F3850431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665578345; bh=jCDNiwCMJMCMgUUkYE+Uerqqdi6LES8m2DAkvJtIEZk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Vi+DeFVpmWLCKh63B395ZGgGRJCHJu4ctHxTaJ/nEcHhnuDl27eDuDpmh6zD8KfrS 82JseMD2yWC3x8Bo7x7ZrwDfCniAdFtwbgLYOotxycrJVUFH+pUSvkCNF64HVztzzC LGIxlTGObXYo5w+Jj82f7ziGHOxppNM3hk2l8laY= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D4ADF3856DE2 for ; Wed, 12 Oct 2022 12:38:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4ADF3856DE2 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-504-EAmDmpfOPsu1L6EdppkleQ-1; Wed, 12 Oct 2022 08:38:42 -0400 X-MC-Unique: EAmDmpfOPsu1L6EdppkleQ-1 Received: by mail-wr1-f72.google.com with SMTP id q28-20020adfab1c000000b0022e0399964dso4889562wrc.8 for ; Wed, 12 Oct 2022 05:38:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jCDNiwCMJMCMgUUkYE+Uerqqdi6LES8m2DAkvJtIEZk=; b=DZi/SyhL5OdmgJikjLCahIh9PtpOsYz9loEamuZBsVCTMazTn7YCLVPsX4EEZu7enX dQsTqcUplJGLJaRCFZs0qT9ask3K3OfGDDWO0CVze0DYL3rGFgh1AMGuIig5XO7bZTeL /uxgnuCzEZUDfcstJyHKCBlmo8oAkrRXTK1opfUYL/P0T4caQHuJXido3+dGnnj/1nUW Xgy/9uuTKySYoK9VQozsjsJ6JOefOThWmfu/4L+DP1f0aEa5lLzD2WAGay9RGOtpL2Kn s9HDiOULD8pCTl3BvXLX8kLIzxbdZpXr/db09Kb1aBkDphtQon3i7zOuOhOwRoFu9wc7 b8wQ== X-Gm-Message-State: ACrzQf2mkZUOj19IhBypdSuDzzS1AU5GY6sBVlgSDElPeWkBpzdnmLXP JzghhJFp0yuweUHVUX6N4Ko99RI3RPWaylJNoZTLGyV4r/aI32Y+iHwBNnQqOXRN3k2K2TwxJhr dLxSNaF0tLOUQs/8xK2TLSQvucH6hjn++Ht4Gmu5Wtm62TdgkXJPzq0AipioataUKkZiFsv6LKw == X-Received: by 2002:adf:f58b:0:b0:22e:3c4:cf83 with SMTP id f11-20020adff58b000000b0022e03c4cf83mr18819290wro.379.1665578320762; Wed, 12 Oct 2022 05:38:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4djxN/aNIa6J7ZYs3kMdFirWN5QKMxDxN1QEpcS9eC+r+VLnSnNH7+sKpOnWcU5Qijv5XLzg== X-Received: by 2002:adf:f58b:0:b0:22e:3c4:cf83 with SMTP id f11-20020adff58b000000b0022e03c4cf83mr18819277wro.379.1665578320522; Wed, 12 Oct 2022 05:38:40 -0700 (PDT) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003b4cba4ef71sm1955655wmq.41.2022.10.12.05.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 05:38:40 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 1/5] sim/cgen: mask uninitialized variable warning in cgen-run.c Date: Wed, 12 Oct 2022 13:38:31 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" I see an uninitialized variable warning (with gcc 9.3.1) from cgen-run.c, like this: /tmp/build/sim/../../src/sim/cris/../common/cgen-run.c: In function ‘sim_resume’: /tmp/build/sim/../../src/sim/cris/../common/cgen-run.c:259:5: warning: ‘engine_fns$’ may be used uninitialized in this function [-Wmaybe-uninitialized] 259 | (* engine_fns[next_cpu_nr]) (cpu); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /tmp/build/sim/../../src/sim/cris/../common/cgen-run.c:232:14: note: ‘engine_fns$’ was declared here 232 | ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; | ^~~~~~~~~~ This is a false positive - we over allocate engine_fn, and then only initialize the nr_cpus entries which we will later go on to use. However, we can easily silence this warning by initializing the unused entries in engine_fns to NULL, this might also help if anyone ever looks at engine_fns in a debugger, it should now be obvious which entries are in use, and which are not. With this change the warning is gone. There should be no change in behaviour with this commit. --- sim/common/cgen-run.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c index 9a13b0ca416..a9a493c01b9 100644 --- a/sim/common/cgen-run.c +++ b/sim/common/cgen-run.c @@ -242,6 +242,11 @@ engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast prime_cpu (cpu, max_insns); } + /* Ensure the remaining engine_fns slots are initialized, this silences a + compiler warning when engine_fns is used below. */ + for (i = nr_cpus; i < MAX_NR_PROCESSORS; ++i) + engine_fns[i] = NULL; + while (1) { SIM_ENGINE_PREFIX_HOOK (sd); -- 2.25.4