target-mips: Fix warning about shifting negative value
PATCH 1/1 target-mips: Fix warning about shifting negative value
With latest clang you get the following warning:
warning: shifting a negative signed value is undefined [-Wshift-negative-value]
Fix the warning by changing negative shift to inverse 0 shift.
--- target-mips/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target-mips/translate.c +5 -5
@@ -3282,7 +3282,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt) {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );
@@ -3298,7 +3298,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt) {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );
@@ -3444,7 +3444,7 @@ static void gen_muldiv(DisasContext *ctx, uint32_t opc, {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );
@@ -3791,7 +3791,7 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,tcg_gen_movi_tl (cpu_gpr[rd],0 );tcg_gen_br (l3);gen_set_label (l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); +tcg_gen_brcondi_tl (TCG_COND_NE , t0, ~0ULL <<63 , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);tcg_gen_mov_tl (cpu_gpr[rd], t0);tcg_gen_br (l3);
@@ -3820,7 +3820,7 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,TCGLabel *l2 =gen_new_label ();TCGLabel *l3 =gen_new_label ();tcg_gen_brcondi_tl (TCG_COND_EQ , t1,0 , l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); +tcg_gen_brcondi_tl (TCG_COND_NE , t0, ~0ULL <<63 , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);gen_set_label (l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );
Signature · 1 line
2.9.2
Quoted 53 lines · Pranith Kumar
With latest clang you get the following warning:
warning: shifting a negative signed value is undefined [-Wshift-negative-value]
Fix the warning by changing negative shift to inverse 0 shift.
Signed-off-by Pranith Kumar <[email protected]>--- target-mips/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)target-mips/translate.c +4
-4@@ -3282,7 +3282,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt) {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );@@ -3298,7 +3298,7 @@ static void gen_r6_muldiv(DisasContext *ctx, int opc, int rd, int rs, int rt) {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );@@ -3444,7 +3444,7 @@ static void gen_muldiv(DisasContext *ctx, uint32_t opc, {TCGv t2 =tcg_temp_new ();TCGv t3 =tcg_temp_new (); -tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0,-1LL <<63 ); +tcg_gen_setcondi_tl (TCG_COND_EQ , t2, t0, ~0ULL <<63 );tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,-1LL );tcg_gen_and_tl (t2, t2, t3);tcg_gen_setcondi_tl (TCG_COND_EQ , t3, t1,0 );@@ -3791,7 +3791,7 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,tcg_gen_movi_tl (cpu_gpr[rd],0 );tcg_gen_br (l3);gen_set_label (l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); +tcg_gen_brcondi_tl (TCG_COND_NE , t0, ~0ULL <<63 , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);tcg_gen_mov_tl (cpu_gpr[rd], t0);tcg_gen_br (l3);
target-mips/translate.c static void gen_loongson_integer(DisasContext *ctx, uint32_t opc, · line 3826
Quoted 8 lines
target-mips/translate.c +1
-1@@ -3820,7 +3820,7 @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc,TCGLabel *l2 =gen_new_label ();TCGLabel *l3 =gen_new_label ();tcg_gen_brcondi_tl (TCG_COND_EQ , t1,0 , l1); -tcg_gen_brcondi_tl (TCG_COND_NE , t0,-1LL <<63 , l2); +tcg_gen_brcondi_tl (TCG_COND_NE , t0, ~0ULL <<63 , l2);tcg_gen_brcondi_tl (TCG_COND_NE , t1,-1LL , l2);gen_set_label (l1);tcg_gen_movi_tl (cpu_gpr[rd],0 );
No, please no.
clang is wrong in putting this under -Wall.
Paolo
Hi Paolo,
Quoted 5 lines · Paolo Bonzini
Quoted 2 lines · Pranith Kumar
With latest clang you get the following warning:
Quoted 9 lines
Quoted 4 lines
warning: shifting a negative signed value is undefined [-Wshift-negative-value]
Fix the warning by changing negative shift to inverse 0 shift.
No, please no.
clang is wrong in putting this under -Wall.
Can you please explain why this warning is spurious? Isn't this what the standard says?
Thanks,
Signature · 1 line
Pranith
Quoted 13 lines · Pranith Kumar
Hi Paolo,
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Pranith Kumar
With latest clang you get the following warning:
warning: shifting a negative signed value is undefined [-Wshift-negative-value]
Fix the warning by changing negative shift to inverse 0 shift.
Quoted 7 lines
Quoted 4 lines
No, please no.
clang is wrong in putting this under -Wall.
Can you please explain why this warning is spurious? Isn't this what the standard says?
Yes, but GCC promises to never exploit this kind of undefined behavior.
Furthermore (though it's not the case for this patch) it's easy to get this "fix" wrong. For example if you change -1 << 3 to -1u << 3, and then the value is extended to 64-bit, the results will be different.
Paolo