Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ pub mod intrinsics {
#[rustc_intrinsic]
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
#[rustc_intrinsic]
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
#[rustc_intrinsic]
pub unsafe fn transmute<T, U>(e: T) -> U;
#[rustc_intrinsic]
pub unsafe fn ctlz_nonzero<T>(x: T) -> u32;
Expand Down
7 changes: 7 additions & 0 deletions src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
);
return Ok(());
}
sym::copy | sym::copy_nonoverlapping | sym::write_bytes => {
let ty = fn_args.type_at(0);
if self.layout_of(ty).size.bytes() == 0 {
return Ok(());
}
return Err(Instance::new_raw(instance.def_id(), instance.args));
}
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not change the memset, memcpy and memmove methods on Builder? Also this only helps with ZST types, not with copying zero elements.

View changes since the review

sym::breakpoint => {
unimplemented!();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/run/zero_sized_mem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Compiler:
//
// Run-time:
// status: 0

#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]

extern crate mini_core;
use mini_core::*;

#[inline(never)]
unsafe fn zero_sized_mem_ops(count: usize) {
let src = 0usize as *const ();
let dst = 0usize as *mut ();

intrinsics::copy_nonoverlapping(src, dst, count);
intrinsics::copy(src, dst, count);
intrinsics::write_bytes(dst, 0xab, count);
}

#[no_mangle]
extern "C" fn main(_argc: i32, _argv: *const *const u8) -> i32 {
unsafe { zero_sized_mem_ops(1) };
0
}
Loading