[pypy-svn] r65103 - in pypy/branch/pyjitpl5/pypy: rpython/lltypesystem translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed May 6 16:40:47 CEST 2009


Author: arigo
Date: Wed May  6 16:40:46 2009
New Revision: 65103

Modified:
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/pyjitpl5/pypy/translator/c/test/test_lladdresses.py
Log:
'cast_adr_to_int' must not be canfold=True.  Otherwise,
we get code compiled with a random integer constant.
See new test.


Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py	Wed May  6 16:40:46 2009
@@ -378,7 +378,7 @@
     'adr_call':             LLOp(canraise=(Exception,)),
     'cast_ptr_to_adr':      LLOp(sideeffects=False),
     'cast_adr_to_ptr':      LLOp(canfold=True),
-    'cast_adr_to_int':      LLOp(canfold=True),
+    'cast_adr_to_int':      LLOp(sideeffects=False),
     'cast_int_to_adr':      LLOp(canfold=True),   # not implemented in llinterp
 
     # __________ used by the JIT ________

Modified: pypy/branch/pyjitpl5/pypy/translator/c/test/test_lladdresses.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/c/test/test_lladdresses.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/c/test/test_lladdresses.py	Wed May  6 16:40:46 2009
@@ -174,3 +174,20 @@
     fn = compile(f, [int], gcpolicy='boehm')
     assert fn(3) == 123
     assert fn(-3) == -42
+
+def test_cast_adr_to_int():
+    S = lltype.Struct("S", ("x", lltype.Signed))
+    s = lltype.malloc(S, immortal=True)
+    adr = cast_ptr_to_adr(s)
+    def f(n):
+        i = cast_adr_to_int(adr)
+        if n > 10:
+            adr2 = adr
+        else:
+            adr2 = NULL
+        print "hello world"     # prevent constant-folding
+        j = cast_adr_to_int(adr2)
+        return i - j
+    fc = compile(f, [int])
+    res = fc(42)
+    assert res == 0



More information about the Pypy-commit mailing list