Skip to contentSkip to conversation

(few more) Steps towards enabling -Wshadow

PATCH Superseded Philippe Mathieu-Daudé 6 participants 23 messages Aug 31, 2023 – Sep 4, 2023

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover (few more) Steps towards enabling -Wshadow

For rational see Markus cover on
https://lore.kernel.org/qemu-devel/[email protected]/

This series contains few more, my take.

Based-on: <[email protected]>

Philippe Mathieu-Daudé (11):
tcg: Clean up local variable shadowing target/arm: Clean up local variable shadowing target/mips: Clean up local variable shadowing target/m68k: Clean up local variable shadowing hw/arm/virt: Clean up local variable shadowing hw/arm/allwinner: Clean up local variable shadowing hw/arm/aspeed: Clean up local variable shadowing hw/m68k: Clean up local variable shadowing hw/ide/ahci: Clean up local variable shadowing net/eth: Clean up local variable shadowing sysemu/device_tree: Clean up local variable shadowing

 hw/m68k/bootinfo.h                       | 10 ++++------
 include/sysemu/device_tree.h             |  6 ++----
 accel/tcg/tb-maint.c                     |  3 +--
 hw/arm/allwinner-r40.c                   |  7 +++----
 hw/arm/aspeed_ast2600.c                  |  2 +-
 hw/arm/virt.c                            |  3 +--
 hw/ide/ahci.c                            |  6 ++----
 net/eth.c                                |  2 +-
 target/arm/hvf/hvf.c                     |  1 -
 target/arm/tcg/mve_helper.c              |  8 ++++----
 target/arm/tcg/translate-m-nocp.c        |  2 +-
 target/m68k/translate.c                  |  2 +-
 target/mips/tcg/msa_helper.c             |  8 ++++----
 target/mips/tcg/translate.c              |  8 +++-----
 tcg/tcg.c                                | 16 ++++++++--------
 target/mips/tcg/nanomips_translate.c.inc |  6 +++---
 16 files changed, 39 insertions(+), 51 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/11 tcg: Clean up local variable shadowing

Fix:

tcg/tcg.c:2551:27: error: declaration shadows a local variable [-Werror,-Wshadow]

                    MemOp op = get_memop(oi);
                          ^
  tcg/tcg.c:2437:12: note: previous declaration is here
    TCGOp *op;
           ^
  accel/tcg/tb-maint.c:245:18: error: declaration shadows a local variable [-Werror,-Wshadow]
        for (int i = 0; i < V_L2_SIZE; i++) {
                 ^
  accel/tcg/tb-maint.c:210:9: note: previous declaration is here
    int i;
        ^
---
 accel/tcg/tb-maint.c |  3 +--
 tcg/tcg.c            | 16 ++++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
accel/tcg/tb-maint.c +1 -2
index c406b2f7b7..f1cf3ad736 100644
@@ -207,13 +207,12 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, bool alloc)
 {
     PageDesc *pd;
     void **lp;
-    int i;
 
     /* Level 1.  Always allocated.  */
     lp = l1_map + ((index >> v_l1_shift) & (v_l1_size - 1));
 
     /* Level 2..N-1.  */
-    for (i = v_l2_levels; i > 0; i--) {
+    for (int i = v_l2_levels; i > 0; i--) {
         void **p = qatomic_rcu_read(lp);
 
         if (p == NULL) {
tcg/tcg.c +8 -8
index 620dbe08da..46a3a231b8 100644
@@ -2548,21 +2548,21 @@ static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs)
                 {
                     const char *s_al, *s_op, *s_at;
                     MemOpIdx oi = op->args[k++];
-                    MemOp op = get_memop(oi);
+                    MemOp o = get_memop(oi);
                     unsigned ix = get_mmuidx(oi);
 
-                    s_al = alignment_name[(op & MO_AMASK) >> MO_ASHIFT];
-                    s_op = ldst_name[op & (MO_BSWAP | MO_SSIZE)];
-                    s_at = atom_name[(op & MO_ATOM_MASK) >> MO_ATOM_SHIFT];
-                    op &= ~(MO_AMASK | MO_BSWAP | MO_SSIZE | MO_ATOM_MASK);
+                    s_al = alignment_name[(o & MO_AMASK) >> MO_ASHIFT];
+                    s_op = ldst_name[o & (MO_BSWAP | MO_SSIZE)];
+                    s_at = atom_name[(o & MO_ATOM_MASK) >> MO_ATOM_SHIFT];
+                    o &= ~(MO_AMASK | MO_BSWAP | MO_SSIZE | MO_ATOM_MASK);
 
                     /* If all fields are accounted for, print symbolically. */
-                    if (!op && s_al && s_op && s_at) {
+                    if (!o && s_al && s_op && s_at) {
                         col += ne_fprintf(f, ",%s%s%s,%u",
                                           s_at, s_al, s_op, ix);
                     } else {
-                        op = get_memop(oi);
-                        col += ne_fprintf(f, ",$0x%x,%u", op, ix);
+                        o = get_memop(oi);
+                        col += ne_fprintf(f, ",$0x%x,%u", o, ix);
                     }
                     i = 1;
                 }
Signature · 1 line
2.41.0
Reviewed-by on v1 1/11
#2 lore raw

Re: [PATCH 01/11] tcg: Clean up local variable shadowing

tcg/tcg.c static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs) · line 2551

Quoted 2 lines · Philippe Mathieu-Daudé
tcg/tcg.c +1 -1
-                    MemOp op = get_memop(oi);
+                    MemOp o = get_memop(oi);

mop would be a more descriptive replacement.

Otherwise,

r~

#3 lore raw

Re: [PATCH 01/11] tcg: Clean up local variable shadowing

Quoted 5 lines · Richard Henderson
Quoted 2 lines · Philippe Mathieu-Daudé

-                    MemOp op = get_memop(oi);
+                    MemOp o = get_memop(oi);

mop would be a more descriptive replacement.

I went with that first, but then noticed 'MemOpIdx oi' and renamed as 'o'. Anyway I'll change to 'mop', thanks!

Quoted 6 lines

Otherwise,

r~

#4 lore raw

PATCH 2/11 target/arm: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

target/arm/tcg/translate-m-nocp.c:509:18: error: declaration shadows a local variable [-Werror,-Wshadow]

        TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
                 ^
  target/arm/tcg/translate-m-nocp.c:433:14: note: previous declaration is here
    TCGv_i32 tmp;
             ^
  target/arm/tcg/mve_helper.c:2463:17: error: declaration shadows a local variable [-Werror,-Wshadow]
        int64_t extval = sextract64(src << shift, 0, 48);
                ^
  target/arm/tcg/mve_helper.c:2443:18: note: previous declaration is here
    int64_t val, extval;
                 ^
  target/arm/hvf/hvf.c:1936:13: error: declaration shadows a local variable [-Werror,-Wshadow]
        int ret = 0;
            ^
  target/arm/hvf/hvf.c:1807:9: note: previous declaration is here
    int ret;
        ^
---
 target/arm/hvf/hvf.c              | 1 -
 target/arm/tcg/mve_helper.c       | 8 ++++----
 target/arm/tcg/translate-m-nocp.c | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)
target/arm/hvf/hvf.c +0 -1
index 486f90be1d..20d534faef 100644
@@ -1933,7 +1933,6 @@ int hvf_vcpu_exec(CPUState *cpu)
         uint32_t rt = (syndrome >> 5) & 0x1f;
         uint32_t reg = syndrome & SYSREG_MASK;
         uint64_t val;
-        int ret = 0;
 
         if (isread) {
             ret = hvf_sysreg_read(cpu, reg, rt);
target/arm/tcg/mve_helper.c +4 -4
index 403b345ea3..32087b6f0a 100644
@@ -924,8 +924,8 @@ DO_1OP_IMM(vorri, DO_ORRI)
         bool qc = false;                                                \
         for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) {              \
             bool sat = false;                                           \
-            TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);          \
-            mergemask(&d[H##ESIZE(e)], r, mask);                        \
+            TYPE r_ = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);         \
+            mergemask(&d[H##ESIZE(e)], r_, mask);                       \
             qc |= sat & mask & 1;                                       \
         }                                                               \
         if (qc) {                                                       \
@@ -2460,7 +2460,7 @@ static inline int64_t do_sqrshl48_d(int64_t src, int64_t shift,
             return extval;
         }
     } else if (shift < 48) {
-        int64_t extval = sextract64(src << shift, 0, 48);
+        extval = sextract64(src << shift, 0, 48);
         if (!sat || src == (extval >> shift)) {
             return extval;
         }
@@ -2492,7 +2492,7 @@ static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift,
             return extval;
         }
     } else if (shift < 48) {
-        uint64_t extval = extract64(src << shift, 0, 48);
+        extval = extract64(src << shift, 0, 48);
         if (!sat || src == (extval >> shift)) {
             return extval;
         }
target/arm/tcg/translate-m-nocp.c +1 -1
index 33f6478bb9..42308c4db5 100644
@@ -506,7 +506,7 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
 
         gen_branch_fpInactive(s, TCG_COND_EQ, lab_active);
         /* fpInactive case: reads as FPDSCR_NS */
-        TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
+        tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
         storefn(s, opaque, tmp, true);
         lab_end = gen_new_label();
         tcg_gen_br(lab_end);
Signature · 1 line
2.41.0
#5 lore raw

Re: [PATCH 02/11] target/arm: Clean up local variable shadowing

Quoted 34 lines · Philippe Mathieu-Daudé

Fix:

target/arm/tcg/translate-m-nocp.c:509:18: error: declaration shadows a local variable [-Werror,-Wshadow]

        TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
                 ^
  target/arm/tcg/translate-m-nocp.c:433:14: note: previous declaration is here
    TCGv_i32 tmp;
             ^
  target/arm/tcg/mve_helper.c:2463:17: error: declaration shadows a local variable [-Werror,-Wshadow]
        int64_t extval = sextract64(src << shift, 0, 48);
                ^
  target/arm/tcg/mve_helper.c:2443:18: note: previous declaration is here
    int64_t val, extval;
                 ^
  target/arm/hvf/hvf.c:1936:13: error: declaration shadows a local variable [-Werror,-Wshadow]
        int ret = 0;
            ^
  target/arm/hvf/hvf.c:1807:9: note: previous declaration is here
    int ret;
        ^
---
 target/arm/hvf/hvf.c              | 1 -
 target/arm/tcg/mve_helper.c       | 8 ++++----
 target/arm/tcg/translate-m-nocp.c | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)
target/arm/hvf/hvf.c +0 -0
index 486f90be1d..20d534faef 100644

target/arm/hvf/hvf.c int hvf_vcpu_exec(CPUState *cpu) · line 1938

Quoted 7 lines
target/arm/hvf/hvf.c +0 -1
@@ -1933,7 +1933,6 @@ int hvf_vcpu_exec(CPUState *cpu)
         uint32_t rt = (syndrome >> 5) & 0x1f;
         uint32_t reg = syndrome & SYSREG_MASK;
         uint64_t val;
-        int ret = 0;
 
         if (isread) {
             ret = hvf_sysreg_read(cpu, reg, rt);

I'm not sure this is correct.

The hvf_vcpu_exec() function is not documented, but in practice its caller expects it to return either EXCP_DEBUG (for "this was a guest debug exception you need to deal with") or something else (presumably the intention being 0 for OK).

The hvf_sysreg_read() and hvf_sysreg_write() functions are also not documented, but they return 0 on success, or 1 for a completely unrecognized sysreg where we've raised the UNDEF exception (but not if we raised an UNDEF exception for an unrecognized GIC sysreg -- I think this is a bug). We use this return value to decide whether we need to advance the PC past the insn or not. It's not the same as the return value we want to return from hvf_vcpu_exec().

So I think the correct fix here is to retain the variable as locally scoped but give it a name that doesn't clash with the other function-scoped variable.

Quoted 5 lines
target/arm/tcg/mve_helper.c +0 -0
index 403b345ea3..32087b6f0a 100644

target/arm/tcg/mve_helper.c DO_1OP_IMM(vorri, DO_ORRI) · line 931

Quoted 10 lines
target/arm/tcg/mve_helper.c +2 -2
@@ -924,8 +924,8 @@ DO_1OP_IMM(vorri, DO_ORRI)
         bool qc = false;                                                \
         for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) {              \
             bool sat = false;                                           \
-            TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);          \
-            mergemask(&d[H##ESIZE(e)], r, mask);                        \
+            TYPE r_ = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);         \
+            mergemask(&d[H##ESIZE(e)], r_, mask);                       \
             qc |= sat & mask & 1;                                       \
         }                                                               \
         if (qc) {                                                       \

The commit message doesn't list an error message relating to this change and it's not immediately obvious to me what 'r' would be shadowing here.

Quoted 10 lines
target/arm/tcg/mve_helper.c +1 -1
@@ -2460,7 +2460,7 @@ static inline int64_t do_sqrshl48_d(int64_t src, int64_t shift,
             return extval;
         }
     } else if (shift < 48) {
-        int64_t extval = sextract64(src << shift, 0, 48);
+        extval = sextract64(src << shift, 0, 48);
         if (!sat || src == (extval >> shift)) {
             return extval;
         }

target/arm/tcg/mve_helper.c static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift, · line 2498

Quoted 8 lines
target/arm/tcg/mve_helper.c +1 -1
@@ -2492,7 +2492,7 @@ static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift,
             return extval;
         }
     } else if (shift < 48) {
-        uint64_t extval = extract64(src << shift, 0, 48);
+        extval = extract64(src << shift, 0, 48);
         if (!sat || src == (extval >> shift)) {
             return extval;
         }

These two parts are good, but one of them is missing from the listed error messages in the commit message.

target/arm/tcg/translate-m-nocp.c static bool gen_M_fp_sysreg_read(DisasContext *s, int regno, · line 512

Quoted 13 lines
target/arm/tcg/translate-m-nocp.c +1 -1
index 33f6478bb9..42308c4db5 100644
@@ -506,7 +506,7 @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
 
         gen_branch_fpInactive(s, TCG_COND_EQ, lab_active);
         /* fpInactive case: reads as FPDSCR_NS */
-        TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
+        tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
         storefn(s, opaque, tmp, true);
         lab_end = gen_new_label();
         tcg_gen_br(lab_end);

This one's right too.

thanks
-- PMM

#6 lore raw

Re: [PATCH 02/11] target/arm: Clean up local variable shadowing

Quoted 50 lines · Peter Maydell
Quoted 34 lines · Philippe Mathieu-Daudé

Fix:

   target/arm/tcg/translate-m-nocp.c:509:18: error: declaration shadows a local variable [-Werror,-Wshadow]
         TCGv_i32 tmp = load_cpu_field(v7m.fpdscr[M_REG_NS]);
                  ^
   target/arm/tcg/translate-m-nocp.c:433:14: note: previous declaration is here
     TCGv_i32 tmp;
              ^
   target/arm/tcg/mve_helper.c:2463:17: error: declaration shadows a local variable [-Werror,-Wshadow]
         int64_t extval = sextract64(src << shift, 0, 48);
                 ^
   target/arm/tcg/mve_helper.c:2443:18: note: previous declaration is here
     int64_t val, extval;
                  ^
   target/arm/hvf/hvf.c:1936:13: error: declaration shadows a local variable [-Werror,-Wshadow]
         int ret = 0;
             ^
   target/arm/hvf/hvf.c:1807:9: note: previous declaration is here
     int ret;
         ^
---
  target/arm/hvf/hvf.c              | 1 -
  target/arm/tcg/mve_helper.c       | 8 ++++----
  target/arm/tcg/translate-m-nocp.c | 2 +-
  3 files changed, 5 insertions(+), 6 deletions(-)
target/arm/hvf/hvf.c +0 -0
index 486f90be1d..20d534faef 100644

target/arm/hvf/hvf.c int hvf_vcpu_exec(CPUState *cpu) · line 1938

Quoted 7 lines
target/arm/hvf/hvf.c +0 -1
@@ -1933,7 +1933,6 @@ int hvf_vcpu_exec(CPUState *cpu)
          uint32_t rt = (syndrome >> 5) & 0x1f;
          uint32_t reg = syndrome & SYSREG_MASK;
          uint64_t val;
-        int ret = 0;
 
          if (isread) {
              ret = hvf_sysreg_read(cpu, reg, rt);

I'm not sure this is correct.

The hvf_vcpu_exec() function is not documented, but in practice its caller expects it to return either EXCP_DEBUG (for "this was a guest debug exception you need to deal with") or something else (presumably the intention being 0 for OK).

Quoted 7 lines

The hvf_sysreg_read() and hvf_sysreg_write() functions are also not documented, but they return 0 on success, or 1 for a completely unrecognized sysreg where we've raised the UNDEF exception (but not if we raised an UNDEF exception for an unrecognized GIC sysreg -- I think this is a bug). We use this return value to decide whether we need to advance the PC past the insn or not. It's not the same as the return value we want to return from hvf_vcpu_exec().

Indeed.

Quoted 3 lines

So I think the correct fix here is to retain the variable as locally scoped but give it a name that doesn't clash with the other function-scoped variable.

OK.

Quoted 11 lines
Quoted 11 lines
target/arm/tcg/mve_helper.c +1 -2
index 403b345ea3..32087b6f0a 100644
@@ -924,8 +924,8 @@ DO_1OP_IMM(vorri, DO_ORRI)
          bool qc = false;                                                \
          for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) {              \
              bool sat = false;                                           \
-            TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);          \
-            mergemask(&d[H##ESIZE(e)], r, mask);                        \
+            TYPE r_ = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat);         \
Quoted 8 lines

target/arm/tcg/mve_helper.c DO_1OP_IMM(vorri, DO_ORRI) · line 931

Quoted 4 lines
target/arm/tcg/mve_helper.c +1 -0
+            mergemask(&d[H##ESIZE(e)], r_, mask);                       \
              qc |= sat & mask & 1;                                       \
          }                                                               \
          if (qc) {                                                       \

The commit message doesn't list an error message relating to this change and it's not immediately obvious to me what 'r' would be shadowing here.

Full error:

target/arm/tcg/mve_helper.c: In function ‘helper_mve_vqshlsb’:
target/arm/tcg/mve_helper.c:1259:19: warning: declaration of ‘r’ shadows a previous local [-Wshadow=compatible-local]
1259 | typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND,
&su32); \
| ^
target/arm/tcg/mve_helper.c:1267:5: note: in expansion of macro ‘WRAP_QRSHL_HELPER’

 1267 |     WRAP_QRSHL_HELPER(do_sqrshl_bhs, N, M, false, satp)
      |     ^~~~~~~~~~~~~~~~~
target/arm/tcg/mve_helper.c:927:22: note: in expansion of macro ‘DO_SQSHL_OP’
  927 |             TYPE r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], &sat); 
        \
      |                      ^~
target/arm/tcg/mve_helper.c:945:5: note: in expansion of macro ‘DO_2OP_SAT’
  945 |     DO_2OP_SAT(OP##b, 1, int8_t, FN)            \
      |     ^~~~~~~~~~
target/arm/tcg/mve_helper.c:1277:1: note: in expansion of macro ‘DO_2OP_SAT_S’
 1277 | DO_2OP_SAT_S(vqshls, DO_SQSHL_OP)
      | ^~~~~~~~~~~~

So 'r' comes from:

#define WRAP_QRSHL_HELPER(FN, N, M, ROUND, satp) \
    ({                                           \
        uint32_t su32 = 0;                       \
        typeof(N) r = FN(N, (int8_t)(M), sizeof(N) * 8, ROUND, &su32); \
        if (su32) {                              \
            *satp = true;                        \
        }                                        \
        r;                                       \
    })

I'll rename this one as 'qrshl_ret', and the previous one 'vqdmladh_ret'.

Quoted 13 lines
Quoted 13 lines
target/arm/tcg/mve_helper.c +1 -1
@@ -2460,7 +2460,7 @@ static inline int64_t do_sqrshl48_d(int64_t src, int64_t shift,
              return extval;
          }
      } else if (shift < 48) {
-        int64_t extval = sextract64(src << shift, 0, 48);
+        extval = sextract64(src << shift, 0, 48);
          if (!sat || src == (extval >> shift)) {
              return extval;
          }
@@ -2492,7 +2492,7 @@ static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift,
              return extval;
          }
      } else if (shift < 48) {
Quoted 8 lines

target/arm/tcg/mve_helper.c static inline uint64_t do_uqrshl48_d(uint64_t src, int64_t shift, · line 2498

Quoted 5 lines
target/arm/tcg/mve_helper.c +1 -1
-        uint64_t extval = extract64(src << shift, 0, 48);
+        extval = extract64(src << shift, 0, 48);
          if (!sat || src == (extval >> shift)) {
              return extval;
          }

These two parts are good, but one of them is missing from the listed error messages in the commit message.

I'll record both.

Thanks,

Phil.

#7 lore raw

PATCH 3/11 target/mips: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

target/mips/tcg/nanomips_translate.c.inc:4410:33: error: declaration shadows a local variable [-Werror,-Wshadow]

                        int32_t imm = extract32(ctx->opcode, 1, 13) |
                                ^
  target/mips/tcg/nanomips_translate.c.inc:3577:9: note: previous declaration is here
    int imm;
        ^
  target/mips/tcg/translate.c:15578:19: error: declaration shadows a local variable [-Werror,-Wshadow]
    for (unsigned i = 1; i < 32; i++) {
                  ^
  target/mips/tcg/translate.c:15567:9: note: previous declaration is here
    int i;
        ^
  target/mips/tcg/msa_helper.c:7478:13: error: declaration shadows a local variable [-Werror,-Wshadow]
            MSA_FLOAT_MAXOP(pwx->w[0], min, pws->w[0], pws->w[0], 32);
            ^
  target/mips/tcg/msa_helper.c:7434:23: note: expanded from macro 'MSA_FLOAT_MAXOP'
        float_status *status = &env->active_tc.msa_fp_status;
                      ^
---
 target/mips/tcg/msa_helper.c             | 8 ++++----
 target/mips/tcg/translate.c              | 8 +++-----
 target/mips/tcg/nanomips_translate.c.inc | 6 +++---
 3 files changed, 10 insertions(+), 12 deletions(-)
target/mips/tcg/msa_helper.c +4 -4
index 29b31d70fe..391a5fca26 100644
@@ -7431,15 +7431,15 @@ void helper_msa_ftq_df(CPUMIPSState *env, uint32_t df, uint32_t wd,
 
 #define MSA_FLOAT_MAXOP(DEST, OP, ARG1, ARG2, BITS)                         \
     do {                                                                    \
-        float_status *status = &env->active_tc.msa_fp_status;               \
+        float_status *status_ = &env->active_tc.msa_fp_status;              \
         int c;                                                              \
                                                                             \
-        set_float_exception_flags(0, status);                               \
-        DEST = float ## BITS ## _ ## OP(ARG1, ARG2, status);                \
+        set_float_exception_flags(0, status_);                              \
+        DEST = float ## BITS ## _ ## OP(ARG1, ARG2, status_);               \
         c = update_msacsr(env, 0, 0);                                       \
                                                                             \
         if (get_enabled_exceptions(env, c)) {                               \
-            DEST = ((FLOAT_SNAN ## BITS(status) >> 6) << 6) | c;            \
+            DEST = ((FLOAT_SNAN ## BITS(status_) >> 6) << 6) | c;           \
         }                                                                   \
     } while (0)
 
target/mips/tcg/translate.c +3 -5
index 9bb40f1849..26d741d960 100644
@@ -15564,10 +15564,8 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns,
 
 void mips_tcg_init(void)
 {
-    int i;
-
     cpu_gpr[0] = NULL;
-    for (i = 1; i < 32; i++)
+    for (unsigned i = 1; i < 32; i++)
         cpu_gpr[i] = tcg_global_mem_new(cpu_env,
                                         offsetof(CPUMIPSState,
                                                  active_tc.gpr[i]),
@@ -15584,7 +15582,7 @@ void mips_tcg_init(void)
                                                rname);
     }
 #endif /* !TARGET_MIPS64 */
-    for (i = 0; i < 32; i++) {
+    for (unsigned i = 0; i < 32; i++) {
         int off = offsetof(CPUMIPSState, active_fpu.fpr[i].wr.d[0]);
 
         fpu_f64[i] = tcg_global_mem_new_i64(cpu_env, off, fregnames[i]);
@@ -15592,7 +15590,7 @@ void mips_tcg_init(void)
     msa_translate_init();
     cpu_PC = tcg_global_mem_new(cpu_env,
                                 offsetof(CPUMIPSState, active_tc.PC), "PC");
-    for (i = 0; i < MIPS_DSP_ACC; i++) {
+    for (unsigned i = 0; i < MIPS_DSP_ACC; i++) {
         cpu_HI[i] = tcg_global_mem_new(cpu_env,
                                        offsetof(CPUMIPSState, active_tc.HI[i]),
                                        regnames_HI[i]);
target/mips/tcg/nanomips_translate.c.inc +3 -3
index a98dde0d2e..d81a7c2d11 100644
@@ -4407,8 +4407,8 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
                 case NM_BPOSGE32C:
                     check_dsp_r3(ctx);
                     {
-                        int32_t imm = extract32(ctx->opcode, 1, 13) |
-                                      extract32(ctx->opcode, 0, 1) << 13;
+                        imm = extract32(ctx->opcode, 1, 13)
+                            | extract32(ctx->opcode, 0, 1) << 13;
 
                         gen_compute_branch_nm(ctx, OPC_BPOSGE32, 4, -1, -2,
                                               imm << 1);
@@ -4635,7 +4635,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx)
         break;
     case NM_LI16:
         {
-            int imm = extract32(ctx->opcode, 0, 7);
+            imm = extract32(ctx->opcode, 0, 7);
             imm = (imm == 0x7f ? -1 : imm);
             if (rt != 0) {
                 tcg_gen_movi_tl(cpu_gpr[rt], imm);
Signature · 1 line
2.41.0
#8 lore raw

PATCH 4/11 target/m68k: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

target/m68k/translate.c:828:18: error: declaration shadows a local variable [-Werror,-Wshadow]

            TCGv tmp = tcg_temp_new();
                 ^
  target/m68k/translate.c:801:15: note: previous declaration is here
    TCGv reg, tmp, result;
              ^
---
 target/m68k/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/m68k/translate.c +1 -1
index 15b3701b8f..f69ae0e3b0 100644
@@ -825,7 +825,7 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0,
         reg = get_areg(s, reg0);
         result = gen_ldst(s, opsize, reg, val, what, index);
         if (what == EA_STORE || !addrp) {
-            TCGv tmp = tcg_temp_new();
+            tmp = tcg_temp_new();
             if (reg0 == 7 && opsize == OS_BYTE &&
                 m68k_feature(s->env, M68K_FEATURE_M68K)) {
                 tcg_gen_addi_i32(tmp, reg, 2);
Signature · 1 line
2.41.0
Reviewed-by on v1 4/11
#9 lore raw

Re: [PATCH 04/11] target/m68k: Clean up local variable shadowing

Quoted 10 lines · Philippe Mathieu-Daudé

Fix:

target/m68k/translate.c:828:18: error: declaration shadows a local variable [-Werror,-Wshadow]

            TCGv tmp = tcg_temp_new();
                 ^
  target/m68k/translate.c:801:15: note: previous declaration is here
    TCGv reg, tmp, result;
              ^
Quoted 3 lines
---
 target/m68k/translate.c | 2 +-

thanks
-- PMM

#10 lore raw

PATCH 5/11 hw/arm/virt: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

hw/arm/virt.c:821:22: error: declaration shadows a local variable [-Werror,-Wshadow]

            qemu_irq irq = qdev_get_gpio_in(vms->gic,
                     ^
  hw/arm/virt.c:803:13: note: previous declaration is here
        int irq;
            ^
---
 hw/arm/virt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/arm/virt.c +1 -2
index a13c658bbf..32a964b572 100644
@@ -800,7 +800,6 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
     for (i = 0; i < smp_cpus; i++) {
         DeviceState *cpudev = DEVICE(qemu_get_cpu(i));
         int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS;
-        int irq;
         /* Mapping from the output timer irq lines from the CPU to the
          * GIC PPI inputs we use for the virt board.
          */
@@ -811,7 +810,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
             [GTIMER_SEC]  = ARCH_TIMER_S_EL1_IRQ,
         };
 
-        for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
+        for (unsigned irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
             qdev_connect_gpio_out(cpudev, irq,
                                   qdev_get_gpio_in(vms->gic,
                                                    ppibase + timer_irq[irq]));
Signature · 1 line
2.41.0
Reviewed-by on v1 5/11
#11 lore raw

Re: [PATCH 05/11] hw/arm/virt: Clean up local variable shadowing

Quoted 4 lines · Philippe Mathieu-Daudé

Fix:

hw/arm/virt.c:821:22: error: declaration shadows a local variable [-Werror,-Wshadow]

Quoted 8 lines
            qemu_irq irq = qdev_get_gpio_in(vms->gic,
                     ^
  hw/arm/virt.c:803:13: note: previous declaration is here
        int irq;
            ^

---

thanks
-- PMM

#12 lore raw

PATCH 6/11 hw/arm/allwinner: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

hw/arm/allwinner-r40.c:412:14: error: declaration shadows a local variable [-Werror,-Wshadow]

    for (int i = 0; i < AW_R40_NUM_MMCS; i++) {
             ^
  hw/arm/allwinner-r40.c:299:14: note: previous declaration is here
    unsigned i;
             ^
---
 hw/arm/allwinner-r40.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/allwinner-r40.c +3 -4
index 7d29eb224f..a0d367c60d 100644
@@ -296,10 +296,9 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
 {
     const char *r40_nic_models[] = { "gmac", "emac", NULL };
     AwR40State *s = AW_R40(dev);
-    unsigned i;
 
     /* CPUs */
-    for (i = 0; i < AW_R40_NUM_CPUS; i++) {
+    for (unsigned i = 0; i < AW_R40_NUM_CPUS; i++) {
 
         /*
          * Disable secondary CPUs. Guest EL3 firmware will start
@@ -335,7 +334,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
      * maintenance interrupt signal to the appropriate GIC PPI inputs,
      * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
      */
-    for (i = 0; i < AW_R40_NUM_CPUS; i++) {
+    for (unsigned i = 0; i < AW_R40_NUM_CPUS; i++) {
         DeviceState *cpudev = DEVICE(&s->cpus[i]);
         int ppibase = AW_R40_GIC_NUM_SPI + i * GIC_INTERNAL + GIC_NR_SGIS;
         int irq;
@@ -494,7 +493,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_EMAC));
 
     /* Unimplemented devices */
-    for (i = 0; i < ARRAY_SIZE(r40_unimplemented); i++) {
+    for (unsigned i = 0; i < ARRAY_SIZE(r40_unimplemented); i++) {
         create_unimplemented_device(r40_unimplemented[i].device_name,
                                     r40_unimplemented[i].base,
                                     r40_unimplemented[i].size);
Signature · 1 line
2.41.0
Reviewed-by on v1 6/11
#13 lore raw

Re: [PATCH 06/11] hw/arm/allwinner: Clean up local variable shadowing

Quoted 4 lines · Philippe Mathieu-Daudé

Fix:

hw/arm/allwinner-r40.c:412:14: error: declaration shadows a local variable [-Werror,-Wshadow]

Quoted 8 lines
    for (int i = 0; i < AW_R40_NUM_MMCS; i++) {
             ^
  hw/arm/allwinner-r40.c:299:14: note: previous declaration is here
    unsigned i;
             ^

---

thanks
-- PMM

#14 lore raw

PATCH 7/11 hw/arm/aspeed: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

hw/arm/aspeed_ast2600.c:391:18: error: declaration shadows a local variable [-Werror,-Wshadow]

        qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
                 ^
  hw/arm/aspeed_ast2600.c:283:14: note: previous declaration is here
    qemu_irq irq;
             ^
  hw/arm/aspeed_ast2600.c:416:18: error: declaration shadows a local variable [-Werror,-Wshadow]
        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
                 ^
  hw/arm/aspeed_ast2600.c:283:14: note: previous declaration is here
    qemu_irq irq;
             ^
---
 hw/arm/aspeed_ast2600.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/aspeed_ast2600.c +1 -1
index a8b3a8065a..f54063445d 100644
@@ -280,7 +280,6 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     AspeedSoCState *s = ASPEED_SOC(dev);
     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
     Error *err = NULL;
-    qemu_irq irq;
     g_autofree char *sram_name = NULL;
 
     /* Default boot region (SPI memory or ROMs) */
@@ -339,6 +338,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     for (i = 0; i < sc->num_cpus; i++) {
         SysBusDevice *sbd = SYS_BUS_DEVICE(&s->a7mpcore);
         DeviceState  *d   = DEVICE(&s->cpu[i]);
+        qemu_irq irq;
 
         irq = qdev_get_gpio_in(d, ARM_CPU_IRQ);
         sysbus_connect_irq(sbd, i, irq);
Signature · 1 line
2.41.0
Reviewed-by on v1 7/11
#15 lore raw

Re: [PATCH 07/11] hw/arm/aspeed: Clean up local variable shadowing

Quoted 15 lines · Philippe Mathieu-Daudé

Fix:

   hw/arm/aspeed_ast2600.c:391:18: error: declaration shadows a local variable [-Werror,-Wshadow]
         qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
                  ^
   hw/arm/aspeed_ast2600.c:283:14: note: previous declaration is here
     qemu_irq irq;
              ^
   hw/arm/aspeed_ast2600.c:416:18: error: declaration shadows a local variable [-Werror,-Wshadow]
         qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
                  ^
   hw/arm/aspeed_ast2600.c:283:14: note: previous declaration is here
     qemu_irq irq;
              ^
Quoted 1 line

Thanks,

C.

Quoted 24 lines
---
  hw/arm/aspeed_ast2600.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/aspeed_ast2600.c +1 -1
index a8b3a8065a..f54063445d 100644
@@ -280,7 +280,6 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
      AspeedSoCState *s = ASPEED_SOC(dev);
      AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
      Error *err = NULL;
-    qemu_irq irq;
      g_autofree char *sram_name = NULL;
 
      /* Default boot region (SPI memory or ROMs) */
@@ -339,6 +338,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
      for (i = 0; i < sc->num_cpus; i++) {
          SysBusDevice *sbd = SYS_BUS_DEVICE(&s->a7mpcore);
          DeviceState  *d   = DEVICE(&s->cpu[i]);
+        qemu_irq irq;
 
          irq = qdev_get_gpio_in(d, ARM_CPU_IRQ);
          sysbus_connect_irq(sbd, i, irq);
#16 lore raw

PATCH 8/11 hw/m68k: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

hw/m68k/virt.c:263:13: error: declaration shadows a local variable [-Werror,-Wshadow]

            BOOTINFOSTR(param_ptr, BI_COMMAND_LINE,
            ^
  hw/m68k/bootinfo.h:47:13: note: expanded from macro 'BOOTINFOSTR'
        int i; \
            ^
  hw/m68k/virt.c:130:9: note: previous declaration is here
    int i;
        ^
---
 hw/m68k/bootinfo.h | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
hw/m68k/bootinfo.h +4 -6
index a3d37e3c80..0e6e3eea87 100644
@@ -44,15 +44,14 @@
 
 #define BOOTINFOSTR(base, id, string) \
     do { \
-        int i; \
         stw_p(base, id); \
         base += 2; \
         stw_p(base, \
                  (sizeof(struct bi_record) + strlen(string) + \
                   1 /* null termination */ + 3 /* padding */) & ~3); \
         base += 2; \
-        for (i = 0; string[i]; i++) { \
-            stb_p(base++, string[i]); \
+        for (unsigned i_ = 0; string[i_]; i_++) { \
+            stb_p(base++, string[i_]); \
         } \
         stb_p(base++, 0); \
         base = QEMU_ALIGN_PTR_UP(base, 4); \
@@ -60,7 +59,6 @@
 
 #define BOOTINFODATA(base, id, data, len) \
     do { \
-        int i; \
         stw_p(base, id); \
         base += 2; \
         stw_p(base, \
@@ -69,8 +67,8 @@
         base += 2; \
         stw_p(base, len); \
         base += 2; \
-        for (i = 0; i < len; ++i) { \
-            stb_p(base++, data[i]); \
+        for (unsigned i_ = 0; i_ < len; ++i_) { \
+            stb_p(base++, data[i_]); \
         } \
         base = QEMU_ALIGN_PTR_UP(base, 4); \
     } while (0)
Signature · 1 line
2.41.0
#17 lore raw

PATCH 9/11 hw/ide/ahci: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

hw/ide/ahci.c:1577:23: error: declaration shadows a local variable [-Werror,-Wshadow]

            IDEState *s = &ad->port.ifs[j];
                      ^

hw/ide/ahci.c:1569:29: note: previous declaration is here
void ahci_uninit(AHCIState *s)
^

---
 hw/ide/ahci.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/ide/ahci.c +2 -4
index 48d550f633..8c9a7c2117 100644
@@ -1573,10 +1573,8 @@ void ahci_uninit(AHCIState *s)
     for (i = 0; i < s->ports; i++) {
         AHCIDevice *ad = &s->dev[i];
 
-        for (j = 0; j < 2; j++) {
-            IDEState *s = &ad->port.ifs[j];
-
-            ide_exit(s);
+        for (j = 0; j < ARRAY_SIZE(ad->port.ifs); j++) {
+            ide_exit(&ad->port.ifs[j]);
         }
         object_unparent(OBJECT(&ad->port));
     }
Signature · 1 line
2.41.0
#18 lore raw

PATCH 10/11 net/eth: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

net/eth.c:435:20: error: declaration shadows a local variable [-Werror,-Wshadow]

            size_t input_size = iov_size(pkt, pkt_frags);
                   ^
  net/eth.c:413:16: note: previous declaration is here
        size_t input_size = iov_size(pkt, pkt_frags);
               ^
---
 net/eth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/eth.c +1 -1
index 649e66bb1f..cf030eed7b 100644
@@ -432,7 +432,7 @@ _eth_get_rss_ex_src_addr(const struct iovec *pkt, int pkt_frags,
         }
 
         if (opthdr.type == IP6_OPT_HOME) {
-            size_t input_size = iov_size(pkt, pkt_frags);
+            input_size = iov_size(pkt, pkt_frags);
 
             if (input_size < opt_offset + sizeof(opthdr)) {
                 return false;
Signature · 1 line
2.41.0
#19 lore raw

Re: [PATCH 10/11] net/eth: Clean up local variable shadowing

Quoted 19 lines · Philippe Mathieu-Daudé

Fix:

   net/eth.c:435:20: error: declaration shadows a local variable [-Werror,-Wshadow]
             size_t input_size = iov_size(pkt, pkt_frags);
                    ^
   net/eth.c:413:16: note: previous declaration is here
         size_t input_size = iov_size(pkt, pkt_frags);
                ^
---
  net/eth.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/eth.c +0 -0
index 649e66bb1f..cf030eed7b 100644

net/eth.c _eth_get_rss_ex_src_addr(const struct iovec *pkt, int pkt_frags, · line 435

Quoted 5 lines
net/eth.c +1 -1
@@ -432,7 +432,7 @@ _eth_get_rss_ex_src_addr(const struct iovec *pkt, int pkt_frags,
          }
 
          if (opthdr.type == IP6_OPT_HOME) {
-            size_t input_size = iov_size(pkt, pkt_frags);
+            input_size = iov_size(pkt, pkt_frags);

You can just remove this statement.

Quoted 3 lines
net/eth.c +0 -0
              if (input_size < opt_offset + sizeof(opthdr)) {
                  return false;
#20 lore raw

Re: [PATCH 10/11] net/eth: Clean up local variable shadowing

Quoted 15 lines · Akihiko Odaki
Quoted 14 lines · Philippe Mathieu-Daudé

Fix:

   net/eth.c:435:20: error: declaration shadows a local variable [-Werror,-Wshadow] size_t input_size = iov_size(pkt, pkt_frags);
                    ^
   net/eth.c:413:16: note: previous declaration is here
         size_t input_size = iov_size(pkt, pkt_frags);
                ^

---
  net/eth.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

net/eth.c _eth_get_rss_ex_src_addr(const struct iovec *pkt, · line 435

Quoted 10 lines
net/eth.c +1 -1
index 649e66bb1f..cf030eed7b 100644
@@ -432,7 +432,7 @@ _eth_get_rss_ex_src_addr(const struct iovec *pkt, 
 int pkt_frags,
           }
           if (opthdr.type == IP6_OPT_HOME) {
-            size_t input_size = iov_size(pkt, pkt_frags);
+            input_size = iov_size(pkt, pkt_frags);

You can just remove this statement.

Clever eh, thanks!

#21 lore raw

PATCH 11/11 sysemu/device_tree: Clean up local variable shadowing

In reply to Philippe Mathieu-Daudé

Fix:

hw/mips/boston.c:472:5: error: declaration shadows a local variable [-Werror,-Wshadow]

    qemu_fdt_setprop_cells(fdt, name, "reg", reg_base, reg_size);
    ^
  include/sysemu/device_tree.h:129:13: note: expanded from macro 'qemu_fdt_setprop_cells'
        int i;
            ^
  hw/mips/boston.c:461:9: note: previous declaration is here
    int i;
        ^
---
 include/sysemu/device_tree.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
include/sysemu/device_tree.h +2 -4
index ca5339beae..8eab395934 100644
@@ -126,10 +126,8 @@ int qemu_fdt_add_path(void *fdt, const char *path);
 #define qemu_fdt_setprop_cells(fdt, node_path, property, ...)                 \
     do {                                                                      \
         uint32_t qdt_tmp[] = { __VA_ARGS__ };                                 \
-        int i;                                                                \
-                                                                              \
-        for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) {                           \
-            qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]);                             \
+        for (unsigned i_ = 0; i_ < ARRAY_SIZE(qdt_tmp); i_++) {               \
+            qdt_tmp[i_] = cpu_to_be32(qdt_tmp[i_]);                           \
         }                                                                     \
         qemu_fdt_setprop(fdt, node_path, property, qdt_tmp,                   \
                          sizeof(qdt_tmp));                                    \
Signature · 1 line
2.41.0