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.
This commit is contained in:
Benjamin Oldenburg 2026-03-20 18:49:10 +07:00
parent 95c17cae64
commit a1bf1d187d

View File

@ -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, ...] */