From 4e8b24694bb265d29826ae38c87d9467c3267e11 Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 9 Aug 2025 15:14:06 +0800 Subject: [PATCH] cgen: fix asm stmt separators (#25067) --- vlib/v/gen/c/cgen.v | 2 +- .../assembly/stmt_separator_test.amd64.v | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 vlib/v/slow_tests/assembly/stmt_separator_test.amd64.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 5de6961a2..2972cfbd3 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3255,7 +3255,7 @@ fn (mut g Gen) asm_stmt(stmt ast.AsmStmt) { } if !template.is_label { - g.write(';') + g.write('\\n\\t') } g.writeln('"') } diff --git a/vlib/v/slow_tests/assembly/stmt_separator_test.amd64.v b/vlib/v/slow_tests/assembly/stmt_separator_test.amd64.v new file mode 100644 index 000000000..1216ee78c --- /dev/null +++ b/vlib/v/slow_tests/assembly/stmt_separator_test.amd64.v @@ -0,0 +1,48 @@ +import os +import time + +const asm_file_content = ' +fn asm_fn() { + mut x := u64(0) + mut y := u64(0) + mut z := u64(0) + mut hi := u64(0) + mut lo := u64(0) + asm amd64 { + mulq rdx + addq rax, z + adcq rdx, 0 + ; =a (lo) + =d (hi) + ; a (x) + d (y) + r (z) + ; cc + } +} + +fn main() { + asm_fn() +} +' + +const vexe = os.getenv('VEXE') +const v_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.amd64.v') +const genexe_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe') +const c_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe.tmp.c') + +fn test_stmt_separator() { + os.write_file(v_file, asm_file_content)! + eprintln('Compiling...') + compile_cmd := '${os.quoted_path(vexe)} -cg -skip-running -no-rsp -keepc -o ${os.quoted_path(genexe_file)} ${os.quoted_path(v_file)}' + eprintln('> compile_cmd: ${compile_cmd}') + time.sleep(1000 * time.millisecond) // improve chances of working on windows + compile_res := os.system(compile_cmd) + assert compile_res == 0 + + content := os.read_file(c_file)! + os.rm(v_file)! + os.rm(genexe_file)! + os.rm(c_file)! + assert content.contains(r'addq %[z], %%rax\n\t') +} -- 2.39.5