Commit 5c40d36e authored by John Zhang's avatar John Zhang

fix: direct_arrayitem might require pinning

parent 1f6e137e
......@@ -1148,10 +1148,21 @@ class LL2MuMapper:
def map_op_direct_arrayitems(self, llop):
ARRAY = llop.args[0].concretetype.TO
ref = llop.args[0]
SRC = llop.args[0].concretetype
DST = llop.result.concretetype
ops = []
if isinstance(SRC, (mutype.MuRef, mutype.MuIRef)) and isinstance(DST, mutype.MuUPtr):
# needs to be pinned
ptr = varof(mutype.MuUPtr(SRC.TO))
ops.append(self.gen_mu_comminst('NATIVE_PIN', [ref], ptr, types=[SRC]))
ref = ptr
if not (isinstance(ARRAY, mutype.MuArray) or mutype.mu_barebonearray(ARRAY)):
_, muops = self._getinterioriref(llop.args[0], [Constant('items', mutype.MU_VOID)])
muops[-1].result = llop.result
return muops
iref, _ops = self._getinterioriref(ref, [Constant('items', mutype.MU_VOID)])
ops[-1].result = llop.result
return ops
# otherwise cast to the correct type
llop.__init__('cast_pointer', [llop.args[0]], llop.result)
return self.map_op_cast_pointer(llop)
......@@ -677,7 +677,7 @@ def test_direct_arrayitems():
llop = SpaceOperation('direct_arrayitems', [arr], res)
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getvarpartiref']
assert [op.opname for op in muops] == ['mu_comminst', 'mu_getvarpartiref']
def test_getsubstruct():
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