From a1bf1d187de7dd3a7fb1d688b1faf0d27067dd82 Mon Sep 17 00:00:00 2001 From: Benjamin Oldenburg Date: Fri, 20 Mar 2026 18:49:10 +0700 Subject: [PATCH] arm64-asm.c: reject invalid operands in parse_operand() Previously, parse_operand() would silently accept any unrecognized token and pass it to asm_expr() as an immediate, causing typos like: add x0, x1, xyz ; 'xyz' is not a valid register to be silently assembled as a symbol reference instead of erroring. Now, if a token is not a register, condition code, or valid immediate prefix (#, :, @, $), an error is emitted for identifier tokens. This implements fail-fast behavior for invalid operands, making it easier to catch typos and mistakes in assembly code. --- arm64-asm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arm64-asm.c b/arm64-asm.c index 3936b1e8..8c00a972 100644 --- a/arm64-asm.c +++ b/arm64-asm.c @@ -258,9 +258,15 @@ static void parse_operand(TCCState *s1, Operand *op) /* Immediate or address expression */ if (tok == '#' || tok == ':' || tok == '@' || tok == '$') { next(); + asm_expr(s1, &op->e); + op->type = OP_IM; + } else if (tok >= TOK_IDENT) { + tcc_error("invalid operand '%s'", get_tok_str(tok, &tokc)); + op->type = OP_IM; + } else { + asm_expr(s1, &op->e); + op->type = OP_IM; } - asm_expr(s1, &op->e); - op->type = OP_IM; } /* Parse address operand in brackets [xn, ...] */