]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
MIPS/GAS: Improve bignum operand error diagnostics
authorMaciej W. Rozycki <macro@imgtec.com>
Mon, 15 May 2017 12:17:18 +0000 (13:17 +0100)
committerMaciej W. Rozycki <macro@imgtec.com>
Mon, 15 May 2017 12:57:09 +0000 (13:57 +0100)
Improve bignum operand error diagnostics for cases where a constant
would be accepted and report them as range errors, also indicating the
offending operand and instruction, e.g.:

$ cat bignum.s
addiu $2, 0x10000000000000000
break 0x10000000000000000
$ as -o bignum.o bignum.s
bignum.s:1: Error: bignum invalid
bignum.s:2: Error: operand 1 must be constant `break 0x10000000000000000'
$

now show as:

$ as -o bignum.o bignum.s
bignum.s:1: Error: operand 2 out of range `addiu $2,0x10000000000000000'
bignum.s:2: Error: operand 1 out of range `break 0x10000000000000000'
$

gas/
* config/tc-mips.c (match_const_int): Call `match_out_of_range'
rather than `match_not_constant' for unrelocated operands
retrieved as an `O_big' expression.
(match_int_operand): Call `match_out_of_range' for relocatable
operands retrieved as an `O_big' expression.
(match_mips16_insn): Call `match_out_of_range' for relaxable
operands retrieved as an `O_big' expression.
* testsuite/gas/mips/addiu-error.d: New test.
* testsuite/gas/mips/mips16@addiu-error.d: New test.
* testsuite/gas/mips/micromips@addiu-error.d: New test.
* testsuite/gas/mips/break-error.d: New test.
* testsuite/gas/mips/lui-1.l: Adjust error message.
* testsuite/gas/mips/addiu-error.l: New stderr output.
* testsuite/gas/mips/mips16@addiu-error.l: New stderr output.
* testsuite/gas/mips/micromips@addiu-error.l: New stderr output.
* testsuite/gas/mips/break-error.l: New stderr output.
* testsuite/gas/mips/addiu-error.s: New test source.
* testsuite/gas/mips/break-error.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new tests.

14 files changed:
gas/ChangeLog
gas/config/tc-mips.c
gas/testsuite/gas/mips/addiu-error.d [new file with mode: 0644]
gas/testsuite/gas/mips/addiu-error.l [new file with mode: 0644]
gas/testsuite/gas/mips/addiu-error.s [new file with mode: 0644]
gas/testsuite/gas/mips/break-error.d [new file with mode: 0644]
gas/testsuite/gas/mips/break-error.l [new file with mode: 0644]
gas/testsuite/gas/mips/break-error.s [new file with mode: 0644]
gas/testsuite/gas/mips/lui-1.l
gas/testsuite/gas/mips/micromips@addiu-error.d [new file with mode: 0644]
gas/testsuite/gas/mips/micromips@addiu-error.l [new file with mode: 0644]
gas/testsuite/gas/mips/mips.exp
gas/testsuite/gas/mips/mips16@addiu-error.d [new file with mode: 0644]
gas/testsuite/gas/mips/mips16@addiu-error.l [new file with mode: 0644]

index 544ff7af1e65b5c458787e664a472d5b61b9bc64..afbb20ef112ad866a534c6338ea770cac0f298be 100644 (file)
@@ -1,3 +1,25 @@
+2017-05-15  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * config/tc-mips.c (match_const_int): Call `match_out_of_range'
+       rather than `match_not_constant' for unrelocated operands
+       retrieved as an `O_big' expression.
+       (match_int_operand): Call `match_out_of_range' for relocatable
+       operands retrieved as an `O_big' expression.
+       (match_mips16_insn): Call `match_out_of_range' for relaxable
+       operands retrieved as an `O_big' expression.
+       * testsuite/gas/mips/addiu-error.d: New test.
+       * testsuite/gas/mips/mips16@addiu-error.d: New test.
+       * testsuite/gas/mips/micromips@addiu-error.d: New test.
+       * testsuite/gas/mips/break-error.d: New test.
+       * testsuite/gas/mips/lui-1.l: Adjust error message.
+       * testsuite/gas/mips/addiu-error.l: New stderr output.
+       * testsuite/gas/mips/mips16@addiu-error.l: New stderr output.
+       * testsuite/gas/mips/micromips@addiu-error.l: New stderr output.
+       * testsuite/gas/mips/break-error.l: New stderr output.
+       * testsuite/gas/mips/addiu-error.s: New test source.
+       * testsuite/gas/mips/break-error.s: New test source.
+       * testsuite/gas/mips/mips.exp: Run the new tests.
+
 2017-05-15  Maciej W. Rozycki  <macro@imgtec.com>
 
        * config/tc-mips.c (match_mips16_insn): Remove the explicit
index ac4fefd25b26bc6dc90308fa146853db2f2e3d55..9fde4626239dce19d198ca66f3992198220ad5cc 100644 (file)
@@ -4856,7 +4856,10 @@ match_const_int (struct mips_arg_info *arg, offsetT *value)
     *value = ex.X_add_number;
   else
     {
-      match_not_constant (arg);
+      if (r[0] == BFD_RELOC_UNUSED && ex.X_op == O_big)
+       match_out_of_range (arg);
+      else
+       match_not_constant (arg);
       return FALSE;
     }
   return TRUE;
@@ -5062,6 +5065,12 @@ match_int_operand (struct mips_arg_info *arg,
       if (!match_expression (arg, &offset_expr, offset_reloc))
        return FALSE;
 
+      if (offset_expr.X_op == O_big)
+       {
+         match_out_of_range (arg);
+         return FALSE;
+       }
+
       if (offset_reloc[0] != BFD_RELOC_UNUSED)
        /* Relocation operators were used.  Accept the argument and
           leave the relocation value in offset_expr and offset_relocs
@@ -8261,6 +8270,12 @@ match_mips16_insn (struct mips_cl_insn *insn, const struct mips_opcode *opcode,
                  return FALSE;
                }
 
+             if (offset_expr.X_op == O_big)
+               {
+                 match_out_of_range (&arg);
+                 return FALSE;
+               }
+
              relax_char = c;
              continue;
            }
diff --git a/gas/testsuite/gas/mips/addiu-error.d b/gas/testsuite/gas/mips/addiu-error.d
new file mode 100644 (file)
index 0000000..13a99ac
--- /dev/null
@@ -0,0 +1,3 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: addiu-error.l
diff --git a/gas/testsuite/gas/mips/addiu-error.l b/gas/testsuite/gas/mips/addiu-error.l
new file mode 100644 (file)
index 0000000..1dc0014
--- /dev/null
@@ -0,0 +1,8 @@
+.*: Assembler messages:
+.*:5: Error: operand 2 out of range `addiu \$2,-32769'
+.*:6: Error: operand 2 out of range `addiu \$2,65536'
+.*:7: Error: operand 2 out of range `addiu \$2,0x10000000000000000'
+.*:8: Error: operand 2 must be an immediate expression `addiu \$2,\$3'
+.*:9: Error: invalid operands `addiu \$2,\(\$3\)'
+.*:10: Error: register value used as expression `addiu \$2,0\+\$3'
+.*:11: Error: register value used as expression `addiu \$2,\(\(\$3\)\)'
diff --git a/gas/testsuite/gas/mips/addiu-error.s b/gas/testsuite/gas/mips/addiu-error.s
new file mode 100644 (file)
index 0000000..1e19ea8
--- /dev/null
@@ -0,0 +1,11 @@
+# Source code used to test error diagnostics with the ADDIU instruction.
+
+       .text
+foo:
+       addiu   $2, -32769
+       addiu   $2, 65536
+       addiu   $2, 0x10000000000000000
+       addiu   $2, $3
+       addiu   $2, ($3)
+       addiu   $2, 0+$3
+       addiu   $2, (($3))
diff --git a/gas/testsuite/gas/mips/break-error.d b/gas/testsuite/gas/mips/break-error.d
new file mode 100644 (file)
index 0000000..2110814
--- /dev/null
@@ -0,0 +1,3 @@
+#name: MIPS BREAK errors
+#as: -32
+#error-output: break-error.l
diff --git a/gas/testsuite/gas/mips/break-error.l b/gas/testsuite/gas/mips/break-error.l
new file mode 100644 (file)
index 0000000..2759a91
--- /dev/null
@@ -0,0 +1,8 @@
+.*: Assembler messages:
+.*:5: Error: operand 1 out of range `break -1'
+.*:6: Error: operand 1 out of range `break 65536'
+.*:7: Error: operand 1 out of range `break 0x10000000000000000'
+.*:8: Error: operand 1 must be an immediate expression `break \$3'
+.*:9: Error: invalid operands `break \(\$3\)'
+.*:10: Error: register value used as expression `break 0\+\$3'
+.*:11: Error: register value used as expression `break \(\(\$3\)\)'
diff --git a/gas/testsuite/gas/mips/break-error.s b/gas/testsuite/gas/mips/break-error.s
new file mode 100644 (file)
index 0000000..f5ac225
--- /dev/null
@@ -0,0 +1,11 @@
+# Source code used to test error diagnostics with the BREAK instruction.
+
+       .text
+foo:
+       break   -1
+       break   65536
+       break   0x10000000000000000
+       break   $3
+       break   ($3)
+       break   0+$3
+       break   (($3))
index 8bf621d181fc5ffda69ef65aba7a47ae6fb4e89e..d6cb98aa457002fd1f97b2ed29821c916cef60ca 100644 (file)
@@ -1,7 +1,7 @@
 .*\.s: Assembler messages:
 .*\.s:5: Error: operand 2 out of range `lui \$2,-1'
 .*\.s:6: Error: operand 2 out of range `lui \$2,65536'
-.*\.s:7: Error: bignum invalid
+.*\.s:7: Error: operand 2 out of range `lui \$2,0x10000000000000000'
 .*\.s:8: Error: operand 2 must be an immediate expression `lui \$2,\$3'
 .*\.s:9: Error: invalid operands `lui \$2,\(\$3\)'
 .*\.s:10: Error: register value used as expression `lui \$2,0\+\$3'
diff --git a/gas/testsuite/gas/mips/micromips@addiu-error.d b/gas/testsuite/gas/mips/micromips@addiu-error.d
new file mode 100644 (file)
index 0000000..0313261
--- /dev/null
@@ -0,0 +1,4 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: micromips@addiu-error.l
+#source: addiu-error.s
diff --git a/gas/testsuite/gas/mips/micromips@addiu-error.l b/gas/testsuite/gas/mips/micromips@addiu-error.l
new file mode 100644 (file)
index 0000000..1527ead
--- /dev/null
@@ -0,0 +1,8 @@
+.*: Assembler messages:
+.*:5: Error: operand 2 out of range `addiu \$2,-32769'
+.*:6: Error: operand 2 out of range `addiu \$2,65536'
+.*:7: Error: operand 2 out of range `addiu \$2,0x10000000000000000'
+.*:8: Error: operand 2 must be an immediate expression `addiu \$2,\$3'
+.*:9: Error: operand 2 out of range `addiu \$2,\(\$3\)'
+.*:10: Error: register value used as expression `addiu \$2,0\+\$3'
+.*:11: Error: register value used as expression `addiu \$2,\(\(\$3\)\)'
index de38a1c7abbcc7c9fe0c4bbfd94eeb2de6b8efff..c9559df5570c0fbb378b10639787e43f927422d5 100644 (file)
@@ -1466,6 +1466,8 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test_arches "lui"         [mips_arch_list_matching mips1]
     run_dump_test_arches "lui-1"       [mips_arch_list_matching mips1]
     run_dump_test_arches "lui-2"       [mips_arch_list_matching mips1]
+    run_dump_test_arches "addiu-error" [mips_arch_list_all]
+    run_dump_test_arches "break-error" [mips_arch_list_all]
 
     run_dump_test "r5900"
     run_dump_test "r5900-full"
diff --git a/gas/testsuite/gas/mips/mips16@addiu-error.d b/gas/testsuite/gas/mips/mips16@addiu-error.d
new file mode 100644 (file)
index 0000000..67b4611
--- /dev/null
@@ -0,0 +1,4 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: mips16@addiu-error.l
+#source: addiu-error.s
diff --git a/gas/testsuite/gas/mips/mips16@addiu-error.l b/gas/testsuite/gas/mips/mips16@addiu-error.l
new file mode 100644 (file)
index 0000000..c7fd7c9
--- /dev/null
@@ -0,0 +1,8 @@
+.*: Assembler messages:
+.*:5: Error: operand value out of range for instruction
+.*:6: Error: operand value out of range for instruction
+.*:7: Error: operand 2 out of range `addiu \$2,0x10000000000000000'
+.*:8: Error: operand 2 must be an immediate expression `addiu \$2,\$3'
+.*:9: Error: invalid operands `addiu \$2,\(\$3\)'
+.*:10: Error: register value used as expression `addiu \$2,0\+\$3'
+.*:11: Error: register value used as expression `addiu \$2,\(\(\$3\)\)'