Commit dcf0b4c9 authored by John Zhang's avatar John Zhang

fix: the logic of block exit analysis has changed, mu_ccall is not explicitly…

fix: the logic of block exit analysis has changed, mu_ccall is not explicitly identified and dealt with, thus it is possible now to cast pointer to correct type after mu_ccall(malloc). This should also fix issue#75 on Zebu issue tracker
parent f1e717b6
Pipeline #872 canceled with stage
......@@ -1239,17 +1239,15 @@ class LL2MuMapper:
# correct memcpy and memmove argument order
if mufnp._name in ('memcpy', 'memmove'):
args = [args[1], args[0], args[2]]
# NOTE: assume implicit casting to avoid
# adding extra operations at the end of a block
# which messes with block exit analysis
# if Sig.RESULTS[0] != llop.result.concretetype:
# malloc_res = varof(Sig.RESULTS[0])
# muops.append(self.gen_mu_ccall(callee, args, malloc_res))
# llop_fc = SpaceOperation('force_cast', [malloc_res], llop.result)
# muops += self.map_op(llop_fc)
# else:
# muops.append(self.gen_mu_ccall(callee, args, llop.result))
muops.append(self.gen_mu_ccall(callee, args, llop.result))
if llop.opname == 'raw_malloc':
if Sig.RESULTS[0] != llop.result.concretetype:
malloc_res = varof(Sig.RESULTS[0])
muops.append(self.gen_mu_ccall(callee, args, malloc_res))
llop_fc = SpaceOperation('force_cast', [malloc_res], llop.result)
muops += self.map_op(llop_fc)
else:
muops.append(self.gen_mu_ccall(callee, args, llop.result))
return muops
map_op_raw_malloc = _map_rawmemop
......
......@@ -343,3 +343,20 @@ def test_NULL_const():
arg = g.startblock.operations[0].args[0].value.args[0]
assert isinstance(arg, Constant)
assert arg.value._is_null()
def test_malloc_castptr():
POINT = lltype.Struct('Point', ('x', lltype.Signed), ('y', lltype.Signed))
def f():
p = lltype.malloc(POINT, flavor='raw', track_allocation=False)
p.x = 10
p.y = 10
return p
t = Translation(f, [], backend='mu')
t.mutype()
g = graph_of(f, t)
ops = g.startblock.operations
assert ops[1].opname == 'mu_convop' and ops[1].args[0].value == 'PTRCAST'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment