public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] sim/cgen: mask uninitialized variable warning in cgen-run.c
Date: Mon, 24 Oct 2022 16:57:45 +0100	[thread overview]
Message-ID: <87o7u18b9i.fsf@redhat.com> (raw)
In-Reply-To: <Y1U0ANI1BjNeVorG@vapier>

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);


  reply	other threads:[~2022-10-24 15:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12 12:38 [PATCH 0/5] Silence some build warnings in various simulators Andrew Burgess
2022-10-12 12:38 ` [PATCH 1/5] sim/cgen: mask uninitialized variable warning in cgen-run.c Andrew Burgess
2022-10-23 12:30   ` Mike Frysinger
2022-10-24 15:57     ` Andrew Burgess [this message]
2022-10-24 15:59       ` Mike Frysinger
2022-10-27 15:53         ` Andrew Burgess
2022-10-12 12:38 ` [PATCH 2/5] sim/ppc: fix warnings related to printf format strings Andrew Burgess
2022-10-12 12:46   ` Tsukasa OI
2022-10-12 13:50     ` Andrew Burgess
2022-10-23 12:20   ` Mike Frysinger
2022-10-24 15:41     ` Andrew Burgess
2022-10-12 12:38 ` [PATCH 3/5] sim/ppc: mark device_error function as ATTRIBUTE_NORETURN Andrew Burgess
2022-10-12 12:38 ` [PATCH 4/5] sim/erc32: avoid dereferencing type-punned pointer warnings Andrew Burgess
2022-10-12 14:11   ` Pedro Alves
2022-10-12 17:02     ` Lancelot SIX
2022-10-13 10:35       ` Andrew Burgess
2022-10-13 10:49         ` Pedro Alves
2022-10-23 12:34   ` Mike Frysinger
2022-10-24 15:42     ` Andrew Burgess
2022-10-12 12:38 ` [PATCH 5/5] sim/iq2000: silence pointer-sign warnings Andrew Burgess
2022-10-23 12:32   ` Mike Frysinger
2022-10-24 15:45     ` Andrew Burgess
2022-10-26  8:51       ` Mike Frysinger
2022-10-14 17:50 ` [PATCH 0/5] Silence some build warnings in various simulators Tom Tromey
2022-10-19 13:34   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7u18b9i.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).