From 85314cc8e0506fa14fc1da3a2af57cd1ad206b7b Mon Sep 17 00:00:00 2001 From: fw Date: Thu, 2 Oct 2025 16:02:29 -0400 Subject: [PATCH 1/2] transpile: assembly: use () rather than [] for indirect operands with AT&T syntax --- c2rust-transpile/src/translator/assembly.rs | 12 ++++++++++-- .../snapshots__transpile-x86_64@vm_x86.c.snap | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/c2rust-transpile/src/translator/assembly.rs b/c2rust-transpile/src/translator/assembly.rs index 93093319dd..6111562501 100644 --- a/c2rust-transpile/src/translator/assembly.rs +++ b/c2rust-transpile/src/translator/assembly.rs @@ -559,6 +559,7 @@ fn tied_output_operand_idx( /// {0:y} (and wrapping mem-only references in square brackets). fn rewrite_asm bool, M: Fn(usize) -> usize>( asm: &str, + att_syntax: bool, input_op_mapper: M, is_mem_only: F, arch: Arch, @@ -647,7 +648,10 @@ fn rewrite_asm bool, M: Fn(usize) -> usize>( } let mem_only = is_mem_only(index_str); // Push the reference wrapped in {}, or in [{}] if mem-only - out.push_str(if mem_only { "[{" } else { "{" }); + if mem_only { + out.push(if att_syntax { '(' } else { '[' }); + }; + out.push('{'); let idx: usize = index_str .parse() .map_err(|_| TranslationError::generic("could not parse operand idx"))?; @@ -656,7 +660,10 @@ fn rewrite_asm bool, M: Fn(usize) -> usize>( out.push(':'); out.push_str(&new_modifiers); } - out.push_str(if mem_only { "}]" } else { "}" }); + out.push('}'); + if mem_only { + out.push(if att_syntax { ')' } else { ']' }); + }; // Push the rest of the chunk out.push_str(&chunk[end_idx..]); continue; @@ -832,6 +839,7 @@ impl<'c> Translation<'c> { // Rewrite arg references in assembly template let rewritten_asm = rewrite_asm( asm, + att_syntax, |idx: usize| { new_idx_for_orig(tied_output_operand_idx(idx, outputs.len(), &tied_operands)) }, diff --git a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap index 450f09c289..5819e9a938 100644 --- a/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap +++ b/c2rust-transpile/tests/snapshots/snapshots__transpile-x86_64@vm_x86.c.snap @@ -58,7 +58,7 @@ pub unsafe extern "C" fn VM_CallCompiled( *opStack = 0 as core::ffi::c_int; opStackOfs = 0 as core::ffi::c_int; asm!( - "movq [{2}], %rax\n", "movq [{0}], %r8\n", "movq [{1}], %r9\n", "push %r15\n", + "movq ({2}), %rax\n", "movq ({0}), %r8\n", "movq ({1}), %r9\n", "push %r15\n", "push %r14\n", "push %r13\n", "push %r12\n", "callq *%rax\n", "pop %r12\n", "pop %r13\n", "pop %r14\n", "pop %r15\n", "\n", "mov {restmp0:x}, %bx\n", in (reg) & (* vm).instructionPointers, in (reg) & (* vm).dataBase, in (reg) & From 76b81e34a080c977ad1f55b2a7cd19a0bf689fe4 Mon Sep 17 00:00:00 2001 From: fw Date: Wed, 1 Oct 2025 18:04:28 -0400 Subject: [PATCH 2/2] ci: run testsuite python2 transpilation users have run into issues with the testsuite's python2, so we should test it in CI more coverage is better, and it's not clear why this wasn't being included before --- .github/workflows/internal-testsuite.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/internal-testsuite.yml b/.github/workflows/internal-testsuite.yml index a69b219206..149509d0f2 100644 --- a/.github/workflows/internal-testsuite.yml +++ b/.github/workflows/internal-testsuite.yml @@ -96,8 +96,11 @@ jobs: sudo apt-get -qq install \ build-essential \ libbrotli-dev \ + libbz2-dev \ libclang-${{ matrix.clang-version }}-dev \ + libdb-dev \ libgcrypt20 \ + libgdbm-dev \ libreadline-dev \ libidn2-dev \ libldap2-dev \ @@ -111,6 +114,8 @@ jobs: python3-setuptools \ python3-wheel \ rcs \ + tcl-dev \ + tk-dev \ zlib1g-dev # installs intercept-build to $HOME/.local/bin @@ -130,7 +135,7 @@ jobs: find testsuite -type f -name compile_commands.json -delete export PATH=$PWD/target/release:$HOME/.local/bin:$PATH echo "PATH=$PATH" - python3 testsuite/test.py curl json-c lua nginx zstd libxml2 + python3 testsuite/test.py curl json-c lua nginx zstd libxml2 python2 - uses: actions/upload-artifact@v4 with: