qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate()
@ 2024-02-23  8:32 Philippe Mathieu-Daudé
  2024-02-26  7:43 ` Thomas Huth
  0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-02-23  8:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cédric Le Goater, Nicholas Piggin, Thomas Huth,
	Daniel Henrique Barboza, qemu-ppc, Daniel P . Berrangé,
	Philippe Mathieu-Daudé

Initialize apshift to avoid a maybe-uninitialized error:

  C compiler for the host machine: cc -m64 -mbig-endian (gcc 13.2.0 "cc (Debian 13.2.0-10) 13.2.0")
  C linker for the host machine: cc -m64 -mbig-endian ld.bfd 2.41.90.20240115
  Host machine cpu family: ppc64
  Host machine cpu: ppc64
  ...
  target/ppc/mmu-hash64.c: In function 'ppc_hash64_xlate':
  target/ppc/mmu-hash64.c:1154:15: error: 'apshift' may be used uninitialized [-Werror=maybe-uninitialized]
   1154 |     *raddrp = deposit64(pte.pte1 & HPTE64_R_RPN, 0, apshift, eaddr);
        |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  target/ppc/mmu-hash64.c:947:14: note: 'apshift' was declared here
    947 |     unsigned apshift;
        |              ^~~~~~~

The call chain is:

  ppc_hash64_xlate -> ppc_hash64_htab_lookup -> ppc_hash64_pteg_search

ppc_hash64_pteg_search() either sets *pshift or returns -1,

ppc_hash64_htab_lookup() returns if ppc_hash64_pteg_search()
returned -1:

  1068:    ptex = ppc_hash64_htab_lookup(cpu, slb, eaddr, &pte, &apshift);
  1069:    if (ptex == -1) {
  1070:        if (!guest_visible) {
  1071:            return false;
  1072:        }
               ...
  1087:        return false;

So IIUC this "uninitialized use" can not happens.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
I had this in an old branch (2 months old) I just rebased,
and don't get why nobody else got this error yet.
---
 target/ppc/mmu-hash64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c
index d645c0bb94..cd1e0c13c8 100644
--- a/target/ppc/mmu-hash64.c
+++ b/target/ppc/mmu-hash64.c
@@ -944,7 +944,7 @@ bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
     CPUPPCState *env = &cpu->env;
     ppc_slb_t vrma_slbe;
     ppc_slb_t *slb;
-    unsigned apshift;
+    unsigned apshift = 0;
     hwaddr ptex;
     ppc_hash_pte64_t pte;
     int exec_prot, pp_prot, amr_prot, prot;
-- 
2.41.0



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

* Re: [RFC PATCH] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate()
  2024-02-23  8:32 [RFC PATCH] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate() Philippe Mathieu-Daudé
@ 2024-02-26  7:43 ` Thomas Huth
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Huth @ 2024-02-26  7:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Cédric Le Goater, Nicholas Piggin, Daniel Henrique Barboza,
	qemu-ppc, Daniel P . Berrangé

On 23/02/2024 09.32, Philippe Mathieu-Daudé wrote:
> Initialize apshift to avoid a maybe-uninitialized error:
> 
>    C compiler for the host machine: cc -m64 -mbig-endian (gcc 13.2.0 "cc (Debian 13.2.0-10) 13.2.0")
>    C linker for the host machine: cc -m64 -mbig-endian ld.bfd 2.41.90.20240115
>    Host machine cpu family: ppc64
>    Host machine cpu: ppc64
>    ...
>    target/ppc/mmu-hash64.c: In function 'ppc_hash64_xlate':
>    target/ppc/mmu-hash64.c:1154:15: error: 'apshift' may be used uninitialized [-Werror=maybe-uninitialized]
>     1154 |     *raddrp = deposit64(pte.pte1 & HPTE64_R_RPN, 0, apshift, eaddr);
>          |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    target/ppc/mmu-hash64.c:947:14: note: 'apshift' was declared here
>      947 |     unsigned apshift;
>          |              ^~~~~~~
> 
> The call chain is:
> 
>    ppc_hash64_xlate -> ppc_hash64_htab_lookup -> ppc_hash64_pteg_search
> 
> ppc_hash64_pteg_search() either sets *pshift or returns -1,
> 
> ppc_hash64_htab_lookup() returns if ppc_hash64_pteg_search()
> returned -1:
> 
>    1068:    ptex = ppc_hash64_htab_lookup(cpu, slb, eaddr, &pte, &apshift);
>    1069:    if (ptex == -1) {
>    1070:        if (!guest_visible) {
>    1071:            return false;
>    1072:        }
>                 ...
>    1087:        return false;
> 
> So IIUC this "uninitialized use" can not happens.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> I had this in an old branch (2 months old) I just rebased,
> and don't get why nobody else got this error yet.

That's weird, indeed. Did you maybe compile without optimizations when you 
hit the error?

  Thomas




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

end of thread, other threads:[~2024-02-26  7:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-23  8:32 [RFC PATCH] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate() Philippe Mathieu-Daudé
2024-02-26  7:43 ` Thomas Huth

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