[pypy-svn] r45947 - in pypy/dist/pypy/translator: cli/test oosupport

antocuni at codespeak.net antocuni at codespeak.net
Fri Aug 24 12:31:08 CEST 2007


Author: antocuni
Date: Fri Aug 24 12:31:07 2007
New Revision: 45947

Modified:
   pypy/dist/pypy/translator/cli/test/test_snippet.py
   pypy/dist/pypy/translator/oosupport/function.py
Log:
finally found the bug. See the comments for more info.



Modified: pypy/dist/pypy/translator/cli/test/test_snippet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_snippet.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_snippet.py	Fri Aug 24 12:31:07 2007
@@ -23,3 +23,21 @@
             return f.le()
         res = self.interpret(fn, [], backendopt=False)
         
+    def test_link_vars_overlapping(self):
+        from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+        def fn(maxofs):
+            lastofs = 0
+            ofs = 1
+            while ofs < maxofs:
+                lastofs = ofs
+                try:
+                    ofs = ovfcheck_lshift(ofs, 1)
+                except OverflowError:
+                    ofs = maxofs
+                else:
+                    ofs = ofs + 1
+            return lastofs
+        res = self.interpret(fn, [64])
+        expected = fn(64)
+        assert res == expected
+        

Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py	(original)
+++ pypy/dist/pypy/translator/oosupport/function.py	Fri Aug 24 12:31:07 2007
@@ -245,13 +245,22 @@
 
     def _setup_link(self, link):
         target = link.target
+        linkvars = []
         for to_load, to_store in zip(link.args, target.inputargs):
             if isinstance(to_load, flowmodel.Variable) and to_load.name == to_store.name:
                 continue
             if to_load.concretetype is ootype.Void:
                 continue
-            self.generator.add_comment("%r --> %r" % (to_load, to_store))
+            linkvars.append((to_load, to_store))
+
+        # after SSI_to_SSA it can happen to have to_load = [a, b] and
+        # to_store = [b, c].  If we store each variable sequentially,
+        # 'b' would be overwritten before being read.  To solve, we
+        # first load all the values on the stack, then store in the
+        # appropriate places.
+        for to_load, to_store in linkvars:
             self.generator.load(to_load)
+        for to_load, to_store in reversed(linkvars):
             self.generator.store(to_store)
 
     def _trace_enabled(self):



More information about the Pypy-commit mailing list