Skip to content

Commit f939cb6

Browse files
committed
Fix asm pointer inputs
1 parent 9886ca5 commit f939cb6

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/asm.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,13 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
362362
let ty = value.layout.gcc_type(self.cx);
363363
let reg_var = self.current_func().new_local(None, ty, "input_register");
364364
reg_var.set_register_name(reg_name);
365-
self.llbb().add_assignment(None, reg_var, value.immediate());
365+
let value = value.immediate();
366+
let value = if value.get_type() != ty {
367+
self.context.new_cast(None, value, ty)
368+
} else {
369+
value
370+
};
371+
self.llbb().add_assignment(None, reg_var, value);
366372

367373
inputs.push(AsmInOperand {
368374
constraint: "r".into(),

tests/run/asm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ fn asm() {
190190
}
191191
assert_eq!((x, y), (8, 8));
192192

193+
// Regression test for <https://github.com/rust-lang/rustc_codegen_gcc/issues/792>
194+
// typed pointer inputs to explicit registers need a cast.
195+
let mut x = 123_i32;
196+
unsafe {
197+
asm!("", in("rdi") &mut x, options(nostack, preserves_flags));
198+
}
199+
assert_eq!(x, 123);
200+
193201
// sysv64 is the default calling convention on unix systems. The rdi register is
194202
// used to pass arguments in the sysv64 calling convention, so this register will be clobbered
195203
#[cfg(unix)]

0 commit comments

Comments
 (0)