[pypy-svn] r58871 - in pypy/dist/pypy/translator/backendopt: . test

arigo at codespeak.net arigo at codespeak.net
Fri Oct 10 10:14:11 CEST 2008


Author: arigo
Date: Fri Oct 10 10:14:11 2008
New Revision: 58871

Modified:
   pypy/dist/pypy/translator/backendopt/mallocv.py
   pypy/dist/pypy/translator/backendopt/test/test_malloc.py
   pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
Log:
A test that fails in the old "malloc.py".  Make it pass in the new "mallocv.py".


Modified: pypy/dist/pypy/translator/backendopt/mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/mallocv.py	Fri Oct 10 10:14:11 2008
@@ -476,6 +476,14 @@
         newresult = self.make_rt_result(op.result)
         return [SpaceOperation(op.opname, newargs, newresult)]
 
+    def handle_unreachable(self, op):
+        from pypy.rpython.lltypesystem.rstr import string_repr
+        msg = 'unreachable: %s' % (op,)
+        ll_msg = string_repr.convert_const(msg)
+        c_msg = Constant(ll_msg, lltype.typeOf(ll_msg))
+        newresult = self.make_rt_result(op.result)
+        return [SpaceOperation('debug_fatalerror', [c_msg], newresult)]
+
     def handle_op_getfield(self, op):
         node = self.getnode(op.args[0])
         if isinstance(node, VirtualSpecNode):
@@ -498,6 +506,31 @@
         else:
             return self.handle_default(op)
 
+    def handle_op_same_as(self, op):
+        node = self.getnode(op.args[0])
+        if isinstance(node, VirtualSpecNode):
+            node = self.getnode(op.args[0])
+            self.setnode(op.result, node)
+            return []
+        else:
+            return self.handle_default(op)
+
+    def handle_op_cast_pointer(self, op):
+        node = self.getnode(op.args[0])
+        if isinstance(node, VirtualSpecNode):
+            node = self.getnode(op.args[0])
+            SOURCEPTR = lltype.Ptr(node.typedesc.MALLOCTYPE)
+            TARGETPTR = op.result.concretetype
+            try:
+                if lltype.castable(TARGETPTR, SOURCEPTR) < 0:
+                    raise lltype.InvalidCast
+            except lltype.InvalidCast:
+                return self.handle_unreachable(op)
+            self.setnode(op.result, node)
+            return []
+        else:
+            return self.handle_default(op)
+
     def handle_op_malloc(self, op):
         if op.result is self.v_expand_malloc:
             MALLOCTYPE = op.result.concretetype.TO

Modified: pypy/dist/pypy/translator/backendopt/test/test_malloc.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_malloc.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_malloc.py	Fri Oct 10 10:14:11 2008
@@ -383,6 +383,19 @@
             return u[0].s.x
         graph = self.check(f, [int], [42], 42)
 
+    def test_bogus_cast_pointer(self):
+        py.test.skip("XXX fix me")
+        S = lltype.GcStruct("S", ('x', lltype.Signed))
+        T = lltype.GcStruct("T", ('s', S), ('y', lltype.Signed))
+        def f(x):
+            s = lltype.malloc(S)
+            s.x = 123
+            if x < 0:
+                t = lltype.cast_pointer(lltype.Ptr(T), s)
+                t.y += 1
+            return s.x
+        graph = self.check(f, [int], [5], 123)
+
 
 class TestOOTypeMallocRemoval(BaseMallocRemovalTest):
     type_system = 'ootype'

Modified: pypy/dist/pypy/translator/backendopt/test/test_mallocv.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_mallocv.py	Fri Oct 10 10:14:11 2008
@@ -43,7 +43,6 @@
             t.view()
         # to detect missing keepalives and broken intermediate graphs,
         # we do the loop ourselves instead of calling remove_simple_mallocs()
-        maxiter = 100
         mallocv = MallocVirtualizer(t.graphs, verbose=True)
         while True:
             progress = mallocv.remove_mallocs_once()
@@ -168,7 +167,6 @@
         assert insns.get('direct_call', 0) == 0     # inlined
 
     def test_fn2(self):
-        py.test.skip("redo me")
         class T:
             pass
         def fn2(x, y):
@@ -502,6 +500,18 @@
             return u[0].s.x
         graph = self.check(f, [int], [42], 42)
 
+    def test_bogus_cast_pointer(self):
+        S = lltype.GcStruct("S", ('x', lltype.Signed))
+        T = lltype.GcStruct("T", ('s', S), ('y', lltype.Signed))
+        def f(x):
+            s = lltype.malloc(S)
+            s.x = 123
+            if x < 0:
+                t = lltype.cast_pointer(lltype.Ptr(T), s)
+                t.y += 1
+            return s.x
+        graph = self.check(f, [int], [5], 123)
+
 
 class DISABLED_TestOOTypeMallocRemoval(BaseMallocRemovalTest):
     type_system = 'ootype'



More information about the Pypy-commit mailing list