From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id EEF0D3858D39; Wed, 19 Oct 2022 13:32:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEF0D3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666186367; bh=3xZKpiSOEXF2/8YGhh+XExd1Edw7AfY4iwVCdl3qX8U=; h=From:To:Subject:Date:From; b=fApEvejMa4uhc5l4iEPnksAIvRQ844abJMSQwCmqtzUah6x18ZlzI/FA6p9DycJbL lPqfZWDy4K1nLu8ACOWdOmlhkxJrtaXmrZCEcdBQnZy3XNTok4LSRrsleHD4S3FaSN rWwdqh8cqpiaN6hUqezmRedinCkClNASGB+kJrNk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim/cgen: mask uninitialized variable warning in cgen-run.c X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 2b06e59de0675c2cb526af2de6803dae29703d15 X-Git-Newrev: cb9d1609da6e623158ba5a8cb4a2712bcea4f57f Message-Id: <20221019133247.EEF0D3858D39@sourceware.org> Date: Wed, 19 Oct 2022 13:32:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dcb9d1609da6e= 623158ba5a8cb4a2712bcea4f57f commit cb9d1609da6e623158ba5a8cb4a2712bcea4f57f Author: Andrew Burgess Date: Wed Oct 12 11:07:24 2022 +0100 sim/cgen: mask uninitialized variable warning in cgen-run.c =20 I see an uninitialized variable warning (with gcc 9.3.1) from cgen-run.c, like this: =20 /tmp/build/sim/../../src/sim/cris/../common/cgen-run.c: In function = =E2=80=98sim_resume=E2=80=99: /tmp/build/sim/../../src/sim/cris/../common/cgen-run.c:259:5: warning= : =E2=80=98engine_fns$=E2=80=99 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: = =E2=80=98engine_fns$=E2=80=99 was declared here 232 | ENGINE_FN *engine_fns[MAX_NR_PROCESSORS]; | ^~~~~~~~~~ =20 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. =20 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. =20 With this change the warning is gone. =20 There should be no change in behaviour with this commit. Diff: --- 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_cpu= s, int max_insns, int fast prime_cpu (cpu, max_insns); } =20 + /* Ensure the remaining engine_fns slots are initialized, this silences a + compiler warning when engine_fns is used below. */ + for (i =3D nr_cpus; i < MAX_NR_PROCESSORS; ++i) + engine_fns[i] =3D NULL; + while (1) { SIM_ENGINE_PREFIX_HOOK (sd);