openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Public bug reported:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);I would initialize cpu_irqs[2] with {}.
** Affects: qemu
Importance: Undecided
Status: New
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsSuggested patch:
hw/openrisc/openrisc_sim.c +1 -1
@@ -129,7 +129,7 @@ static void openrisc_sim_init(MachineState *machine)const char *kernel_filename = machine->kernel_filename;OpenRISCCPU *cpu =NULL ;MemoryRegion *ram; -qemu_irq *cpu_irqs[2 ]; +qemu_irq *cpu_irqs[2 ] = {};qemu_irq serial_irq;int n;unsigned int smp_cpus = machine->smp.cpus;
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsI'm not sure why the compiler thinks it might be uninitialized here -- is it just that it's not aware that smp_cpus can't be zero and so the loop will always initialize cpu_irqs[0] ?
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsNote that our -Wmaybe-uninitialized warnings tends to report false positives. We have a rich meta bug for it:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
That's why it can't prove the variable is initialized in all possible execution paths.
** Bug watch added: GCC Bugzilla #24639
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsDoes adding "assert(smp_cpus >= 1 && smp_cpus <= 2);" after the assignment to smp_cpus give the compiler enough information to know there's no use of uninitialized data?
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsConfirming Peter's suggestion does silent the warning.
-- >8 --
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 · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsHello. The assert approach is preferred.
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
New
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptions** Changed in: qemu
Status: New => Confirmed
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
Confirmed
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsMerged in commit 1db889c71f37d5bad411b2ef83a69739d9d598f9.
** Changed in: qemu
Status: Confirmed => Fix Committed
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
Fix Committed
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptions** Changed in: qemu
Status: Fix Committed => Fix Released
Signature · 27 lines
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1874073
Title:
openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized
in this function [-Werror=maybe-uninitialized]
Status in QEMU:
Fix Released
Bug description:
I see the warning since gcc10:
static void openrisc_sim_init(MachineState *machine):
...
qemu_irq *cpu_irqs[2];
...
serial_mm_init(get_system_memory(), 0x90000000, 0, serial_irq,
115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
I would initialize cpu_irqs[2] with {}.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1874073/+subscriptionsPATCH v2 1/1 hw/openrisc/openrisc_sim: Add assertion to silence 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.
---
v2: Fixed typo in subject (eblake)
Supersedes: <[email protected]>
--- 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
Re: [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
Quoted 22 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]>Reviewed-by Thomas Huth <[email protected]>Tested-by Eric Blake <[email protected]>Reviewed-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 6 lines
---
v2: Fixed typo in subject (eblake)
Supersedes: <[email protected]>--- hw/openrisc/openrisc_sim.c | 1 + 1 file changed, 1 insertion(+)
r~
Laurent Vivier
Applied[Bug 1874073] Re: [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
In reply to Philippe Mathieu-DaudéLe 08/06/2020 à 18:06, Philippe Mathieu-Daudé a écrit :
Quoted 35 lines
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]>Reviewed-by Thomas Huth <[email protected]>Tested-by Eric Blake <[email protected]>Reviewed-by Eric Blake <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Fixed typo in subject (eblake)
Supersedes: <[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 ) {
Applied to my trivial-patches branch.
Thanks,
Laurent