This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed 3/5] MIPS/GAS: Improve bignum operand error diagnostics
- From: "Maciej W. Rozycki" <macro at imgtec dot com>
- To: <binutils at sourceware dot org>
- Date: Mon, 15 May 2017 14:32:35 +0100
- Subject: [committed 3/5] MIPS/GAS: Improve bignum operand error diagnostics
- Authentication-results: sourceware.org; auth=none
- References: <alpine.DEB.2.00.1705102025580.2590@tp.orcam.me.uk>
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.
---
NB the "operand 2 out of range `addiu $2,($3)'" message seen in one of
the listings for microMIPS ADDIU is misleading and refers to an elided
base expression's offset matching the `mB' operand code. A generic
"invalid operands `addiu $2,($3)'" message would be better, like with
regular MIPS and MIPS16 assembly, as would better yet "operand 2 must be
an immediate expression `addiu $2,($3)'". However with the way base
expressions are handled this is somewhat tricky to achieve, so I'm leaving
it to a future change.
Maciej
binutils-mips-gas-bignum-range-err.diff
Index: binutils/gas/config/tc-mips.c
===================================================================
--- binutils.orig/gas/config/tc-mips.c 2017-05-12 18:53:29.000000000 +0100
+++ binutils/gas/config/tc-mips.c 2017-05-12 18:54:12.666693817 +0100
@@ -4856,7 +4856,10 @@ match_const_int (struct mips_arg_info *a
*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
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 *
return FALSE;
}
+ if (offset_expr.X_op == O_big)
+ {
+ match_out_of_range (&arg);
+ return FALSE;
+ }
+
relax_char = c;
continue;
}
Index: binutils/gas/testsuite/gas/mips/addiu-error.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/addiu-error.d 2017-05-12 18:54:13.064769532 +0100
@@ -0,0 +1,3 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: addiu-error.l
Index: binutils/gas/testsuite/gas/mips/addiu-error.l
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/addiu-error.l 2017-05-12 18:54:13.220134489 +0100
@@ -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\)\)'
Index: binutils/gas/testsuite/gas/mips/addiu-error.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/addiu-error.s 2017-05-12 18:54:13.317226907 +0100
@@ -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))
Index: binutils/gas/testsuite/gas/mips/break-error.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/break-error.d 2017-05-12 18:54:13.780902075 +0100
@@ -0,0 +1,3 @@
+#name: MIPS BREAK errors
+#as: -32
+#error-output: break-error.l
Index: binutils/gas/testsuite/gas/mips/break-error.l
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/break-error.l 2017-05-12 18:54:13.844984679 +0100
@@ -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\)\)'
Index: binutils/gas/testsuite/gas/mips/break-error.s
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/break-error.s 2017-05-12 18:54:13.859235503 +0100
@@ -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: binutils/gas/testsuite/gas/mips/lui-1.l
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/lui-1.l 2017-05-12 18:30:27.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/lui-1.l 2017-05-12 18:54:13.889662562 +0100
@@ -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'
Index: binutils/gas/testsuite/gas/mips/micromips@addiu-error.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips@addiu-error.d 2017-05-12 18:54:13.978843752 +0100
@@ -0,0 +1,4 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: micromips@addiu-error.l
+#source: addiu-error.s
Index: binutils/gas/testsuite/gas/mips/micromips@addiu-error.l
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/micromips@addiu-error.l 2017-05-12 18:54:14.000595979 +0100
@@ -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: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp 2017-05-12 18:53:29.000000000 +0100
+++ binutils/gas/testsuite/gas/mips/mips.exp 2017-05-12 18:54:14.026108362 +0100
@@ -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"
Index: binutils/gas/testsuite/gas/mips/mips16@addiu-error.d
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16@addiu-error.d 2017-05-12 18:54:14.191127725 +0100
@@ -0,0 +1,4 @@
+#name: MIPS ADDIU errors
+#as: -32
+#error-output: mips16@addiu-error.l
+#source: addiu-error.s
Index: binutils/gas/testsuite/gas/mips/mips16@addiu-error.l
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/mips16@addiu-error.l 2017-05-12 18:54:14.222948364 +0100
@@ -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\)\)'