openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized] 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 {}. Suggested patch: diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index 79e7049..724dcd0 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -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; I'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] ? Note 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. Does 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? Confirming Peter's suggestion does silent the warning. -- >8 -- diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index d08ce61811..02f5259e5e 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -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) { --- On 5/26/20 8:51 PM, Eric Blake wrote: > On my Fedora 32 machine, gcc 10.1.1 at -O2 (the default for a bare > './configure') has a false-positive complaint: > > CC or1k-softmmu/hw/openrisc/openrisc_sim.o > /home/eblake/qemu/hw/openrisc/openrisc_sim.c: In function ‘openrisc_sim_init’: > /home/eblake/qemu/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]); > | ~~~~~~~~^~~ > > Initializing both pointers of cpu_irqs[] to NULL is sufficient to shut > up the compiler, even though they are definitely assigned in > openrisc_sim_init() prior to the inlined call to > openrisc_sim_ompic_init() containing the line in question. > > Signed-off-by: Eric Blake