diff mbox series

[RFC] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate()

Message ID 20240223083245.80175-1-philmd@linaro.org
State New
Headers show
Series [RFC] target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate() | expand

Commit Message

Philippe Mathieu-Daudé Feb. 23, 2024, 8:32 a.m. UTC
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(-)

Comments

Thomas Huth Feb. 26, 2024, 7:43 a.m. UTC | #1
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
diff mbox series

Patch

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;