Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r80584:97dbcab3e9a0 Date: 2015-11-08 10:52 +0100 http://bitbucket.org/pypy/pypy/changeset/97dbcab3e9a0/
Log: Add (skipped, failing) tests for the constant_fold() done in pure.py on possibly invalid GC pointers diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -638,6 +638,7 @@ def bh_getarrayitem_gc(self, a, index, descr): a = support.cast_arg(lltype.Ptr(descr.A), a) array = a._obj + assert index >= 0 return support.cast_result(descr.A.OF, array.getitem(index)) bh_getarrayitem_gc_pure_i = bh_getarrayitem_gc @@ -743,6 +744,7 @@ return s._obj.container.chars.getlength() def bh_strgetitem(self, s, item): + assert item >= 0 return ord(s._obj.container.chars.getitem(item)) def bh_strsetitem(self, s, item, v): @@ -764,6 +766,7 @@ return string._obj.container.chars.getlength() def bh_unicodegetitem(self, string, index): + assert index >= 0 return ord(string._obj.container.chars.getitem(index)) def bh_unicodesetitem(self, string, index, newvalue): diff --git a/rpython/jit/metainterp/executor.py b/rpython/jit/metainterp/executor.py --- a/rpython/jit/metainterp/executor.py +++ b/rpython/jit/metainterp/executor.py @@ -409,7 +409,7 @@ def make_execute_function(name, func): # Make a wrapper for 'func'. The func is a simple bhimpl_xxx function # from the BlackholeInterpreter class. The wrapper is a new function - # that receives and returns boxed values. + # that receives boxed values (but returns a non-boxed value). for argtype in func.argtypes: if argtype not in ('i', 'r', 'f', 'd', 'cpu'): return None diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -9027,6 +9027,138 @@ # may either raise InvalidLoop or compile; it's a rare case self.optimize_loop(ops, expected) + def test_unroll_pure_on_bogus_object_1(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getfield_gc_pure_i(p0, descr=valuedescr) + i3 = int_sub(i1, 1) + jump(NULL, i3) + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_2(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getfield_gc_pure_i(p0, descr=valuedescr) + i3 = int_sub(i1, 1) + jump(ConstPtr(myptr3), i3) + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_3(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getarrayitem_gc_pure_i(p0, 5, descr=arraydescr) + i3 = int_sub(i1, 1) + jump(NULL, i3) + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_4(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getarrayitem_gc_pure_i(p0, 5, descr=arraydescr) + i3 = int_sub(i1, 1) + jump(ConstPtr(myptr3), i3) + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_5(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getarrayitem_gc_pure_i(p0, 125, descr=arraydescr) + i3 = int_sub(i1, 1) + jump(ConstPtr(arrayref), i3) # too short, length < 126! + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_6(self): + py.test.skip("FIXME") + ops = """ + [i0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getarrayitem_gc_pure_i(ConstPtr(arrayref), i0, descr=arraydescr) + i3 = int_sub(i1, 1) + jump(125, i3) # arrayref is too short, length < 126! + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_7(self): + py.test.skip("FIXME") + ops = """ + [i0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + getarrayitem_gc_pure_i(ConstPtr(arrayref), i0, descr=arraydescr) + i3 = int_sub(i1, 1) + jump(-1, i3) # cannot access array item -1! + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_8(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + i4 = strgetitem(p0, 125) + i3 = int_sub(i1, 1) + jump(NULL, i3) + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_9(self): + py.test.skip("FIXME") + ops = """ + [p0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + i4 = strgetitem(p0, 125) + i3 = int_sub(i1, 1) + jump(ConstPtr(myptr), i3) # not a string at all + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_10(self): + py.test.skip("FIXME") + ops = """ + [i0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + i4 = strgetitem("foobar", i0) + i3 = int_sub(i1, 1) + jump(125, i3) # string is too short! + """ + self.optimize_loop(ops, ops) + + def test_unroll_pure_on_bogus_object_11(self): + py.test.skip("FIXME") + ops = """ + [i0, i1] + i2 = int_gt(i1, 0) + guard_true(i2) [] + i4 = strgetitem("foobar", i0) + i3 = int_sub(i1, 1) + jump(-1, i3) # cannot access character -1! + """ + self.optimize_loop(ops, ops) + class TestLLtype(OptimizeOptTest, LLtypeMixin): pass _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit