[PATCH 3/3] PPC: improve handling of improper "kind-of-register" operands

Jan Beulich jbeulich@suse.com
Mon Jan 12 12:26:02 GMT 2026


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.
---
I would have wanted to use O_register in place of O_illegal, but while
that leads to a better diagnostic, it's only a warning.

--- 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 mailing list