arm64-asm.c: reject invalid registers in address operands

parse_addr_operand() silently accepted invalid register names like
[xyz] without error. Now explicitly validates the register and calls
tcc_error() if arm64_parse_regvar() returns -1 or >= 32.

Before: invalid registers caused silent wrong code or confusing errors
After: clear error message 'invalid register in address operand'
This commit is contained in:
Benjamin Oldenburg 2026-03-20 19:59:27 +07:00
parent a702dcce9e
commit 7fe9c22cf2

View File

@ -293,17 +293,19 @@ static void parse_addr_operand(TCCState *s1, Operand *op)
skip('[');
reg = arm64_parse_regvar(tok);
if (reg >= 0 && reg < 32) {
op->reg = reg;
op->reg_tok = tok;
if (reg < 0 || reg >= 32) {
tcc_error("invalid register in address operand");
return;
}
op->reg = reg;
op->reg_tok = tok;
next();
/* Check for offset */
if (tok == ',') {
next();
/* Check for offset */
if (tok == ',') {
if (tok == '#' || tok == '@' || tok == '$')
next();
if (tok == '#' || tok == '@' || tok == '$')
next();
asm_expr(s1, &op->e);
}
asm_expr(s1, &op->e);
}
skip(']');
if (tok == '!') {