All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
@ 2020-06-08  7:14 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08  7:14 UTC (permalink / raw)
  To: qemu-devel, Martin Liška, Eric Blake
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Markus Armbruster, 1874073, Christophe de Dinechin,
	Stafford Horne, 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_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.

Buglink: https://bugs.launchpad.net/qemu/+bug/1874073
Reported-by: Martin Liška <mliska@suse.cz>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/openrisc/openrisc_sim.c | 1 +
 1 file changed, 1 insertion(+)

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) {
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 37+ messages in thread
* [PATCH] or1k: Fix compilation hiccup
@ 2020-05-26 18:51 Eric Blake
  2020-05-26 23:21 ` no-reply
                   ` (3 more replies)
  0 siblings, 4 replies; 37+ messages in thread
From: Eric Blake @ 2020-05-26 18:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Stafford Horne, Jia Liu

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 <eblake@redhat.com>
---
 hw/openrisc/openrisc_sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
index d08ce6181199..95011a8015b4 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;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 37+ messages in thread
* [Bug 1874073] [NEW] openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
@ 2020-04-21 13:16 Martin Liska
  2020-04-21 13:25 ` [Bug 1874073] " Martin Liska
                   ` (9 more replies)
  0 siblings, 10 replies; 37+ messages in thread
From: Martin Liska @ 2020-04-21 13:16 UTC (permalink / raw)
  To: qemu-devel

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

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


^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2020-08-20 14:52 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08  7:14 [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning Philippe Mathieu-Daudé
2020-06-08  7:14 ` [Bug 1874073] " Philippe Mathieu-Daudé
2020-06-08  7:16 ` Thomas Huth
2020-06-08 15:33 ` Eric Blake
2020-06-08 15:33   ` [Bug 1874073] " Eric Blake
2020-06-09 20:42   ` Stafford Horne
2020-06-09 20:49     ` Stafford Horne
2020-06-09 20:49     ` Eric Blake
2020-06-09 20:49       ` [Bug 1874073] " Eric Blake
  -- strict thread matches above, loose matches on Subject: below --
2020-05-26 18:51 [PATCH] or1k: Fix compilation hiccup Eric Blake
2020-05-26 23:21 ` no-reply
2020-05-27  2:58   ` Eric Blake
2020-05-27  5:29 ` Thomas Huth
2020-05-27  7:27 ` Philippe Mathieu-Daudé
2020-05-27  7:27   ` [Bug 1874073] " Philippe Mathieu-Daudé
2020-05-29 16:21 ` Christophe de Dinechin
2020-05-29 16:40   ` Peter Maydell
2020-06-02  7:43     ` Markus Armbruster
2020-06-08  6:03       ` Markus Armbruster
2020-06-08  6:22         ` Philippe Mathieu-Daudé
2020-06-08  9:15           ` Markus Armbruster
2020-06-08 15:43             ` Eric Blake
2020-04-21 13:16 [Bug 1874073] [NEW] openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized] Martin Liska
2020-04-21 13:25 ` [Bug 1874073] " Martin Liska
2020-04-21 13:37 ` Peter Maydell
2020-04-21 14:08 ` Martin Liska
2020-04-21 14:36 ` Peter Maydell
2020-04-21 15:08 ` Philippe Mathieu-Daudé
2020-05-27  7:54 ` Martin Liska
2020-06-08  6:25 ` Philippe Mathieu-Daudé
2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning Philippe Mathieu-Daudé
2020-06-08 16:06   ` [Bug 1874073] " Philippe Mathieu-Daudé
2020-06-08 19:42   ` Richard Henderson
2020-06-09 17:44   ` [Bug 1874073] " Laurent Vivier
2020-06-09 17:44     ` Laurent Vivier
2020-07-02  8:50 ` [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized] Philippe Mathieu-Daudé
2020-08-20 14:39 ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.