qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [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
                   ` (10 more replies)
  0 siblings, 11 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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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 ` Martin Liska
  2020-04-21 13:37 ` Peter Maydell
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Martin Liska @ 2020-04-21 13:25 UTC (permalink / raw)
  To: qemu-devel

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;

-- 
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 related	[flat|nested] 37+ messages in thread

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Peter Maydell @ 2020-04-21 13:37 UTC (permalink / raw)
  To: qemu-devel

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

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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Martin Liska @ 2020-04-21 14:08 UTC (permalink / raw)
  To: qemu-devel

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.

** Bug watch added: GCC Bugzilla #24639
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639

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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (2 preceding siblings ...)
  2020-04-21 14:08 ` Martin Liska
@ 2020-04-21 14:36 ` Peter Maydell
  2020-04-21 15:08 ` Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Peter Maydell @ 2020-04-21 14:36 UTC (permalink / raw)
  To: qemu-devel

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?

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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (3 preceding siblings ...)
  2020-04-21 14:36 ` Peter Maydell
@ 2020-04-21 15:08 ` Philippe Mathieu-Daudé
  2020-05-27  7:54 ` Martin Liska
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 15:08 UTC (permalink / raw)
  To: qemu-devel

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

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

* Re: [PATCH] or1k: Fix compilation hiccup
  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
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 37+ messages in thread
From: no-reply @ 2020-05-26 23:21 UTC (permalink / raw)
  To: eblake; +Cc: qemu-trivial, shorne, qemu-devel, proljc

Patchew URL: https://patchew.org/QEMU/20200526185132.1652355-1-eblake@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20200526185132.1652355-1-eblake@redhat.com
Subject: [PATCH] or1k: Fix compilation hiccup
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Switched to a new branch 'test'
d96d2fb or1k: Fix compilation hiccup

=== OUTPUT BEGIN ===
ERROR: spaces required around that '*' (ctx:WxV)
#33: FILE: hw/openrisc/openrisc_sim.c:132:
+    qemu_irq *cpu_irqs[2] = {};
              ^

total: 1 errors, 0 warnings, 8 lines checked

Commit d96d2fbbc5db (or1k: Fix compilation hiccup) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20200526185132.1652355-1-eblake@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-26 23:21 ` no-reply
@ 2020-05-27  2:58   ` Eric Blake
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Blake @ 2020-05-27  2:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, shorne, proljc

On 5/26/20 6:21 PM, no-reply@patchew.org wrote:
> Patchew URL: https://patchew.org/QEMU/20200526185132.1652355-1-eblake@redhat.com/
> 
> 
> 
> Hi,
> 
> This series seems to have some coding style problems. See output below for
> more information:
> 

> === OUTPUT BEGIN ===
> ERROR: spaces required around that '*' (ctx:WxV)
> #33: FILE: hw/openrisc/openrisc_sim.c:132:
> +    qemu_irq *cpu_irqs[2] = {};
>                ^
> 
> total: 1 errors, 0 warnings, 8 lines checked
> 
> Commit d96d2fbbc5db (or1k: Fix compilation hiccup) has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.

False positive, due to 'qemu_irq' not following the normal naming 
conventions for typedefs.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-26 18:51 [PATCH] or1k: Fix compilation hiccup Eric Blake
  2020-05-26 23:21 ` no-reply
@ 2020-05-27  5:29 ` Thomas Huth
  2020-05-27  7:27 ` Philippe Mathieu-Daudé
  2020-05-29 16:21 ` Christophe de Dinechin
  3 siblings, 0 replies; 37+ messages in thread
From: Thomas Huth @ 2020-05-27  5:29 UTC (permalink / raw)
  To: Eric Blake, qemu-devel; +Cc: qemu-trivial, Stafford Horne, Jia Liu

On 26/05/2020 20.51, 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 <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;
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-26 18:51 [PATCH] or1k: Fix compilation hiccup Eric Blake
  2020-05-26 23:21 ` no-reply
  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
  3 siblings, 1 reply; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-27  7:27 UTC (permalink / raw)
  To: Eric Blake, qemu-devel
  Cc: Peter Maydell, Jia Liu, qemu-trivial, Bug 1874073,
	Stafford Horne, Martin Liska

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 <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] = {};

Ah I now remembered why this warning sound familiar:
https://bugs.launchpad.net/qemu/+bug/1874073

Peter suggested a different fix, I tested it, and was expecting Martin
Liska to post an updated patch.

>      qemu_irq serial_irq;
>      int n;
>      unsigned int smp_cpus = machine->smp.cpus;
> 



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

* [Bug 1874073] Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-27  7:27 ` Philippe Mathieu-Daudé
@ 2020-05-27  7:27   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-27  7:27 UTC (permalink / raw)
  To: qemu-devel

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 <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] = {};

Ah I now remembered why this warning sound familiar:
https://bugs.launchpad.net/qemu/+bug/1874073

Peter suggested a different fix, I tested it, and was expecting Martin
Liska to post an updated patch.

>      qemu_irq serial_irq;
>      int n;
>      unsigned int smp_cpus = machine->smp.cpus;
>

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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (4 preceding siblings ...)
  2020-04-21 15:08 ` Philippe Mathieu-Daudé
@ 2020-05-27  7:54 ` Martin Liska
  2020-06-08  6:25 ` Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Martin Liska @ 2020-05-27  7:54 UTC (permalink / raw)
  To: qemu-devel

Hello. The assert approach is preferred.

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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-26 18:51 [PATCH] or1k: Fix compilation hiccup Eric Blake
                   ` (2 preceding siblings ...)
  2020-05-27  7:27 ` Philippe Mathieu-Daudé
@ 2020-05-29 16:21 ` Christophe de Dinechin
  2020-05-29 16:40   ` Peter Maydell
  3 siblings, 1 reply; 37+ messages in thread
From: Christophe de Dinechin @ 2020-05-29 16:21 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-trivial, Stafford Horne, Jia Liu, qemu-devel


On 2020-05-26 at 20:51 CEST, 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 <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] = {};

Why is the value [2] correct here? The loop that initializes loops over
machine->smp.cpus. Is it always less than 2 on this machine?


>      qemu_irq serial_irq;
>      int n;
>      unsigned int smp_cpus = machine->smp.cpus;


--
Cheers,
Christophe de Dinechin (IRC c3d)



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-29 16:21 ` Christophe de Dinechin
@ 2020-05-29 16:40   ` Peter Maydell
  2020-06-02  7:43     ` Markus Armbruster
  0 siblings, 1 reply; 37+ messages in thread
From: Peter Maydell @ 2020-05-29 16:40 UTC (permalink / raw)
  To: Christophe de Dinechin
  Cc: QEMU Trivial, Stafford Horne, Jia Liu, QEMU Developers

On Fri, 29 May 2020 at 17:23, Christophe de Dinechin
<dinechin@redhat.com> wrote:
> On 2020-05-26 at 20:51 CEST, Eric Blake wrote...
> > 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] = {};
>
> Why is the value [2] correct here? The loop that initializes loops over
> machine->smp.cpus. Is it always less than 2 on this machine?

Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
My suggestion of adding an assert() is essentially telling the
compiler that indeed smp_cpus must always be in the range [1,2],
which we can tell but it can't.

thanks
-- PMM


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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-05-29 16:40   ` Peter Maydell
@ 2020-06-02  7:43     ` Markus Armbruster
  2020-06-08  6:03       ` Markus Armbruster
  0 siblings, 1 reply; 37+ messages in thread
From: Markus Armbruster @ 2020-06-02  7:43 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Jia Liu, QEMU Trivial, QEMU Developers, Christophe de Dinechin,
	Stafford Horne, Philippe Mathieu-Daudé

Peter Maydell <peter.maydell@linaro.org> writes:

> On Fri, 29 May 2020 at 17:23, Christophe de Dinechin
> <dinechin@redhat.com> wrote:
>> On 2020-05-26 at 20:51 CEST, Eric Blake wrote...
>> > 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] = {};
>>
>> Why is the value [2] correct here? The loop that initializes loops over
>> machine->smp.cpus. Is it always less than 2 on this machine?
>
> Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
> My suggestion of adding an assert() is essentially telling the
> compiler that indeed smp_cpus must always be in the range [1,2],
> which we can tell but it can't.

Do we have a proper patch for this on the list?



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-06-02  7:43     ` Markus Armbruster
@ 2020-06-08  6:03       ` Markus Armbruster
  2020-06-08  6:22         ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 37+ messages in thread
From: Markus Armbruster @ 2020-06-08  6:03 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Jia Liu, QEMU Trivial, QEMU Developers, Christophe de Dinechin,
	Stafford Horne, Philippe Mathieu-Daudé

Markus Armbruster <armbru@redhat.com> writes:

> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On Fri, 29 May 2020 at 17:23, Christophe de Dinechin
>> <dinechin@redhat.com> wrote:
>>> On 2020-05-26 at 20:51 CEST, Eric Blake wrote...
>>> > 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] = {};
>>>
>>> Why is the value [2] correct here? The loop that initializes loops over
>>> machine->smp.cpus. Is it always less than 2 on this machine?
>>
>> Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
>> My suggestion of adding an assert() is essentially telling the
>> compiler that indeed smp_cpus must always be in the range [1,2],
>> which we can tell but it can't.
>
> Do we have a proper patch for this on the list?

Apparently not.

Philippe did try Peter's suggestion, found it works, but then posted it
only to Launchpad.  Philippe, please post to the list, so we can finally
get this fixed.



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-06-08  6:03       ` Markus Armbruster
@ 2020-06-08  6:22         ` Philippe Mathieu-Daudé
  2020-06-08  9:15           ` Markus Armbruster
  0 siblings, 1 reply; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08  6:22 UTC (permalink / raw)
  To: Markus Armbruster, Peter Maydell
  Cc: Christophe de Dinechin, QEMU Trivial, Stafford Horne, Jia Liu,
	QEMU Developers

On 6/8/20 8:03 AM, Markus Armbruster wrote:
> Markus Armbruster <armbru@redhat.com> writes:
> 
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>>> On Fri, 29 May 2020 at 17:23, Christophe de Dinechin
>>> <dinechin@redhat.com> wrote:
>>>> On 2020-05-26 at 20:51 CEST, Eric Blake wrote...
>>>>> 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] = {};
>>>>
>>>> Why is the value [2] correct here? The loop that initializes loops over
>>>> machine->smp.cpus. Is it always less than 2 on this machine?
>>>
>>> Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
>>> My suggestion of adding an assert() is essentially telling the
>>> compiler that indeed smp_cpus must always be in the range [1,2],
>>> which we can tell but it can't.
>>
>> Do we have a proper patch for this on the list?
> 
> Apparently not.
> 
> Philippe did try Peter's suggestion, found it works, but then posted it
> only to Launchpad.  Philippe, please post to the list, so we can finally
> get this fixed.

Sorry since it was Eric finding, I didn't understood I had to post it.
Will do.



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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (5 preceding siblings ...)
  2020-05-27  7:54 ` Martin Liska
@ 2020-06-08  6:25 ` Philippe Mathieu-Daudé
  2020-06-08  7:14 ` [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08  6:25 UTC (permalink / raw)
  To: qemu-devel

** Changed in: qemu
       Status: New => Confirmed

-- 
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/+subscriptions


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

* [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
@ 2020-06-08  7:14 ` Philippe Mathieu-Daudé
  2020-06-08  7:14   ` [Bug 1874073] " Philippe Mathieu-Daudé
                     ` (2 more replies)
  0 siblings, 3 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

* [Bug 1874073] [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  2020-06-08  7:14 ` [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning Philippe Mathieu-Daudé
@ 2020-06-08  7:14   ` Philippe Mathieu-Daudé
  2020-06-08  7:16   ` Thomas Huth
  2020-06-08 15:33   ` Eric Blake
  2 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08  7:14 UTC (permalink / raw)
  To: qemu-devel

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


** Changed in: qemu
     Assignee: (unassigned) => Philippe Mathieu-Daudé (philmd)

-- 
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/+subscriptions


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

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

On 08/06/2020 09.14, Philippe Mathieu-Daudé wrote:
> 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) {
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-06-08  6:22         ` Philippe Mathieu-Daudé
@ 2020-06-08  9:15           ` Markus Armbruster
  2020-06-08 15:43             ` Eric Blake
  0 siblings, 1 reply; 37+ messages in thread
From: Markus Armbruster @ 2020-06-08  9:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Jia Liu, QEMU Trivial, QEMU Developers,
	Christophe de Dinechin, Stafford Horne

Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 6/8/20 8:03 AM, Markus Armbruster wrote:
>> Markus Armbruster <armbru@redhat.com> writes:
>> 
>>> Peter Maydell <peter.maydell@linaro.org> writes:
>>>
>>>> On Fri, 29 May 2020 at 17:23, Christophe de Dinechin
>>>> <dinechin@redhat.com> wrote:
>>>>> On 2020-05-26 at 20:51 CEST, Eric Blake wrote...
>>>>>> 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] = {};
>>>>>
>>>>> Why is the value [2] correct here? The loop that initializes loops over
>>>>> machine->smp.cpus. Is it always less than 2 on this machine?
>>>>
>>>> Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
>>>> My suggestion of adding an assert() is essentially telling the
>>>> compiler that indeed smp_cpus must always be in the range [1,2],
>>>> which we can tell but it can't.
>>>
>>> Do we have a proper patch for this on the list?
>> 
>> Apparently not.
>> 
>> Philippe did try Peter's suggestion, found it works, but then posted it
>> only to Launchpad.  Philippe, please post to the list, so we can finally
>> get this fixed.
>
> Sorry since it was Eric finding, I didn't understood I had to post it.
> Will do.

You didn't *have* to, but it'll help if you do :)



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

* Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  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
  2 siblings, 2 replies; 37+ messages in thread
From: Eric Blake @ 2020-06-08 15:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, Martin Liška
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Markus Armbruster, 1874073, Christophe de Dinechin,
	Stafford Horne

On 6/8/20 2:14 AM, Philippe Mathieu-Daudé wrote:
> When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:

In the subject: s/silent/silence/

> 
>      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(+)

Tested-by: Eric Blake <eblake@redhat.com>

With the typo fixed,
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



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

* [Bug 1874073] Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  2020-06-08 15:33   ` Eric Blake
@ 2020-06-08 15:33     ` Eric Blake
  2020-06-09 20:42     ` Stafford Horne
  1 sibling, 0 replies; 37+ messages in thread
From: Eric Blake @ 2020-06-08 15:33 UTC (permalink / raw)
  To: qemu-devel

On 6/8/20 2:14 AM, Philippe Mathieu-Daudé wrote:
> When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:

In the subject: s/silent/silence/

> 
>      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(+)

Tested-by: Eric Blake <eblake@redhat.com>

With the typo fixed,
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-- 
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/+subscriptions


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

* Re: [PATCH] or1k: Fix compilation hiccup
  2020-06-08  9:15           ` Markus Armbruster
@ 2020-06-08 15:43             ` Eric Blake
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Blake @ 2020-06-08 15:43 UTC (permalink / raw)
  To: Markus Armbruster, Philippe Mathieu-Daudé
  Cc: Peter Maydell, Jia Liu, QEMU Trivial, QEMU Developers,
	Christophe de Dinechin, Stafford Horne

On 6/8/20 4:15 AM, Markus Armbruster wrote:

>>>>> Yes: openrisc_sim_machine_init() sets mc->max_cpus = 2.
>>>>> My suggestion of adding an assert() is essentially telling the
>>>>> compiler that indeed smp_cpus must always be in the range [1,2],
>>>>> which we can tell but it can't.
>>>>
>>>> Do we have a proper patch for this on the list?
>>>
>>> Apparently not.
>>>
>>> Philippe did try Peter's suggestion, found it works, but then posted it
>>> only to Launchpad.  Philippe, please post to the list, so we can finally
>>> get this fixed.
>>
>> Sorry since it was Eric finding, I didn't understood I had to post it.
>> Will do.
> 
> You didn't *have* to, but it'll help if you do :)

Now at https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg01779.html

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



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

* [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
@ 2020-06-08 16:06 ` Philippe Mathieu-Daudé
  2020-06-08 16:06   ` [Bug 1874073] " Philippe Mathieu-Daudé
                     ` (2 more replies)
  0 siblings, 3 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08 16:06 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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2: Fixed typo in subject (eblake)
Supersedes: <20200608071409.17024-1-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

* [Bug 1874073] [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
  2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence " Philippe Mathieu-Daudé
@ 2020-06-08 16:06   ` Philippe Mathieu-Daudé
  2020-06-08 19:42   ` Richard Henderson
  2020-06-09 17:44   ` [Bug 1874073] " Laurent Vivier
  2 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-08 16:06 UTC (permalink / raw)
  To: qemu-devel

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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2: Fixed typo in subject (eblake)
Supersedes: <20200608071409.17024-1-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

-- 
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/+subscriptions


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

* Re: [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
  2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence " 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
  2 siblings, 0 replies; 37+ messages in thread
From: Richard Henderson @ 2020-06-08 19:42 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, Martin Liška, Eric Blake
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Markus Armbruster, 1874073, Christophe de Dinechin,
	Stafford Horne

On 6/8/20 9:06 AM, Philippe Mathieu-Daudé wrote:
> 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>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Tested-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v2: Fixed typo in subject (eblake)
> Supersedes: <20200608071409.17024-1-philmd@redhat.com>
> ---
>  hw/openrisc/openrisc_sim.c | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


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

* [Bug 1874073] Re: [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
  2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence " 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   ` Laurent Vivier
  2020-06-09 17:44     ` Laurent Vivier
  2 siblings, 1 reply; 37+ messages in thread
From: Laurent Vivier @ 2020-06-09 17:44 UTC (permalink / raw)
  To: qemu-devel

Le 08/06/2020 à 18:06, Philippe Mathieu-Daudé a écrit :
> 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>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Tested-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v2: Fixed typo in subject (eblake)
> Supersedes: <20200608071409.17024-1-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) {
> 

Applied to my trivial-patches branch.

Thanks,
Laurent

-- 
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/+subscriptions


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

* Re: [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence GCC warning
  2020-06-09 17:44   ` [Bug 1874073] " Laurent Vivier
@ 2020-06-09 17:44     ` Laurent Vivier
  0 siblings, 0 replies; 37+ messages in thread
From: Laurent Vivier @ 2020-06-09 17:44 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, Martin Liška, Eric Blake
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Markus Armbruster, 1874073, Christophe de Dinechin,
	Stafford Horne

Le 08/06/2020 à 18:06, Philippe Mathieu-Daudé a écrit :
> 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>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Tested-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> v2: Fixed typo in subject (eblake)
> Supersedes: <20200608071409.17024-1-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) {
> 

Applied to my trivial-patches branch.

Thanks,
Laurent



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

* Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  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
  1 sibling, 2 replies; 37+ messages in thread
From: Stafford Horne @ 2020-06-09 20:42 UTC (permalink / raw)
  To: Eric Blake
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Philippe Mathieu-Daudé,
	qemu-devel, Markus Armbruster, 1874073, Christophe de Dinechin,
	Martin Liška

On Mon, Jun 08, 2020 at 10:33:24AM -0500, Eric Blake wrote:
> On 6/8/20 2:14 AM, Philippe Mathieu-Daudé wrote:
> > When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
> 
> In the subject: s/silent/silence/
> 
> > 
> >      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(+)
> 
> Tested-by: Eric Blake <eblake@redhat.com>
> 
> With the typo fixed,
> Reviewed-by: Eric Blake <eblake@redhat.com>

Acked-by: Stafford Horne <shorne@gmail.com>

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


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

* Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  2020-06-09 20:42     ` Stafford Horne
@ 2020-06-09 20:49       ` Stafford Horne
  2020-06-09 20:49       ` Eric Blake
  1 sibling, 0 replies; 37+ messages in thread
From: Stafford Horne @ 2020-06-09 20:49 UTC (permalink / raw)
  To: Eric Blake
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Philippe Mathieu-Daudé,
	qemu-devel, Markus Armbruster, 1874073, Christophe de Dinechin,
	Martin Liška

On Wed, Jun 10, 2020 at 05:42:27AM +0900, Stafford Horne wrote:
> On Mon, Jun 08, 2020 at 10:33:24AM -0500, Eric Blake wrote:
> > On 6/8/20 2:14 AM, Philippe Mathieu-Daudé wrote:
> > > When compiling with GCC 10 (Fedora 32) using CFLAGS=-O2 we get:
> > 
> > In the subject: s/silent/silence/
> > 
> > > 
> > >      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(+)
> > 
> > Tested-by: Eric Blake <eblake@redhat.com>
> > 
> > With the typo fixed,
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> Acked-by: Stafford Horne <shorne@gmail.com>
> 
> 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


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

* Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  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
  1 sibling, 1 reply; 37+ messages in thread
From: Eric Blake @ 2020-06-09 20:49 UTC (permalink / raw)
  To: Stafford Horne
  Cc: Peter Maydell, Thomas Huth, Jia Liu, qemu-trivial,
	Philippe Mathieu-Daudé,
	qemu-devel, Markus Armbruster, 1874073, Christophe de Dinechin,
	Martin Liška

On 6/9/20 3:42 PM, Stafford Horne wrote:

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

> Acked-by: Stafford Horne <shorne@gmail.com>
> 
> 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.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



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

* [Bug 1874073] Re: [PATCH] hw/openrisc/openrisc_sim: Add assertion to silent GCC warning
  2020-06-09 20:49       ` Eric Blake
@ 2020-06-09 20:49         ` Eric Blake
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Blake @ 2020-06-09 20:49 UTC (permalink / raw)
  To: qemu-devel

On 6/9/20 3:42 PM, Stafford Horne wrote:

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

> Acked-by: Stafford Horne <shorne@gmail.com>
> 
> 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.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-- 
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/+subscriptions


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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (8 preceding siblings ...)
  2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence " Philippe Mathieu-Daudé
@ 2020-07-02  8:50 ` Philippe Mathieu-Daudé
  2020-08-20 14:39 ` Thomas Huth
  10 siblings, 0 replies; 37+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-07-02  8:50 UTC (permalink / raw)
  To: qemu-devel

Merged in commit 1db889c71f37d5bad411b2ef83a69739d9d598f9.

** Changed in: qemu
       Status: Confirmed => Fix Committed

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


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

* [Bug 1874073] Re: openrisc_sim.c:87:42: error: 'cpu_irqs[0]' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  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
                   ` (9 preceding siblings ...)
  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
  10 siblings, 0 replies; 37+ messages in thread
From: Thomas Huth @ 2020-08-20 14:39 UTC (permalink / raw)
  To: qemu-devel

** Changed in: qemu
       Status: Fix Committed => Fix Released

-- 
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/+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-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  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
2020-06-08 16:06 ` [PATCH v2] hw/openrisc/openrisc_sim: Add assertion to silence " 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).