diff options
author | Mike Pall <mike> | 2022-12-22 00:03:06 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2022-12-22 00:03:06 +0100 |
commit | 8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b (patch) | |
tree | dae089564f58db2963bae8e3530c1faae104cc61 /src/lj_asm_mips.h | |
parent | b2791179ef96d652d00d78d2a8780af690537f6a (diff) | |
download | luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.tar.gz luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.tar.bz2 luajit-8a5e398c52c7f8ca3e1a0e574cc2ba38224b759b.zip |
Avoid negation of signed integers in C that may hold INT*_MIN.
Reported by minoki.
Recent C compilers 'take advantage' of the undefined behavior.
This completely changes the meaning of expressions like (k == -k).
Diffstat (limited to 'src/lj_asm_mips.h')
-rw-r--r-- | src/lj_asm_mips.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h index c0e491a6..1d4c8a25 100644 --- a/src/lj_asm_mips.h +++ b/src/lj_asm_mips.h | |||
@@ -1227,7 +1227,7 @@ static void asm_arithov(ASMState *as, IRIns *ir) | |||
1227 | Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR); | 1227 | Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR); |
1228 | if (irref_isk(ir->op2)) { | 1228 | if (irref_isk(ir->op2)) { |
1229 | int k = IR(ir->op2)->i; | 1229 | int k = IR(ir->op2)->i; |
1230 | if (ir->o == IR_SUBOV) k = -k; | 1230 | if (ir->o == IR_SUBOV) k = (int)(~(unsigned int)k+1u); |
1231 | if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */ | 1231 | if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */ |
1232 | left = ra_alloc1(as, ir->op1, RSET_GPR); | 1232 | left = ra_alloc1(as, ir->op1, RSET_GPR); |
1233 | asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); | 1233 | asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO); |