]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[tdep/s390] Fix Wmaybe-uninitialized in s390_displaced_step_fixup
authorTom de Vries <tdevries@suse.de>
Wed, 29 Jul 2020 07:03:20 +0000 (09:03 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 29 Jul 2020 07:03:20 +0000 (09:03 +0200)
When building gdb with CFLAGS/CXXFLAGS="-O2 -g -Wall", I see:
...
src/gdb/s390-tdep.c: In function 'void s390_displaced_step_fixup(gdbarch*, \
  displaced_step_closure*, CORE_ADDR, CORE_ADDR, regcache*)':
src/gdb/s390-tdep.c:528:30: warning: 'r2' may be used uninitialized in this \
  function [-Wmaybe-uninitialized]
  528 |       if (insn[0] == op_basr && r2 == 0)
      |           ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
...

The problem is that the compiler is unaware that
'is_rr (insn, op_basr, &r1, &r2) == 1' ensures that 'insn[0] == op_basr':
...
  if (is_rr (insn, op_basr, &r1, &r2)
      || is_rx (insn, op_bas, &r1, &d2, &x2, &b2))
    {
      /* Recompute saved return address in R1.  */
      regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
                                      amode | (from + insnlen));
      /* Update PC iff the instruction doesn't actually branch.  */
      if (insn[0] == op_basr && r2 == 0)
        regcache_write_pc (regs, from + insnlen);
    }
...

Fix this by storing the result of the call, and using it instead of
'insn[0] ==op_basr'.

Build on x86_64-linux with --enable-targets=s390-suse-linux,s390x-suse-linux.

gdb/ChangeLog:

2020-07-29  Tom de Vries  <tdevries@suse.de>

PR tdep/26280
* s390-tdep.c (s390_displaced_step_fixup): Fix Wmaybe-uninitialized.

gdb/ChangeLog
gdb/s390-tdep.c

index 9a9161561fdeeeea46022eb73209e05a21011582..4d4d62e302a33903bee745d916af02b0b7737bf9 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-29  Tom de Vries  <tdevries@suse.de>
+
+       PR tdep/26280
+       * s390-tdep.c (s390_displaced_step_fixup): Fix Wmaybe-uninitialized.
+
 2020-07-28  Tom Tromey  <tromey@adacore.com>
 
        PR symtab/26270:
index 0ee7a37256301ecf5b3a92da907984d82b00675f..65cb23705d26241999e9b539de3f986413e9c7cf 100644 (file)
@@ -518,14 +518,15 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch,
                        paddress (gdbarch, pc), insnlen, (int) amode);
 
   /* Handle absolute branch and save instructions.  */
-  if (is_rr (insn, op_basr, &r1, &r2)
+  int op_basr_p = is_rr (insn, op_basr, &r1, &r2);
+  if (op_basr_p
       || is_rx (insn, op_bas, &r1, &d2, &x2, &b2))
     {
       /* Recompute saved return address in R1.  */
       regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
                                      amode | (from + insnlen));
       /* Update PC iff the instruction doesn't actually branch.  */
-      if (insn[0] == op_basr && r2 == 0)
+      if (op_basr_p && r2 == 0)
        regcache_write_pc (regs, from + insnlen);
     }