Skip to content

Commit

Permalink
workaround for #997
Browse files Browse the repository at this point in the history
SMT's (div 0 0) == 0xffff, which is annoying
Usually it doesn't matter because we make it UB when divisor=0
But with undef, things get complicated when undef vars are not quantified.
We could fix this properly with either some quantifiers or by wrapping around div
But that's expensive, so we const fold (div 0 x) -> 0 only.
  • Loading branch information
nunoplopes committed Dec 26, 2023
1 parent d1dfabb commit 93b947e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions smt/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ expr expr::sdiv(const expr &rhs) const {
if (rhs.isZero())
return rhs;

if (isZero())
return *this;

if (isSMin() && rhs.isAllOnes())
return mkUInt(0, sort());

Expand All @@ -741,6 +744,9 @@ expr expr::udiv(const expr &rhs) const {
if (rhs.isZero())
return rhs;

if (isZero())
return *this;

return binop_fold(rhs, Z3_mk_bvudiv);
}

Expand Down

0 comments on commit 93b947e

Please sign in to comment.