1. Stian Andreassen
  2. pypy-improvebigint

Commits

Maciej Fijalkowski  committed 1196e6e

make the JIT explode if we try to push negative for alloc_and_set

  • Participants
  • Parent commits b2e4012
  • Branches virtual-arguments

Comments (0)

Files changed (3)

File pypy/interpreter/argument.py

View file
             for i in range(take):
                 scope_w[i + input_argcount] = args_w[i]
             input_argcount += take
-            input_argcount = max(input_argcount, 0)
 
         # collect extra positional arguments into the *vararg
         if signature.has_vararg():
         if num_kwds:
             # kwds_mapping maps target indexes in the scope (minus input_argcount)
             # to positions in the keywords_w list
-            kwds_mapping = [0] * (co_argcount - input_argcount)
+            cnt = (co_argcount - input_argcount)
+            if cnt < 0:
+                cnt = 0
+            kwds_mapping = [0] * cnt
             # initialize manually, for the JIT :-(
             for i in range(len(kwds_mapping)):
                 kwds_mapping[i] = -1

File pypy/jit/codewriter/jtransform.py

View file
 
     def do_fixed_newlist(self, op, args, arraydescr):
         v_length = self._get_initial_newlist_length(op, args)
+        if v_length.concretetype == lltype.Signed:
+            raise Exception("[item] * lgt must have lgt to be proven non-negative for the JIT")
         return SpaceOperation('new_array', [arraydescr, v_length], op.result)
 
     def do_fixed_list_len(self, op, args, arraydescr):

File pypy/jit/codewriter/test/test_codewriter.py

View file
     assert 'setarrayitem_raw_i' in s
     assert 'getarrayitem_raw_i' in s
     assert 'residual_call_ir_v $<* fn _ll_1_raw_free__arrayPtr>' in s
+
+def test_newlist_negativ():
+    def f(n):
+        l = [0] * n
+        return len(l)
+
+    rtyper = support.annotate(f, [-1])
+    jitdriver_sd = FakeJitDriverSD(rtyper.annotator.translator.graphs[0])
+    cw = CodeWriter(FakeCPU(rtyper), [jitdriver_sd])
+    cw.find_all_graphs(FakePolicy())
+    py.test.raises(Exception, "cw.make_jitcodes(verbose=True)")