From a5e756e63e170cf69e06be98287528760833aad5 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 25 Apr 2023 11:16:44 +0200 Subject: [PATCH] RISC-V: avoid redundant and misleading/wrong error messages 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". --- gas/config/tc-riscv.c | 9 +++++++++ gas/testsuite/gas/riscv/tprel-add.l | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 160161c3c75..6b7112bc7c7 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -2279,6 +2279,15 @@ my_getSmallExpression (expressionS *ep, bfd_reloc_code_real_type *reloc, && 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; diff --git a/gas/testsuite/gas/riscv/tprel-add.l b/gas/testsuite/gas/riscv/tprel-add.l index 74bb5352971..1378c274d9a 100644 --- 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' -- 2.30.2