]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PPC: improve handling of improper "kind-of-register" operands
authorJan Beulich <jbeulich@suse.com>
Fri, 27 Feb 2026 07:00:05 +0000 (08:00 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 27 Feb 2026 07:00:05 +0000 (08:00 +0100)
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>
gas/config/tc-ppc.c

index 396b0232816d68584dd04447e0b17bac4fa99dc1..a5dbc73386a4badd418ec8bc01024d610900a408 100644 (file)
@@ -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