Commits

Antonio Cuni  committed ada6185

force the raw buffer if we detect an invalid read

  • Participants
  • Parent commits 27446ea
  • Branches virtual-raw-mallocs

Comments (0)

Files changed (2)

File pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py

         """
         self.optimize_loop(ops, expected)
 
+    def test_virtual_raw_malloc_invalid_read_force(self):
+        ops = """
+        [i1]
+        i2 = call('malloc', 10, descr=raw_malloc_descr)
+        setarrayitem_raw(i2, 0, i1, descr=rawarraydescr)
+        label('foo') # we expect the buffer to be forced *after* the label
+        i3 = getarrayitem_raw(i2, 0, descr=rawarraydescr_char)
+        call('free', i2, descr=raw_free_descr)
+        jump(i1)
+        """
+        expected = """
+        [i1]
+        label('foo')
+        i2 = call('malloc', 10, descr=raw_malloc_descr)
+        setarrayitem_raw(i2, 0, i1, descr=rawarraydescr)
+        i3 = getarrayitem_raw(i2, 0, descr=rawarraydescr_char)
+        call('free', i2, descr=raw_free_descr)
+        jump(i1)
+        """
+        self.optimize_loop(ops, expected)
+
     def test_duplicate_getfield_1(self):
         ops = """
         [p1, p2]

File pypy/jit/metainterp/optimizeopt/virtualize.py

         self.buffer.write_value(offset, length, descr, value)
 
     def getitem_raw(self, offset, length, descr):
-        try:
-            return self.buffer.read_value(offset, length, descr)
-        except InvalidRawOperation:
-            XXX
+        return self.buffer.read_value(offset, length, descr)
 
 
 class OptVirtualize(optimizer.Optimization):
             indexbox = self.get_constant_box(op.getarg(1))
             if indexbox is not None:
                 offset, itemsize, descr = self._unpack_arrayitem_raw_op(op, indexbox)
-                itemvalue = value.getitem_raw(offset, itemsize, descr)
-                self.make_equal_to(op.result, itemvalue)
+                try:
+                    itemvalue = value.getitem_raw(offset, itemsize, descr)
+                    self.make_equal_to(op.result, itemvalue)
+                except InvalidRawOperation:
+                    box = value.force_box(self)
+                    op.setarg(0, box)
+                    self.emit_operation(op)
                 return
         value.ensure_nonnull()
         self.emit_operation(op)