Skip to contentSkip to conversation

cris: avoid write only variables

PATCH Superseded Blue Swirl 3 participants 5 messages Oct 6, 2010 – Oct 7, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

PATCH 7/11 cris: avoid write only variables

Compiling with GCC 4.6.0 20100925 produced warnings:
/src/qemu/target-cris/op_helper.c: In function 'helper_movl_sreg_reg':
/src/qemu/target-cris/op_helper.c:145:8: error: variable 'tlb_v' set but not used [-Werror=unused-but-set-variable]
In file included from /src/qemu/target-cris/translate.c:3154:0:
/src/qemu/target-cris/translate_v10.c: In function 'dec10_prep_move_m':
/src/qemu/target-cris/translate_v10.c:111:22: error: variable 'rd' set but not used [-Werror=unused-but-set-variable]

Fix by making the variable declarations and their uses also conditional to debug definition, delete rd.

---
 target-cris/op_helper.c     |    6 ++++++
 target-cris/translate_v10.c |    5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)
target-cris/op_helper.c +6 -0
index a60da94..28c79b1 100644
@@ -142,7 +142,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			uint32_t idx;
 			uint32_t lo, hi;
 			uint32_t vaddr;
+#ifdef CRIS_OP_HELPER_DEBUG
 			int tlb_v;
+#endif
 
 			idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
 			set >>= 4;
@@ -157,13 +159,17 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
 					      13, 31);
 			vaddr <<= TARGET_PAGE_BITS;
+#ifdef CRIS_OP_HELPER_DEBUG
 			tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
 					    3, 3);
+#endif
 			env->tlbsets[srs - 1][set][idx].lo = lo;
 			env->tlbsets[srs - 1][set][idx].hi = hi;
 
+#ifdef CRIS_OP_HELPER_DEBUG
 			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
 				  vaddr, tlb_v, env->pc);
+#endif
 			tlb_flush_page(env, vaddr);
 		}
 	}
target-cris/translate_v10.c +0 -0
index 14e590d..6944827 100644
@@ -108,16 +108,15 @@ static unsigned int

crisv10_post_memaddr(DisasContext *dc, unsigned int size)
static int dec10_prep_move_m(DisasContext *dc, int s_ext, int memsize,
TCGv dst)
{
- unsigned int rs, rd;

+    unsigned int rs;
     uint32_t imm;
     int is_imm;
     int insn_len = 0;

     rs = dc->src;
-    rd = dc->dst;
     is_imm = rs == 15 && !(dc->tb_flags & PFIX_FLAG);
     LOG_DIS("rs=%d rd=%d is_imm=%d mode=%d pfix=%d\n",

- rs, rd, is_imm, dc->mode, dc->tb_flags & PFIX_FLAG);
+ rs, dc->dst, is_imm, dc->mode, dc->tb_flags & PFIX_FLAG);

     /* Load [$rs] onto T1.  */
     if (is_imm) {
Signature · 1 line
1.6.2.4
#1 lore raw
Quoted 40 lines · Blue Swirl

Compiling with GCC 4.6.0 20100925 produced warnings:
/src/qemu/target-cris/op_helper.c: In function 'helper_movl_sreg_reg':
/src/qemu/target-cris/op_helper.c:145:8: error: variable 'tlb_v' set but not used [-Werror=unused-but-set-variable]
In file included from /src/qemu/target-cris/translate.c:3154:0:
/src/qemu/target-cris/translate_v10.c: In function 'dec10_prep_move_m':
/src/qemu/target-cris/translate_v10.c:111:22: error: variable 'rd' set but not used [-Werror=unused-but-set-variable]

Fix by making the variable declarations and their uses also conditional to debug definition, delete rd.

---
 target-cris/op_helper.c     |    6 ++++++
 target-cris/translate_v10.c |    5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)
target-cris/op_helper.c +4 -0
index a60da94..28c79b1 100644
@@ -142,7 +142,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			uint32_t idx;
 			uint32_t lo, hi;
 			uint32_t vaddr;
+#ifdef CRIS_OP_HELPER_DEBUG
 			int tlb_v;
+#endif
 
 			idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
 			set >>= 4;
@@ -157,13 +159,17 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
 					      13, 31);
 			vaddr <<= TARGET_PAGE_BITS;
+#ifdef CRIS_OP_HELPER_DEBUG
 			tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
 					    3, 3);
+#endif

target-cris/op_helper.c void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg) · line 175

Quoted 10 lines
target-cris/op_helper.c +2 -0
 			env->tlbsets[srs - 1][set][idx].lo = lo;
 			env->tlbsets[srs - 1][set][idx].hi = hi;
 
+#ifdef CRIS_OP_HELPER_DEBUG
 			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
 				  vaddr, tlb_v, env->pc);
+#endif
 			tlb_flush_page(env, vaddr);
 		}
 	}

Could we eliminate the bothersome variable instead?

target-cris/op_helper.c +4 -4
index a60da94..94e3e27 100644
@@ -142,7 +142,6 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			uint32_t idx;
 			uint32_t lo, hi;
 			uint32_t vaddr;
-			int tlb_v;
 
 			idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
 			set >>= 4;
@@ -157,13 +156,14 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
 					      13, 31);
 			vaddr <<= TARGET_PAGE_BITS;
-			tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
+			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n", 
+                              vaddr,
+                              EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
 					    3, 3);
+                              env->pc);
 			env->tlbsets[srs - 1][set][idx].lo = lo;
 			env->tlbsets[srs - 1][set][idx].hi = hi;
 
-			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n", 
-				  vaddr, tlb_v, env->pc);
 			tlb_flush_page(env, vaddr);
 		}
 	}

Untested.

[...]

#2 lore raw
Quoted 75 lines · Markus Armbruster
Quoted 40 lines · Blue Swirl

Compiling with GCC 4.6.0 20100925 produced warnings:
/src/qemu/target-cris/op_helper.c: In function 'helper_movl_sreg_reg':
/src/qemu/target-cris/op_helper.c:145:8: error: variable 'tlb_v' set but not used [-Werror=unused-but-set-variable]
In file included from /src/qemu/target-cris/translate.c:3154:0:
/src/qemu/target-cris/translate_v10.c: In function 'dec10_prep_move_m':
/src/qemu/target-cris/translate_v10.c:111:22: error: variable 'rd' set but not used [-Werror=unused-but-set-variable]

Fix by making the variable declarations and their uses also conditional to debug definition, delete rd.

---
 target-cris/op_helper.c     |    6 ++++++
 target-cris/translate_v10.c |    5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)
target-cris/op_helper.c +4 -0
index a60da94..28c79b1 100644
@@ -142,7 +142,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			uint32_t idx;
 			uint32_t lo, hi;
 			uint32_t vaddr;
+#ifdef CRIS_OP_HELPER_DEBUG
 			int tlb_v;
+#endif
 
 			idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
 			set >>= 4;
@@ -157,13 +159,17 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
 					      13, 31);
 			vaddr <<= TARGET_PAGE_BITS;
+#ifdef CRIS_OP_HELPER_DEBUG
 			tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
 					    3, 3);
+#endif

target-cris/op_helper.c void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg) · line 175

Quoted 10 lines
target-cris/op_helper.c +2 -0
 			env->tlbsets[srs - 1][set][idx].lo = lo;
 			env->tlbsets[srs - 1][set][idx].hi = hi;
 
+#ifdef CRIS_OP_HELPER_DEBUG
 			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
 				  vaddr, tlb_v, env->pc);
+#endif
 			tlb_flush_page(env, vaddr);
 		}
 	}

Could we eliminate the bothersome variable instead?

target-cris/op_helper.c +3 -2
index a60da94..94e3e27 100644
@@ -142,7 +142,6 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			uint32_t idx;
 			uint32_t lo, hi;
 			uint32_t vaddr;
-			int tlb_v;
 
 			idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
 			set >>= 4;
@@ -157,13 +156,14 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 			vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
 					      13, 31);
 			vaddr <<= TARGET_PAGE_BITS;
-			tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
+			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n", 
+                              vaddr,
+                              EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,

target-cris/op_helper.c void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg) · line 169

Quoted 10 lines
target-cris/op_helper.c +1 -2
 					    3, 3);
+                              env->pc);
 			env->tlbsets[srs - 1][set][idx].lo = lo;
 			env->tlbsets[srs - 1][set][idx].hi = hi;
 
-			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n", 
-				  vaddr, tlb_v, env->pc);
 			tlb_flush_page(env, vaddr);
 		}
 	}

Hi,

Sorry for the late answer.

Markus, I agree that removing tlb_v would have been better than ifdefs, but i think that the intent I originally had in mind was that there should not be a need to flush the entry from the QEMU TLB if the old guest entry was not valid.

The following patch works on my side:

target-cris/op_helper.c +3 -1
index a60da94..be9eb06 100644
@@ -164,7 +164,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 
 			D_LOG("tlb flush vaddr=%x v=%d pc=%x\n", 
 				  vaddr, tlb_v, env->pc);
-			tlb_flush_page(env, vaddr);
+			if (tlb_v) {
+				tlb_flush_page(env, vaddr);
+			}
 		}
 	}
 #endif

The target-cris/translate_v10.c hunk looks good.

Blue, can you incorporate the tlb_v change in your patch set? Or if you prefer, I can commit that part on my side.

Cheers

author
#3 lore raw
Quoted 89 lines · Edgar E. Iglesias
Quoted 75 lines · Markus Armbruster
Quoted 40 lines · Blue Swirl

Compiling with GCC 4.6.0 20100925 produced warnings:
/src/qemu/target-cris/op_helper.c: In function 'helper_movl_sreg_reg':
/src/qemu/target-cris/op_helper.c:145:8: error: variable 'tlb_v' set but not used [-Werror=unused-but-set-variable]
In file included from /src/qemu/target-cris/translate.c:3154:0:
/src/qemu/target-cris/translate_v10.c: In function 'dec10_prep_move_m':
/src/qemu/target-cris/translate_v10.c:111:22: error: variable 'rd' set but not used [-Werror=unused-but-set-variable]

Fix by making the variable declarations and their uses also conditional to debug definition, delete rd.

---
 target-cris/op_helper.c     |    6 ++++++
 target-cris/translate_v10.c |    5 ++---

 2 files changed, 8 insertions(+), 3 deletions(-)
target-cris/op_helper.c +4 -0
index a60da94..28c79b1 100644
@@ -142,7 +142,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
                     uint32_t idx;
                     uint32_t lo, hi;
                     uint32_t vaddr;
+#ifdef CRIS_OP_HELPER_DEBUG
                     int tlb_v;
+#endif
 
                     idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
                     set >>= 4;
@@ -157,13 +159,17 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
                     vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
                                           13, 31);
                     vaddr <<= TARGET_PAGE_BITS;
+#ifdef CRIS_OP_HELPER_DEBUG
                     tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
                                         3, 3);
+#endif

target-cris/op_helper.c void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg) · line 175

Quoted 10 lines
target-cris/op_helper.c +2 -0
                     env->tlbsets[srs - 1][set][idx].lo = lo;
                     env->tlbsets[srs - 1][set][idx].hi = hi;
 
+#ifdef CRIS_OP_HELPER_DEBUG
                     D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
                               vaddr, tlb_v, env->pc);
+#endif
                     tlb_flush_page(env, vaddr);
             }
     }

Could we eliminate the bothersome variable instead?

target-cris/op_helper.c +3 -2
index a60da94..94e3e27 100644
@@ -142,7 +142,6 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
                       uint32_t idx;
                       uint32_t lo, hi;
                       uint32_t vaddr;
-                     int tlb_v;
 
                       idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
                       set >>= 4;
@@ -157,13 +156,14 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
                       vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
                                             13, 31);
                       vaddr <<= TARGET_PAGE_BITS;
-                     tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
+                     D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
+                              vaddr,
+                              EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,

target-cris/op_helper.c void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg) · line 169

Quoted 10 lines
target-cris/op_helper.c +1 -2
                                           3, 3);
+                              env->pc);
                       env->tlbsets[srs - 1][set][idx].lo = lo;
                       env->tlbsets[srs - 1][set][idx].hi = hi;
 
-                     D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
-                               vaddr, tlb_v, env->pc);
                       tlb_flush_page(env, vaddr);
               }
       }

Hi,

Quoted 1 line

Sorry for the late answer.

Late? I think my timescale is slightly different than yours :-)

Quoted 25 lines

Markus, I agree that removing tlb_v would have been better than ifdefs, but i think that the intent I originally had in mind was that there should not be a need to flush the entry from the QEMU TLB if the old guest entry was not valid.

The following patch works on my side:

target-cris/op_helper.c +3 -1
index a60da94..be9eb06 100644
@@ -164,7 +164,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 
                        D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
                                  vaddr, tlb_v, env->pc);
-                       tlb_flush_page(env, vaddr);
+                       if (tlb_v) {
+                               tlb_flush_page(env, vaddr);
+                       }
                }
        }
  #endif
Quoted 4 lines

The target-cris/translate_v10.c hunk looks good.

Blue, can you incorporate the tlb_v change in your patch set? Or if you prefer, I can commit that part on my side.

Please do.

#4 lore raw
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Edgar E. Iglesias
Quoted 3 lines · Markus Armbruster
Quoted 1 line · Blue Swirl

Compiling with GCC 4.6.0 20100925 produced warnings:

[...]

Quoted 25 lines
Quoted 25 lines

Markus, I agree that removing tlb_v would have been better than ifdefs, but i think that the intent I originally had in mind was that there should not be a need to flush the entry from the QEMU TLB if the old guest entry was not valid.

The following patch works on my side:

target-cris/op_helper.c +3 -1
index a60da94..be9eb06 100644
@@ -164,7 +164,9 @@ void helper_movl_sreg_reg (uint32_t sreg, uint32_t reg)
 
                        D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
                                  vaddr, tlb_v, env->pc);
-                       tlb_flush_page(env, vaddr);
+                       if (tlb_v) {
+                               tlb_flush_page(env, vaddr);
+                       }
                }
        }
  #endif
Quoted 6 lines
Quoted 4 lines

The target-cris/translate_v10.c hunk looks good.

Blue, can you incorporate the tlb_v change in your patch set? Or if you prefer, I can commit that part on my side.

Please do.

OK, done.

Thanks