Commits

Manuel Jacob committed ae05315

Add failing test that checks whether raisingop2direct_call transforms overflow operations using unsigned arithmetic.

  • Participants
  • Parent commits b4f8189

Comments (0)

Files changed (1)

rpython/translator/c/test/test_backendoptimized.py

         fn = self.getcompiled(f, [int])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(x) == f(x)
+
+    def test_ovf_op_in_loop(self):
+        # This checks whether the raising operations are implemented using
+        # unsigned arithmetic. The problem with using signed arithmetic is that
+        # signed overflow is undefined in C and the optimizer is allowed to
+        # remove the overflow check.
+        from sys import maxint
+        from rpython.rlib.rarithmetic import ovfcheck
+        def f(x, y):
+            ret = 0
+            for i in range(y):
+                try:
+                    ret = ovfcheck(x + i)
+                except OverflowError:
+                    break
+            return ret
+        fc = self.getcompiled(f, [int, int])
+        assert fc(10, 10) == 19
+        assert fc(maxint, 10) == maxint