hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
PATCH 1/1 hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
CC or1k-softmmu/hw/openrisc/openrisc_sim.o
hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’:
hw/openrisc/openrisc_sim.c:87:42: error: ‘cpu_irqs[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
87 | sysbus_connect_irq(s, i, cpu_irqs[i][irq_pin]);
| ~~~~~~~~^~~While humans can tell smp_cpus will always be in the [1, 2] range, (openrisc_sim_machine_init sets mc->max_cpus = 2), the compiler can't.
Add an assertion to give the compiler a hint there's no use of uninitialized data.
--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)
hw/openrisc/openrisc_sim.c +1 -0
@@ -134,6 +134,7 @@ static void openrisc_sim_init(MachineState *machine)int n;unsigned int smp_cpus = machine->smp.cpus; +assert (smp_cpus >=1 && smp_cpus <=2 );for (n =0 ; n < smp_cpus; n++) { cpu =OPENRISC_CPU (cpu_create (machine->cpu_type));if (cpu ==NULL ) {
Signature · 1 line
2.21.3
Quoted 29 lines · Philippe Mathieu-Daudé
When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
CC
or1k-softmmu/hw/openrisc/openrisc_sim.o
hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’:
hw/openrisc/openrisc_sim.c:87:42: error: ‘cpu_irqs[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]87 | sysbus_connect_irq(s, i, cpu_irqs[i][irq_pin]); | ~~~~~~~~^~~While humans can tell
smp_cpuswill always be in the [1, 2] range, (openrisc_sim_machine_initsetsmc->max_cpus= 2), the compiler can't.Add an assertion to give the compiler a hint there's no use of uninitialized data.
Reported-by Martin Liška <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)hw/openrisc/openrisc_sim.c +0
-0
hw/openrisc/openrisc_sim.c static void openrisc_sim_init(MachineState *machine) · line 140
Quoted 7 lines
hw/openrisc/openrisc_sim.c +1
-0@@ -134,6 +134,7 @@ static void openrisc_sim_init(MachineState *machine)int n;unsigned int smp_cpus = machine->smp.cpus; +assert (smp_cpus >=1 && smp_cpus <=2 );for (n =0 ; n < smp_cpus; n++) { cpu =OPENRISC_CPU (cpu_create (machine->cpu_type));if (cpu ==NULL ) {
Quoted 1 line · Philippe Mathieu-Daudé
When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
In the subject: s/silent/silence/
Quoted 14 lines
CC
or1k-softmmu/hw/openrisc/openrisc_sim.o
hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’:hw/openrisc/openrisc_sim.c:87:42: error: ‘cpu_irqs[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 87 | sysbus_connect_irq(s, i, cpu_irqs[i][irq_pin]); | ~~~~~~~~^~~While humans can tell
smp_cpuswill always be in the [1, 2] range, (openrisc_sim_machine_initsetsmc->max_cpus= 2), the compiler can't.Add an assertion to give the compiler a hint there's no use of uninitialized data.
Quoted 7 lines
Reported-by Martin Liška <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)
With the typo fixed,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Stafford Horne
Acked-byQuoted 27 lines · Eric Blake
Quoted 1 line · Philippe Mathieu-Daudé
When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
In the subject: s/silent/silence/
Quoted 14 lines
CC
or1k-softmmu/hw/openrisc/openrisc_sim.o
hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’:hw/openrisc/openrisc_sim.c:87:42: error: ‘cpu_irqs[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 87 | sysbus_connect_irq(s, i, cpu_irqs[i][irq_pin]); | ~~~~~~~~^~~While humans can tell
smp_cpuswill always be in the [1, 2] range, (openrisc_sim_machine_initsetsmc->max_cpus= 2), the compiler can't.Add an assertion to give the compiler a hint there's no use of uninitialized data.
Quoted 7 lines
Reported-by Martin Liška <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)
Quoted 4 lines
Tested-by Eric Blake <[email protected]>With the typo fixed,
Reviewed-by Eric Blake <[email protected]>
I see there are now two patches for this, I kind of like this assert fix.
Shall I queue it for OpenRISC pulling? Or can someone else pick this up?
-Stafford
Quoted 30 lines · Stafford Horne
Quoted 29 lines · Eric Blake
Quoted 1 line · Philippe Mathieu-Daudé
When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
In the subject: s/silent/silence/
Quoted 14 lines
CC
or1k-softmmu/hw/openrisc/openrisc_sim.o
hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’:hw/openrisc/openrisc_sim.c:87:42: error: ‘cpu_irqs[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 87 | sysbus_connect_irq(s, i, cpu_irqs[i][irq_pin]); | ~~~~~~~~^~~While humans can tell
smp_cpuswill always be in the [1, 2] range, (openrisc_sim_machine_initsetsmc->max_cpus= 2), the compiler can't.Add an assertion to give the compiler a hint there's no use of uninitialized data.
Quoted 7 lines
Reported-by Martin Liška <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)Tested-by Eric Blake <[email protected]>
Quoted 8 lines
Quoted 2 lines
With the typo fixed,
Reviewed-by Eric Blake <[email protected]>Acked-by Stafford Horne <[email protected]>I see there are now two patches for this, I kind of like this assert fix.
Shall I queue it for OpenRISC pulling? Or can someone else pick this up?
Hello,
Sorry, I see v2 of this patch has already been picked up.
-Stafford
Quoted 8 lines · Stafford Horne
Quoted 7 lines
Quoted 7 lines
While humans can tell
smp_cpuswill always be in the [1, 2] range, (openrisc_sim_machine_initsetsmc->max_cpus= 2), the compiler can't.Add an assertion to give the compiler a hint there's no use of uninitialized data.
Quoted 5 lines
Acked-by Stafford Horne <[email protected]>I see there are now two patches for this, I kind of like this assert fix.
Shall I queue it for OpenRISC pulling? Or can someone else pick this up?
Looks like Laurent already volunteered to queue it through the trivial patches tree.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org