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).
This commit is contained in:
@@ -1227,7 +1227,7 @@ static void asm_arithov(ASMState *as, IRIns *ir)
|
||||
Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);
|
||||
if (irref_isk(ir->op2)) {
|
||||
int k = IR(ir->op2)->i;
|
||||
if (ir->o == IR_SUBOV) k = -k;
|
||||
if (ir->o == IR_SUBOV) k = (int)(~(unsigned int)k+1u);
|
||||
if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */
|
||||
left = ra_alloc1(as, ir->op1, RSET_GPR);
|
||||
asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
|
||||
|
||||
Reference in New Issue
Block a user