Message ID | aab2ea3326ddac9c919045fd90c54085b1ce4811.1665578246.git.aburgess@redhat.com |
---|---|
State | Committed |
Commit | cb9d1609da6e623158ba5a8cb4a2712bcea4f57f |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> 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 2F1B938207CB for <patchwork@sourceware.org>; Wed, 12 Oct 2022 12:39:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1B938207CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665578349; 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=w51rax5etv/el9mXHrsgs5P3lrBCjUFFge7JmrVKiurso69bbMGlFAmNpMUSV5wDf ogEUlsHjnI8jjpoa/Boy4f8pMZUMKxLoZlb65X6DUz+IWEhiEYA7eNcXITlEaZRUBf 7KJGzr/6xavZFz8jfBDaT+oLR06XMCA0aH/CFXBY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 <gdb-patches@sourceware.org>; 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 <gdb-patches@sourceware.org>; 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: <aab2ea3326ddac9c919045fd90c54085b1ce4811.1665578246.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <cover.1665578246.git.aburgess@redhat.com> References: <cover.1665578246.git.aburgess@redhat.com> 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-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Andrew Burgess <aburgess@redhat.com> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Silence some build warnings in various simulators
|
|
Commit Message
Andrew Burgess
Oct. 12, 2022, 12:38 p.m. UTC
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(+)
Comments
On 12 Oct 2022 13:38, Andrew Burgess via Gdb-patches wrote: > --- 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; engine_fns is declared in this func. why not assign it and let gcc handle the rest ? - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; -mike
Mike Frysinger <vapier@gentoo.org> writes: > On 12 Oct 2022 13:38, Andrew Burgess via Gdb-patches wrote: >> --- 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; > > engine_fns is declared in this func. why not assign it and let gcc handle > the rest ? > - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; > + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; How's the patch below? Thanks, Andrew --- commit 79f4f1d82d1da482e223079deb453eda7b2d2323 Author: Andrew Burgess <aburgess@redhat.com> Date: Mon Oct 24 16:55:07 2022 +0100 sim/cgen: initialize variable at creation in engine_run_n Zero initialize engine_fns entirely at creation, then override those fields we intend to use, rather than zero just initializing the unused fields later on. There should be no user visible changes after this commit. diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c index a9a493c01b9..1ace067a395 100644 --- a/sim/common/cgen-run.c +++ b/sim/common/cgen-run.c @@ -229,7 +229,7 @@ static void engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p) { int i; - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; SIM_ASSERT (nr_cpus <= MAX_NR_PROCESSORS); SIM_ASSERT (next_cpu_nr >= 0 && next_cpu_nr < nr_cpus); @@ -242,11 +242,6 @@ 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);
On 24 Oct 2022 16:57, Andrew Burgess wrote: > Mike Frysinger <vapier@gentoo.org> writes: > commit 79f4f1d82d1da482e223079deb453eda7b2d2323 > Author: Andrew Burgess <aburgess@redhat.com> > Date: Mon Oct 24 16:55:07 2022 +0100 > > sim/cgen: initialize variable at creation in engine_run_n > > Zero initialize engine_fns entirely at creation, then override those > fields we intend to use, rather than zero just initializing the unused > fields later on. > > There should be no user visible changes after this commit. > > diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c > index a9a493c01b9..1ace067a395 100644 > --- a/sim/common/cgen-run.c > +++ b/sim/common/cgen-run.c > @@ -229,7 +229,7 @@ static void > engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p) > { > int i; > - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; > + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; > > SIM_ASSERT (nr_cpus <= MAX_NR_PROCESSORS); > SIM_ASSERT (next_cpu_nr >= 0 && next_cpu_nr < nr_cpus); > @@ -242,11 +242,6 @@ 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. */ this comment is useful, so i would retain it otherwise lgtm -mike
Mike Frysinger <vapier@gentoo.org> writes: > On 24 Oct 2022 16:57, Andrew Burgess wrote: >> Mike Frysinger <vapier@gentoo.org> writes: >> commit 79f4f1d82d1da482e223079deb453eda7b2d2323 >> Author: Andrew Burgess <aburgess@redhat.com> >> Date: Mon Oct 24 16:55:07 2022 +0100 >> >> sim/cgen: initialize variable at creation in engine_run_n >> >> Zero initialize engine_fns entirely at creation, then override those >> fields we intend to use, rather than zero just initializing the unused >> fields later on. >> >> There should be no user visible changes after this commit. >> >> diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c >> index a9a493c01b9..1ace067a395 100644 >> --- a/sim/common/cgen-run.c >> +++ b/sim/common/cgen-run.c >> @@ -229,7 +229,7 @@ static void >> engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p) >> { >> int i; >> - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; >> + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; >> >> SIM_ASSERT (nr_cpus <= MAX_NR_PROCESSORS); >> SIM_ASSERT (next_cpu_nr >= 0 && next_cpu_nr < nr_cpus); >> @@ -242,11 +242,6 @@ 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. */ > > this comment is useful, so i would retain it I added a variant of this comment back, and pushed this patch. Thanks, Andrew --- commit a09f33be653fb112586be126f3d5ab848aaed095 Author: Andrew Burgess <aburgess@redhat.com> Date: Mon Oct 24 16:55:07 2022 +0100 sim/cgen: initialize variable at creation in engine_run_n Zero initialize engine_fns entirely at creation, then override those fields we intend to use, rather than zero just initializing the unused fields later on. There should be no user visible changes after this commit. diff --git a/sim/common/cgen-run.c b/sim/common/cgen-run.c index a9a493c01b9..b6400a69c13 100644 --- a/sim/common/cgen-run.c +++ b/sim/common/cgen-run.c @@ -229,7 +229,9 @@ static void engine_run_n (SIM_DESC sd, int next_cpu_nr, int nr_cpus, int max_insns, int fast_p) { int i; - ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; + /* Ensure that engine_fns is fully initialized, this silences a compiler + warning when engine_fns is used below. */ + ENGINE_FN *engine_fns[MAX_NR_PROCESSORS] = {}; SIM_ASSERT (nr_cpus <= MAX_NR_PROCESSORS); SIM_ASSERT (next_cpu_nr >= 0 && next_cpu_nr < nr_cpus); @@ -242,11 +244,6 @@ 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);
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);