@@ -969,6 +969,7 @@ static void warn_undef_insn(struct instruction *insn, int warn)
if (is_pseudo_value(insn->src2, 0)) {
if (warn && Wdiv_by_zero)
warning(insn->pos, "division by zero");
+ insn->warned = 1;
}
break;
default:
@@ -404,6 +404,15 @@ static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long val
return 0;
}
+static void check_divide_by_zero(struct instruction *insn, long long value)
+{
+ if (value != 0 || insn->warned)
+ return;
+ if (Wdiv_by_zero)
+ warning(insn->pos, "division by zero");
+ insn->warned = 1;
+}
+
static int simplify_mul_div(struct instruction *insn, long long value)
{
unsigned long long sbit = 1ULL << (insn->size - 1);
@@ -525,9 +534,12 @@ static int simplify_constant_rightside(struct instruction *insn)
case OP_MODU: case OP_MODS:
if (value == 1)
return replace_with_pseudo(insn, value_pseudo(0));
+ check_divide_by_zero(insn, value);
return 0;
case OP_DIVU: case OP_DIVS:
+ check_divide_by_zero(insn, value);
+ /* Fall through */
case OP_MULU: case OP_MULS:
return simplify_mul_div(insn, value);
@@ -49,7 +49,9 @@ div-by-zero.c:18:30: warning: division by zero
div-by-zero.c:19:30: warning: division by zero
div-by-zero.c:21:42: warning: division by zero
div-by-zero.c:22:33: warning: division by zero
+div-by-zero.c:23:38: warning: division by zero
div-by-zero.c:25:42: warning: division by zero
div-by-zero.c:26:33: warning: division by zero
+div-by-zero.c:27:38: warning: division by zero
* check-error-end
*/
sparse now warn about divion by zero during linearization but during simplification some expression can become constants and so some new divisions by zero can appears. Warn also on those new and to avoid to warn also here on the old ones, mark the instructions for wich we have already be warned. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- linearize.c | 1 + simplify.c | 12 ++++++++++++ validation/div-by-zero.c | 2 ++ 3 files changed, 15 insertions(+)