Skip to content

Commit 4bb0ddf

Browse files
committed
transpile: Use raw borrows in assembly translations
1 parent 6aefbd3 commit 4bb0ddf

5 files changed

Lines changed: 20 additions & 17 deletions

c2rust-transpile/src/translator/assembly.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,8 @@ impl<'c> Translation<'c> {
883883
// c2rust-ast-exporter added it (there's no gcc equivalent);
884884
// in this case, we need to do what clang does and pass in
885885
// the operand by-address instead of by-value
886-
out_expr = mk().mutbl().borrow_expr(out_expr);
886+
self.use_feature("raw_ref_op");
887+
out_expr = mk().mutbl().raw_borrow_expr(out_expr);
887888
}
888889

889890
if let Some(_tied_operand) = tied_operands.get(&(output_idx, true)) {
@@ -895,12 +896,13 @@ impl<'c> Translation<'c> {
895896
// type conversions into the `c2rust-asm-casts` crate,
896897
// so we call into that one from here.
897898

898-
// Convert `x` into `let freshN = &mut x; *x`
899+
// Convert `x` into `let freshN = &raw mut x; *x`
900+
self.use_feature("raw_ref_op");
899901
let output_name = self.renamer.borrow_mut().fresh();
900902
let output_local = mk().local(
901903
mk().ident_pat(&output_name),
902904
None,
903-
Some(mk().mutbl().borrow_expr(out_expr)),
905+
Some(mk().mutbl().raw_borrow_expr(out_expr)),
904906
);
905907
stmts.push(mk().local_stmt(Box::new(output_local)));
906908

@@ -924,7 +926,8 @@ impl<'c> Translation<'c> {
924926
let mut in_expr = in_expr.into_value();
925927

926928
if operand.mem_only {
927-
in_expr = mk().borrow_expr(in_expr);
929+
self.use_feature("raw_ref_op");
930+
in_expr = mk().raw_borrow_expr(in_expr);
928931
}
929932
if let Some(tied_operand) = tied_operands.get(&(input_idx, false)) {
930933
self.use_crate(ExternCrate::C2RustAsmCasts);

c2rust-transpile/tests/snapshots/snapshots__transpile@asm.c.2021.x86_64.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ expression: cat tests/snapshots/arch-specific/asm.2021.x86_64.rs
1111
unused_mut
1212
)]
1313
#![deny(unsafe_op_in_unsafe_fn)]
14-
#![feature(asm)]
14+
#![feature(asm, raw_ref_op)]
1515
use ::c2rust_asm_casts::AsmCastTrait;
1616
use ::core::arch::asm;
1717
#[no_mangle]
1818
pub unsafe extern "C" fn six() -> ::core::ffi::c_int {
1919
unsafe {
2020
let mut out: ::core::ffi::c_int = 0 as ::core::ffi::c_int;
2121
let mut six_0: ::core::ffi::c_int = 6 as ::core::ffi::c_int;
22-
let c2rust_fresh0 = &mut out;
22+
let c2rust_fresh0 = &raw mut out;
2323
let c2rust_fresh1;
2424
let c2rust_fresh2 = out;
2525
asm!(

c2rust-transpile/tests/snapshots/snapshots__transpile@asm.c.2024.x86_64.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub unsafe extern "C" fn six() -> ::core::ffi::c_int {
1818
unsafe {
1919
let mut out: ::core::ffi::c_int = 0 as ::core::ffi::c_int;
2020
let mut six_0: ::core::ffi::c_int = 6 as ::core::ffi::c_int;
21-
let c2rust_fresh0 = &mut out;
21+
let c2rust_fresh0 = &raw mut out;
2222
let c2rust_fresh1;
2323
let c2rust_fresh2 = out;
2424
asm!(

c2rust-transpile/tests/snapshots/snapshots__transpile@vm_x86.c.2021.x86_64.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ pub unsafe extern "C" fn VM_CallCompiled(
6464
"movq ({2}), %rax\n", "movq ({0}), %r8\n", "movq ({1}), %r9\n",
6565
"push %r15\n", "push %r14\n", "push %r13\n", "push %r12\n", "callq *%rax\n",
6666
"pop %r12\n", "pop %r13\n", "pop %r14\n", "pop %r15\n", "\n",
67-
"mov {restmp0:x}, %bx\n", in (reg) & (* vm).instructionPointers, in (reg) &
68-
(* vm).dataBase, in (reg) & entryPoint, restmp0 = inlateout(reg) opStackOfs,
69-
inlateout("di") opStack, inlateout("si") programStack, out("rax") _,
70-
out("rcx") _, out("rdx") _, out("r8") _, out("r9") _, out("r10") _,
71-
out("r11") _, options(att_syntax)
67+
"mov {restmp0:x}, %bx\n", in (reg) & raw const (* vm).instructionPointers, in
68+
(reg) & raw const (* vm).dataBase, in (reg) & raw const entryPoint, restmp0 =
69+
inlateout(reg) opStackOfs, inlateout("di") opStack, inlateout("si")
70+
programStack, out("rax") _, out("rcx") _, out("rdx") _, out("r8") _,
71+
out("r9") _, out("r10") _, out("r11") _, options(att_syntax)
7272
);
7373
if opStackOfs != 1 as ::core::ffi::c_int
7474
|| *opStack as ::core::ffi::c_uint != 0xdeadbeef as ::core::ffi::c_uint

c2rust-transpile/tests/snapshots/snapshots__transpile@vm_x86.c.2024.x86_64.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ pub unsafe extern "C" fn VM_CallCompiled(
6363
"movq ({2}), %rax\n", "movq ({0}), %r8\n", "movq ({1}), %r9\n",
6464
"push %r15\n", "push %r14\n", "push %r13\n", "push %r12\n", "callq *%rax\n",
6565
"pop %r12\n", "pop %r13\n", "pop %r14\n", "pop %r15\n", "\n",
66-
"mov {restmp0:x}, %bx\n", in (reg) & (* vm).instructionPointers, in (reg) &
67-
(* vm).dataBase, in (reg) & entryPoint, restmp0 = inlateout(reg) opStackOfs,
68-
inlateout("di") opStack, inlateout("si") programStack, out("rax") _,
69-
out("rcx") _, out("rdx") _, out("r8") _, out("r9") _, out("r10") _,
70-
out("r11") _, options(att_syntax)
66+
"mov {restmp0:x}, %bx\n", in (reg) & raw const (* vm).instructionPointers, in
67+
(reg) & raw const (* vm).dataBase, in (reg) & raw const entryPoint, restmp0 =
68+
inlateout(reg) opStackOfs, inlateout("di") opStack, inlateout("si")
69+
programStack, out("rax") _, out("rcx") _, out("rdx") _, out("r8") _,
70+
out("r9") _, out("r10") _, out("r11") _, options(att_syntax)
7171
);
7272
if opStackOfs != 1 as ::core::ffi::c_int
7373
|| *opStack as ::core::ffi::c_uint != 0xdeadbeef as ::core::ffi::c_uint

0 commit comments

Comments
 (0)