From 738855bb58c1b27aa7ceeddaadbdeb373baf686f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:29 +0300 Subject: [PATCH] checker: asm bad operand with opcode error (fixes #10708) --- vlib/v/checker/checker.v | 15 +++++++++++++++ .../tests/asm_mov_requires_two_operands.out | 7 +++++++ .../tests/asm_mov_requires_two_operands.vv | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 vlib/v/checker/tests/asm_mov_requires_two_operands.out create mode 100644 vlib/v/checker/tests/asm_mov_requires_two_operands.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0b9ad2647..620b1162c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3883,6 +3883,11 @@ fn (mut c Checker) asm_stmt(mut stmt ast.AsmStmt) { 'string', 'asciz', 'ascii'] { // all tcc-supported assembler directives c.error('unknown assembler directive: `${template.name}`', template.pos) } + } else if expected_operands := asm_expected_operand_count(stmt.arch, template.name) { + if template.args.len != expected_operands { + c.error('asm instruction `${template.name}` expects ${expected_operands} operands, but got ${template.args.len}', + template.pos) + } } for mut arg in template.args { c.asm_arg(arg, stmt, aliases) @@ -3893,6 +3898,16 @@ fn (mut c Checker) asm_stmt(mut stmt ast.AsmStmt) { } } +fn asm_expected_operand_count(arch pref.Arch, name string) ?int { + if arch !in [.amd64, .i386] { + return none + } + return match name { + 'mov' { 2 } + else { none } + } +} + fn (mut c Checker) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt, aliases []string) { match arg { ast.AsmAlias {} diff --git a/vlib/v/checker/tests/asm_mov_requires_two_operands.out b/vlib/v/checker/tests/asm_mov_requires_two_operands.out new file mode 100644 index 000000000..03ee36534 --- /dev/null +++ b/vlib/v/checker/tests/asm_mov_requires_two_operands.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/asm_mov_requires_two_operands.vv:3:3: error: asm instruction `mov` expects 2 operands, but got 0 + 1 | fn main() { + 2 | asm amd64 { + 3 | mov + | ~~~ + 4 | } + 5 | } diff --git a/vlib/v/checker/tests/asm_mov_requires_two_operands.vv b/vlib/v/checker/tests/asm_mov_requires_two_operands.vv new file mode 100644 index 000000000..a92c0c582 --- /dev/null +++ b/vlib/v/checker/tests/asm_mov_requires_two_operands.vv @@ -0,0 +1,5 @@ +fn main() { + asm amd64 { + mov + } +} -- 2.39.5