[pypy-commit] pypy s390x-backend: assembly instructions now check the immediate values, asserting if a value too big/small is passed

plan_rich pypy.commits at gmail.com
Tue Mar 1 03:53:39 EST 2016


Author: Richard Plangger <planrichi at gmail.com>
Branch: s390x-backend
Changeset: r82625:1e7875e46f1c
Date: 2016-03-01 09:47 +0100
http://bitbucket.org/pypy/pypy/changeset/1e7875e46f1c/

Log:	assembly instructions now check the immediate values, asserting if a
	value too big/small is passed

diff --git a/rpython/jit/backend/zarch/assembler.py b/rpython/jit/backend/zarch/assembler.py
--- a/rpython/jit/backend/zarch/assembler.py
+++ b/rpython/jit/backend/zarch/assembler.py
@@ -1369,6 +1369,7 @@
         assert lengthloc is not r.RES and lengthloc is not r.RSZ
         assert lengthloc.is_reg()
 
+        assert maxlength >= 0
         if maxlength > 2**16-1:
             maxlength = 2**16-1      # makes things easier
         mc = self.mc
diff --git a/rpython/jit/backend/zarch/instruction_builder.py b/rpython/jit/backend/zarch/instruction_builder.py
--- a/rpython/jit/backend/zarch/instruction_builder.py
+++ b/rpython/jit/backend/zarch/instruction_builder.py
@@ -461,7 +461,45 @@
 
 def build_unpack_func(mnemonic, func):
     @always_inline
+    def check_arg_type(arg, type):
+        #iX     - immediate X bits (signed)
+        if type.startswith('i'):
+            value = arg.value
+            if type == 'i8': assert -2**7 <= value <= 2**7-1
+            if type == 'i12': assert -2**11 <= value <= 2**11-1
+            if type == 'i16': assert -2**15 <= value <= 2**15-1
+            if type == 'i20': assert -2**19 <= value <= 2**19-1
+            if type == 'i32': assert -2**31 <= value <= 2**31-1
+        #uX     - immediate X bits (unsigend)
+        if type.startswith('u'):
+            value = arg.value
+            if type == 'u8': assert  0 <= value <= 2**8-1
+            if type == 'u12': assert 0 <= value <= 2**12-1
+            if type == 'u16': assert 0 <= value <= 2**16-1
+            if type == 'u20': assert 0 <= value <= 2**20-1
+            if type == 'u32': assert 0 <= value <= 2**32-1
+        #bd     - base displacement (unsigned 12 bit)
+        #bid    - index base displacement (unsigned 12 bit)
+        if type == 'bd' or type == 'bid':
+            value = arg.displace
+            assert 0 <= value <= 2**12-1
+        #bdl    - base displacement long (20 bit)
+        #bidl   - index base displacement (20 bit)
+        if type == 'bdl' or type == 'bidl':
+            value = arg.displace
+            assert -2**19 <= value <= 2**19-1
+        #l4bd   - length base displacement (4 bit)
+        if type == 'l4db':
+            value = arg.displace
+            assert 0 <= value <= 2**4-1
+        #h32    - halfwords 32 bit (e.g. LARL, or other relative instr.)
+        if type == 'h32':
+            value = arg.value
+            assert -2**31 <= value <= 2**31-1
+            assert value & 0x1 == 0
+    @always_inline
     def unpack_arg(arg, argtype):
+        check_arg_type(arg, argtype)
         if argtype == '-':
             return 0
         elif argtype == 'r' or argtype == 'r/m' or \
@@ -565,3 +603,4 @@
         setattr(clazz, mnemonic, build_unpack_func(mnemonic, func))
         setattr(clazz, mnemonic + '_byte_count', func._byte_count)
         del func._byte_count
+        del func._arguments_
diff --git a/rpython/jit/backend/zarch/instructions.py b/rpython/jit/backend/zarch/instructions.py
--- a/rpython/jit/backend/zarch/instructions.py
+++ b/rpython/jit/backend/zarch/instructions.py
@@ -182,6 +182,7 @@
     'STE':     ('rx',    ['\x70']),
     # note displacement is UNsigned 12 bit
     'STD':     ('rx',    ['\x60']),
+    # here it is 20 bit signed
     'STDY':    ('rxy',   ['\xED','\x67']),
 
     'SPM':     ('rr',    ['\x04'], 'r,-'),
diff --git a/rpython/jit/backend/zarch/opassembler.py b/rpython/jit/backend/zarch/opassembler.py
--- a/rpython/jit/backend/zarch/opassembler.py
+++ b/rpython/jit/backend/zarch/opassembler.py
@@ -454,7 +454,8 @@
         [lengthloc] = arglocs
         arraydescr = op.getdescr()
         itemsize = op.getarg(1).getint()
-        maxlength = (gc_ll_descr.max_size_of_young_obj - WORD * 2) / itemsize
+        assert itemsize == 1
+        maxlength = (gc_ll_descr.max_size_of_young_obj - WORD * 2)
         gcmap = regalloc.get_gcmap([r.RES, r.RSZ])
         self.malloc_cond_varsize(
             op.getarg(0).getint(),
diff --git a/rpython/jit/backend/zarch/regalloc.py b/rpython/jit/backend/zarch/regalloc.py
--- a/rpython/jit/backend/zarch/regalloc.py
+++ b/rpython/jit/backend/zarch/regalloc.py
@@ -803,6 +803,7 @@
         # sure it is in a register different from r.RES and r.RSZ.  (It
         # should not be a ConstInt at all.)
         length_box = op.getarg(2)
+        assert not isinstance(length_box, Const)
         lengthloc = self.ensure_reg(length_box)
         return [lengthloc]
 


More information about the pypy-commit mailing list