[v2,3/7] RISC-V: avoid redundant and misleading/wrong error messages

Message ID 5352e5fd-d1c5-4267-c802-73d6074e80ca@suse.com
State Accepted
Headers
Series RISC-V/gas: insn operand parsing |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Jan Beulich March 10, 2023, 9:26 a.m. UTC
  The use of a wrong (for the insn) relocation operator (or a future one
which simply isn't recognized by older gas yet) doesn't render the (rest
of the) expression "bad". Furthermore alongside the error from
expression() in most cases the parser would emit another error then
anyway. Suppress the call to my_getExpression() in such a case,
arranging for a guaranteed subsequent error message by marking the
expression "illegal".
---
Of course superfluous "bad expression" errors remain for format
specifiers where my_getExpression() is used directly. I guess once the
GPR special casing has disappeared from my_getSmallExpression() (see
"RISC-V: adjust logic to avoid register name symbols"), both functions
could be folded (which would also eliminate the unclear split between
when which of the two is used).
---
v2: New.
  

Patch

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -2265,6 +2265,15 @@  my_getSmallExpression (expressionS *ep,
 	 && reloc_index < 1
 	 && parse_relocation (&str, reloc, percent_op));
 
+  if (*str == '%')
+    {
+       /* expression() will choke on anything looking like an (unrecognized)
+	  relocation specifier.  Don't even call it, avoiding multiple (and
+	  perhaps redundant) error messages; our caller will issue one.  */
+       ep->X_op = O_illegal;
+       return 0;
+    }
+
   my_getExpression (ep, crux);
   str = expr_parse_end;
 
--- a/gas/testsuite/gas/riscv/tprel-add.l
+++ b/gas/testsuite/gas/riscv/tprel-add.l
@@ -1,4 +1,3 @@ 
 .*: Assembler messages:
-.*: Error: bad expression
 .*: Error: illegal operands `amoadd.w x8,x9,%tprel_add\(i\)\(x10\)'
 .*: Error: illegal operands `add a5,a5,tp,0'