[v2,7/7] gas: pru: Add range checks for constant operands

Message ID 20180504170742.27303-7-dimitar@dinux.eu
State New
Headers show
Series
  • [v2,1/7] bfd:pru: Fix LDI32 relocation to conform to TI ABI
Related show

Commit Message

Dimitar Dimitrov May 4, 2018, 5:07 p.m.
Add missed check for 8-bit immediate operands.

Note that other types of operands have corresponding relocations, so GAS
already catches their overflows using pru_check_overflow().

2018-05-02  Dimitar Dimitrov  <dimitar@dinux.eu>

	* gas/config/tc-pru.c (pru_assemble_arg_b): Check imm8 operand range.
	* gas/testsuite/gas/pru/illegal2.l: New test.
	* gas/testsuite/gas/pru/illegal2.s: New test.
	* gas/testsuite/gas/pru/pru.exp: Register new illegal2 test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>

---
 gas/config/tc-pru.c              | 2 ++
 gas/testsuite/gas/pru/illegal2.l | 2 ++
 gas/testsuite/gas/pru/illegal2.s | 5 +++++
 gas/testsuite/gas/pru/pru.exp    | 1 +
 4 files changed, 10 insertions(+)
 create mode 100644 gas/testsuite/gas/pru/illegal2.l
 create mode 100644 gas/testsuite/gas/pru/illegal2.s

-- 
2.11.0

Patch

diff --git a/gas/config/tc-pru.c b/gas/config/tc-pru.c
index 91edf14557..5121b1f8a4 100644
--- a/gas/config/tc-pru.c
+++ b/gas/config/tc-pru.c
@@ -1089,6 +1089,8 @@  pru_assemble_arg_b (pru_insn_infoS *insn_info, const char *argstr)
   if (src2 == NULL)
     {
       unsigned long imm8 = pru_assemble_noreloc_expression (argstr);
+      if (imm8 >= 0x100)
+	as_bad (_("value %lu is too large for a byte operand"), imm8);
       SET_INSN_FIELD (IMM8, insn_info->insn_code, imm8);
       SET_INSN_FIELD (IO, insn_info->insn_code, 1);
     }
diff --git a/gas/testsuite/gas/pru/illegal2.l b/gas/testsuite/gas/pru/illegal2.l
new file mode 100644
index 0000000000..793eca7cfd
--- /dev/null
+++ b/gas/testsuite/gas/pru/illegal2.l
@@ -0,0 +1,2 @@ 
+.*illegal2.s: Assembler messages:
+.*illegal2.s:5: Error: value 256 is too large for a byte operand
diff --git a/gas/testsuite/gas/pru/illegal2.s b/gas/testsuite/gas/pru/illegal2.s
new file mode 100644
index 0000000000..c37f1b2b60
--- /dev/null
+++ b/gas/testsuite/gas/pru/illegal2.s
@@ -0,0 +1,5 @@ 
+# Source file used to test illegal operands.
+
+foo:
+# Out-of-bounds immediate value
+	add r2, r2, 256
diff --git a/gas/testsuite/gas/pru/pru.exp b/gas/testsuite/gas/pru/pru.exp
index 49bdf03a47..cacaa2bcd8 100644
--- a/gas/testsuite/gas/pru/pru.exp
+++ b/gas/testsuite/gas/pru/pru.exp
@@ -22,5 +22,6 @@  if { [istarget pru-*-*] } {
     run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
 
     run_list_test "illegal" ""
+    run_list_test "illegal2" ""
     run_list_test "warn_reglabel" ""
 }