diff options
| -rw-r--r-- | miasm2/expression/simplifications_common.py | 7 | ||||
| -rw-r--r-- | test/expression/simplifications.py | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/miasm2/expression/simplifications_common.py b/miasm2/expression/simplifications_common.py index 208870eb..58cabaf4 100644 --- a/miasm2/expression/simplifications_common.py +++ b/miasm2/expression/simplifications_common.py @@ -92,9 +92,14 @@ def simp_cst_propagation(e_s, e): if op == '-' and len(args) == 1 and isinstance(args[0], ExprInt): return ExprInt(-args[0].arg) # A op 0 =>A - if op in ['+', '-', '|', "^", "<<", ">>", "<<<", ">>>"] and len(args) > 1: + if op in ['+', '|', "^", "<<", ">>", "<<<", ">>>"] and len(args) > 1: if isinstance(args[-1], ExprInt) and args[-1].arg == 0: args.pop() + # A - 0 =>A + if op == '-' and len(args) > 1 and args[-1].arg == 0: + assert(len(args) == 2) # Op '-' with more than 2 args: SantityCheckError + return args[0] + # A * 1 =>A if op == "*" and len(args) > 1: if isinstance(args[-1], ExprInt) and args[-1].arg == 1: diff --git a/test/expression/simplifications.py b/test/expression/simplifications.py index 6b437218..0f217c72 100644 --- a/test/expression/simplifications.py +++ b/test/expression/simplifications.py @@ -155,6 +155,8 @@ to_test = [(ExprInt32(1) - ExprInt32(1), ExprInt32(0)), (a & b & ExprInt_fromsize(a.size, -1), a & b), (a | b | ExprInt_fromsize(a.size, -1), ExprInt_fromsize(a.size, -1)), + (ExprOp('-', ExprInt8(1), ExprInt8(0)), + ExprInt8(1)), ] for e, e_check in to_test[:]: |