Overlapping `memory.copy` (`copy_within`, dst > src) aborts the VM
- Dominant language
- Rust
- Stars
- 115
- Forks
- 84
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 15
Description
Discovered in https://github.com/0xMiden/compiler/pull/1164
## Summary
wasm `memory.copy` (emitted by Rust `slice::copy_within`) has memmove semantics:
overlapping source/destination ranges are valid. The MASM lowering instead calls
a memcpy intrinsic that asserts the ranges do not overlap, so a valid wasm program
aborts at runtime (`assertion failed: source and destination ranges must not
overlap`) while the native build produces the correct memmove result.
## Reproduction
The `mem_overlap` test (currently `#[ignore]`d):
cargo test -p midenc-integration-tests mem_overlap -- --ignored
Contributor guide
Research direction
The issue is in the MASM lowering for the `memory.copy` instruction. Look at the code that handles this instruction, likely in a code generation or lowering module. The failing test `mem_overlap` in the integration tests provides a reproduction. Run the test to see the assertion failure, then find and replace the memcpy intrinsic with a proper memmove implementation. Verify by running the test after the fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100