target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate()
RFC PATCH 1/1 target/ppc/mmu: Silent maybe-uninitialized error in ppc_hash64_xlate()
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.
---
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(-)
target/ppc/mmu-hash64.c +1 -1
@@ -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;
Signature · 1 line
2.41.0
Quoted 32 lines · 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 ifppc_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;
Quoted 6 lines
So IIUC this "uninitialized use" can not happens.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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