[binutils-gdb] PPC: improve handling of improper "kind-of-register" operands
Jan Beulich
jbeulich@sourceware.org
Fri Feb 27 07:03:53 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e80ac000da58023b89e499a56ccc6c41098c4e95
commit e80ac000da58023b89e499a56ccc6c41098c4e95
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri Feb 27 08:00:05 2026 +0100
PPC: improve handling of improper "kind-of-register" operands
A unary % is expected to be followed by a register. While this is being
diagnosed as "bad expression", a 2nd error then follows ("syntax error;
found ..."). Consume the % in md_operand() (thus preventing it to be
treated as modulus with missing [i.e. implicitly 0] leading operand) and
mark the expression O_illegal (thus avoiding the "bad expression") when
the "register" is unrecognized.
Reviewed-by: Peter Bergner <bergner@tenstorrent.com>
Diff:
---
gas/config/tc-ppc.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index 396b0232816..a5dbc73386a 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -821,11 +821,16 @@ md_operand (expressionS *expressionP)
char *start;
char c;
- if (input_line_pointer[0] != '%' || !ISALPHA (input_line_pointer[1]))
+ if (input_line_pointer[0] != '%')
return;
+ if (!ISALPHA (*++input_line_pointer))
+ {
+ expressionP->X_op = O_illegal;
+ return;
+ }
+
start = input_line_pointer;
- ++input_line_pointer;
c = get_symbol_name (&name);
reg = reg_name_search (pre_defined_registers,
@@ -839,7 +844,10 @@ md_operand (expressionS *expressionP)
expressionP->X_md = reg->flags;
}
else
- input_line_pointer = start;
+ {
+ expressionP->X_op = O_illegal;
+ input_line_pointer = start;
+ }
}
/* Whether to do the special parsing. */
@@ -3443,10 +3451,18 @@ md_assemble (char *str)
resolve_register (&ex);
if (ex.X_op == O_illegal)
- as_bad (_("illegal operand"));
- else if (ex.X_op == O_absent)
- as_bad (_("missing operand"));
- else if (ex.X_op == O_register)
+ {
+ as_bad (_("illegal operand"));
+ break;
+ }
+
+ if (ex.X_op == O_absent)
+ {
+ as_bad (_("missing operand"));
+ break;
+ }
+
+ if (ex.X_op == O_register)
{
if ((ex.X_md
& ~operand->flags
More information about the Binutils-cvs
mailing list