OSDN Git Service

decodetree: Properly diagnose fields overflowing an insn
authorRichard Henderson <richard.henderson@linaro.org>
Tue, 5 Mar 2019 23:34:41 +0000 (15:34 -0800)
committerRichard Henderson <richard.henderson@linaro.org>
Tue, 12 Mar 2019 16:46:58 +0000 (09:46 -0700)
Previously this would result in an exception for shifting
the field mask by a negative number.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
scripts/decodetree.py
tests/decode/err_width1.decode [new file with mode: 0644]
tests/decode/err_width2.decode [new file with mode: 0644]
tests/decode/err_width3.decode [new file with mode: 0644]
tests/decode/err_width4.decode [new file with mode: 0644]

index ac158b4..aa790b5 100755 (executable)
@@ -622,6 +622,8 @@ def parse_generic(lineno, is_format, name, toks):
                 sign = True
                 flen = flen[1:]
             shift = int(flen, 10)
+            if shift + width > insnwidth:
+                error(lineno, 'field {0} exceeds insnwidth'.format(fname))
             f = Field(sign, insnwidth - width - shift, shift)
             flds = add_field(lineno, flds, fname, f)
             fixedbits <<= shift
diff --git a/tests/decode/err_width1.decode b/tests/decode/err_width1.decode
new file mode 100644 (file)
index 0000000..0c14f6d
--- /dev/null
@@ -0,0 +1,5 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+# Diagnose too many bits (33 of 32)
+one    000000000000000000000000000000000
diff --git a/tests/decode/err_width2.decode b/tests/decode/err_width2.decode
new file mode 100644 (file)
index 0000000..47f0acf
--- /dev/null
@@ -0,0 +1,5 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+# Diagnose too few bits (31 of 32)
+one    0000000000000000000000000000000
diff --git a/tests/decode/err_width3.decode b/tests/decode/err_width3.decode
new file mode 100644 (file)
index 0000000..c5fb6b3
--- /dev/null
@@ -0,0 +1,5 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+# Diagnose too many bits (33 of 32)
+one    0 s:32
diff --git a/tests/decode/err_width4.decode b/tests/decode/err_width4.decode
new file mode 100644 (file)
index 0000000..1588a63
--- /dev/null
@@ -0,0 +1,5 @@
+# This work is licensed under the terms of the GNU LGPL, version 2 or later.
+# See the COPYING.LIB file in the top-level directory.
+
+# Diagnose too few bits (31 of 32)
+one    0 s:30