diff options
author | Maciej W. Rozycki <macro@imgtec.com> | 2017-05-15 13:17:18 +0100 |
---|---|---|
committer | Maciej W. Rozycki <macro@imgtec.com> | 2017-05-15 13:57:09 +0100 |
commit | c96425c560d640df9c416ff4e6a8c49c1f3b1119 (patch) | |
tree | 88912e125b86687f549c886d5042bf262463a635 | |
parent | 1a7bf198b67c4b99e9adeaeba38c6874ec354c12 (diff) | |
download | gdb-c96425c560d640df9c416ff4e6a8c49c1f3b1119.zip gdb-c96425c560d640df9c416ff4e6a8c49c1f3b1119.tar.gz gdb-c96425c560d640df9c416ff4e6a8c49c1f3b1119.tar.bz2 |
MIPS/GAS: Improve bignum operand error diagnostics
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.
-rw-r--r-- | gas/ChangeLog | 22 | ||||
-rw-r--r-- | gas/config/tc-mips.c | 17 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/addiu-error.d | 3 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/addiu-error.l | 8 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/addiu-error.s | 11 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/break-error.d | 3 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/break-error.l | 8 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/break-error.s | 11 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/lui-1.l | 2 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/micromips@addiu-error.d | 4 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/micromips@addiu-error.l | 8 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/mips.exp | 2 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/mips16@addiu-error.d | 4 | ||||
-rw-r--r-- | gas/testsuite/gas/mips/mips16@addiu-error.l | 8 |
14 files changed, 109 insertions, 2 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index 544ff7a..afbb20e 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,27 @@ 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 OT_INTEGER check before the `match_expression' call. * testsuite/gas/mips/mips16-insn-e.l: Adjust messages. diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index ac4fefd..9fde462 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -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 index 0000000..13a99ac --- /dev/null +++ b/gas/testsuite/gas/mips/addiu-error.d @@ -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 index 0000000..1dc0014 --- /dev/null +++ b/gas/testsuite/gas/mips/addiu-error.l @@ -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 index 0000000..1e19ea8 --- /dev/null +++ b/gas/testsuite/gas/mips/addiu-error.s @@ -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 index 0000000..2110814 --- /dev/null +++ b/gas/testsuite/gas/mips/break-error.d @@ -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 index 0000000..2759a91 --- /dev/null +++ b/gas/testsuite/gas/mips/break-error.l @@ -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 index 0000000..f5ac225 --- /dev/null +++ b/gas/testsuite/gas/mips/break-error.s @@ -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)) diff --git a/gas/testsuite/gas/mips/lui-1.l b/gas/testsuite/gas/mips/lui-1.l index 8bf621d..d6cb98a 100644 --- a/gas/testsuite/gas/mips/lui-1.l +++ b/gas/testsuite/gas/mips/lui-1.l @@ -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 index 0000000..0313261 --- /dev/null +++ b/gas/testsuite/gas/mips/micromips@addiu-error.d @@ -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 index 0000000..1527ead --- /dev/null +++ b/gas/testsuite/gas/mips/micromips@addiu-error.l @@ -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\)\)' diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index de38a1c..c9559df 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -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 index 0000000..67b4611 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16@addiu-error.d @@ -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 index 0000000..c7fd7c9 --- /dev/null +++ b/gas/testsuite/gas/mips/mips16@addiu-error.l @@ -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\)\)' |