The following patch tries to address some missing overflow checks. It fixes the example of -1 -0x7fffffff and _maybe_ others. Some of the checks might not be necessary, though.
arne
diff --git a/src/peep.in b/src/peep.in index c311069..bdc03ba 100644 --- a/src/peep.in +++ b/src/peep.in @@ -39,8 +39,8 @@ CONST1 NEGATE : CONST_1 CONST_1 NEGATE : CONST1 NUMBER NEGATE : NEG_NUMBER($1a) NEG_NUMBER NEGATE : NUMBER ($1a) -NUMBER [(-$1a) > 0] : NEG_NUMBER (-$1a) -NEG_NUMBER [(-$1a) >= 0] : NUMBER (-$1a) +NUMBER [ !INT32_NEG_OVERFLOW($1a) && (-$1a) > 0] : NEG_NUMBER (-$1a) +NEG_NUMBER [ !INT32_NEG_OVERFLOW($1a) && (-$1a) >= 0] : NUMBER (-$1a) NEGATE NEGATE : COMPL COMPL : NEGATE CONST_1 ADD_INTS : COMPL @@ -277,7 +277,7 @@ CONST_1 INDEX: NEG_INT_INDEX (1) CONST1 INDEX: POS_INT_INDEX (1) NUMBER INDEX: POS_INT_INDEX ($1a) NEG_NUMBER INDEX: NEG_INT_INDEX ($1a) -POS_INT_INDEX [$1a < 0]: NEG_INT_INDEX (-$1a) +POS_INT_INDEX [$1a < 0 && !INT32_NEG_OVERFLOW($1a) ]: NEG_INT_INDEX (-$1a) NEG_INT_INDEX [-$1a >= 0]: POS_INT_INDEX (-$1a)
BRANCH_WHEN_ZERO BRANCH LABEL ($1a): BRANCH_WHEN_NON_ZERO($2a) LABEL($1a) @@ -365,15 +365,15 @@ LOCAL VOLATILE_RETURN : RETURN_LOCAL($1a)
NUMBER ADD_INT [ !INT32_ADD_OVERFLOW($1a, $2a) ] : NUMBER($1a+$2a) NUMBER ADD_NEG_INT [ !INT32_SUB_OVERFLOW($1a, $2a) ]: NUMBER($1a-$2a) -NEG_NUMBER ADD_INT [ !INT32_ADD_OVERFLOW(-$1a, $2a) ]: NUMBER(-$1a+$2a) -NEG_NUMBER ADD_NEG_INT [ !INT32_SUB_OVERFLOW(-$1a, $2a) ]: NUMBER(-$1a-$2a) +NEG_NUMBER ADD_INT [ !INT32_SUB_OVERFLOW($2a, $1a) ]: NUMBER($2a-$1a) +NEG_NUMBER ADD_NEG_INT [ !INT32_NEG_OVERFLOW($1a) && !INT32_SUB_OVERFLOW(-$1a, $2a) ]: NUMBER(-$1a-$2a)
CONST0 ADD_INT : NUMBER($2a) CONST0 ADD_NEG_INT : NEG_NUMBER($2a) CONST1 ADD_INT [($2a+1) > 0] : NUMBER($2a+1) -CONST1 ADD_NEG_INT : NEG_NUMBER($2a-1) -CONST_1 ADD_INT : NUMBER($2a-1) -CONST_1 ADD_NEG_INT [($2a+1) > 0] : NEG_NUMBER($2a+1) +CONST1 ADD_NEG_INT [ !INT32_SUB_OVERFLOW($2a, 1) ] : NEG_NUMBER($2a-1) +CONST_1 ADD_INT [ !INT32_SUB_OVERFLOW($2a, 1) ] : NUMBER($2a-1) +CONST_1 ADD_NEG_INT [ !INT32_ADD_OVERFLOW($2a, 1) && ($2a+1) > 0] : NEG_NUMBER($2a+1) CONST0 LOCAL ADD_INTS : LOCAL($2a) CONST0 LOCAL NEGATE ADD_INTS : LOCAL($2a) NEGATE CONST0 GLOBAL ADD_INTS : GLOBAL($2a)