Skip to contentSkip to conversation

powerpc/xmon: Fix opcode being uninitialized in print_insn_powerpc

PATCH Applied Nathan Chancellor 3 participants 3 messages Feb 26, 2019 – Feb 28, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/xmon: Fix opcode being uninitialized in print_insn_powerpc

When building with -Wsometimes-uninitialized, Clang warns:

arch/powerpc/xmon/ppc-dis.c:157:7: warning: variable 'opcode' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (cpu_has_feature(CPU_FTRS_POWER9))

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:167:7: note: uninitialized use occurs here
  if (opcode == NULL)
      ^~~~~~

arch/powerpc/xmon/ppc-dis.c:157:3: note: remove the 'if' if its condition is always true
if (cpu_has_feature(CPU_FTRS_POWER9)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:132:38: note: initialize the variable 'opcode' to silence this warning

  const struct powerpc_opcode *opcode;
                                     ^
                                      = NULL

1 warning generated.

This warning seems to make no sense on the surface because opcode is set to NULL right below this statement. However, there is a comma instead of semicolon to end the dialect assignment, meaning that the opcode assignment only happens in the if statement. Properly terminate that line so that Clang no longer warns.

Fixes 5b102782c7f4 ("powerpc/xmon: Enable disassembly files (compilation changes)")
---
 arch/powerpc/xmon/ppc-dis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/xmon/ppc-dis.c +1 -1
index 9deea5ee13f6..27f1e6415036 100644
@@ -158,7 +158,7 @@ int print_insn_powerpc (unsigned long insn, unsigned long memaddr)
     dialect |= (PPC_OPCODE_POWER5 | PPC_OPCODE_POWER6 | PPC_OPCODE_POWER7
 		| PPC_OPCODE_POWER8 | PPC_OPCODE_POWER9 | PPC_OPCODE_HTM
 		| PPC_OPCODE_ALTIVEC | PPC_OPCODE_ALTIVEC2
-		| PPC_OPCODE_VSX | PPC_OPCODE_VSX3),
+		| PPC_OPCODE_VSX | PPC_OPCODE_VSX3);
 
   /* Get the major opcode of the insn.  */
   opcode = NULL;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

arch/powerpc/xmon/ppc-dis.c:157:7: warning: variable 'opcode' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (cpu_has_feature(CPU_FTRS_POWER9))

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:167:7: note: uninitialized use occurs here
  if (opcode == NULL)
      ^~~~~~

arch/powerpc/xmon/ppc-dis.c:157:3: note: remove the 'if' if its condition is always true
if (cpu_has_feature(CPU_FTRS_POWER9)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:132:38: note: initialize the variable 'opcode' to silence this warning

  const struct powerpc_opcode *opcode;
                                     ^
                                      = NULL

1 warning generated.

This warning seems to make no sense on the surface because opcode is set to NULL right below this statement. However, there is a comma instead of semicolon to end the dialect assignment, meaning that the opcode assignment only happens in the if statement. Properly terminate that line so that Clang no longer warns.

Quoted 3 lines
Fixes 5b102782c7f4 ("powerpc/xmon: Enable disassembly files (compilation changes)")

haha! (shows office mates). Nice find, and fix!

Quoted 20 lines
---
 arch/powerpc/xmon/ppc-dis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/xmon/ppc-dis.c +1 -2
index 9deea5ee13f6..27f1e6415036 100644
@@ -158,7 +158,7 @@ int print_insn_powerpc (unsigned long insn, unsigned long memaddr)
     dialect |= (PPC_OPCODE_POWER5 | PPC_OPCODE_POWER6 | PPC_OPCODE_POWER7
                | PPC_OPCODE_POWER8 | PPC_OPCODE_POWER9 | PPC_OPCODE_HTM
                | PPC_OPCODE_ALTIVEC | PPC_OPCODE_ALTIVEC2
-               | PPC_OPCODE_VSX | PPC_OPCODE_VSX3),
+               | PPC_OPCODE_VSX | PPC_OPCODE_VSX3);
 
   /* Get the major opcode of the insn.  */
   opcode = NULL;
--

2.21.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
In reply to Nathan Chancellor
Quoted 27 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

arch/powerpc/xmon/ppc-dis.c:157:7: warning: variable 'opcode' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (cpu_has_feature(CPU_FTRS_POWER9))

      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:167:7: note: uninitialized use occurs here
  if (opcode == NULL)
      ^~~~~~

arch/powerpc/xmon/ppc-dis.c:157:3: note: remove the 'if' if its condition is always true
if (cpu_has_feature(CPU_FTRS_POWER9)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/xmon/ppc-dis.c:132:38: note: initialize the variable 'opcode' to silence this warning

  const struct powerpc_opcode *opcode;
                                     ^
                                      = NULL

1 warning generated.

This warning seems to make no sense on the surface because opcode is set to NULL right below this statement. However, there is a comma instead of semicolon to end the dialect assignment, meaning that the opcode assignment only happens in the if statement. Properly terminate that line so that Clang no longer warns.

Quoted 4 lines
Fixes 5b102782c7f4 ("powerpc/xmon: Enable disassembly files (compilation changes)")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/e7140639b1de65bba435a6bd772d1349

cheers