def test_simplify_dead_assign_1(): # if a register is used ever, it should not be simplified away arch = archinfo.arch_from_id('AMD64') block = ailment.Block(0x1337, 10) n = count(start=1) important = 0x999 block.statements.extend([ ailment.Assignment( next(n), ailment.Register(next(n), None, arch.registers['rdi'][0], 64), ailment.Const(next(n), None, 0x13371337, 64), ins_addr=0x1337, ), # rdi = 0x13371337 ailment.Stmt.Call( important, ailment.Const(next(n), None, 0x400080, 64), ins_addr=0x1338, ), # Call(0x400080), which uses rdi but also overwrites rdi (since it is a caller-saved argument) ]) b = block_simplify(block) nose.tools.assert_equal(len(b.statements), 2) nose.tools.assert_equal(b.statements[0].idx, 1) nose.tools.assert_equal(b.statements[1].idx, important)
def test_simplify_dead_assign_0(): block = ailment.Block(0x1337, 10) n = count() important = 0x999 block.statements.extend( [ ailment.Assignment( next(n), ailment.Register(next(n), None, 1, 64), ailment.Const(next(n), None, 100, 64), ins_addr=0x1337, ), ailment.Assignment( important, ailment.Register(next(n), None, 1, 64), ailment.Const(next(n), None, 101, 64), ins_addr=0x1338, ), ailment.Stmt.Jump( next(n), ailment.Expr.Const(None, None, 0x3333, 64), ins_addr=0x1338 ), ] ) b = block_simplify(block) nose.tools.assert_equal(len(b.statements), 2) nose.tools.assert_equal(b.statements[0].idx, important)