Skip to content

Commit

Permalink
Unsigned div constant folding simplification (#1530)
Browse files Browse the repository at this point in the history
* Unsigned div constant folding simp

* blkn

* Precalculate unsign mask
  • Loading branch information
feliam committed Oct 2, 2019
1 parent 1ec9032 commit 5e5f5bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manticore/core/smtlib/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import operator

logger = logging.getLogger(__name__)
UNSIGN_MASK = (1 << 256) - 1


class Visitor:
Expand Down Expand Up @@ -281,6 +282,7 @@ def __init__(self, **kw):
BoolAnd: operator.__and__,
BoolOr: operator.__or__,
BoolNot: operator.__not__,
BitVecUnsignedDiv: lambda x, y: (x & UNSIGN_MASK) // (y & UNSIGN_MASK),
}

def visit_BitVecConcat(self, expression, *operands):
Expand Down
8 changes: 8 additions & 0 deletions tests/other/test_smtlibv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ def test_arithmetic_simplify_extract(self):
)
self.assertEqual(translate_to_smtlib(simplify(c)), "((_ extract 23 8) VARA)")

def test_constant_folding_udiv(self):
cs = ConstraintSet()
x = BitVecConstant(32, 0xFFFFFFFF, taint=("important",))
y = BitVecConstant(32, 2, taint=("stuff",))
z = constant_folder(x.udiv(y))
self.assertItemsEqual(z.taint, ("important", "stuff"))
self.assertEqual(z.value, 0x7FFFFFFF)

def testBasicReplace(self):
""" Add """
a = BitVecConstant(32, 100)
Expand Down

0 comments on commit 5e5f5bd

Please sign in to comment.