# llvm: add safety-check for Wasm memcpy · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/836f9fceab03c7de56eba7a9c2e810206e7e8469)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 836f9fceab03c7de56eba7a9c2e810206e7e8469

Requested commit: 836f9fceab03c7de56eba7a9c2e810206e7e8469

Commit: 836f9fceab03c7de56eba7a9c2e810206e7e8469

Tree: 216e3c7486d9c2f3aae0ab14848ad1c0cf94201e

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
llvm: add safety-check for Wasm memcpy

When lowering the `memcpy` instruction, LLVM will lower it to WebAssembly's
`memory.copy` instruction when the bulk-memory feature is enabled. This
instruction will trap when the destination or source pointer is out-of-bounds.
By Zig's semantics, it is valid to have an invalid pointer when the length is 0.
To prevent runtimes from trapping, we add a safety-check for slices to only
lower to a memcpy instruction when the length is larger than 0.

```

## Parents

- [89396ff02ba235592641fb388e3958c2c047e728](https://git.cafe/gitcafe/zig/commit/89396ff02ba235592641fb388e3958c2c047e728?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/836f9fceab03c7de56eba7a9c2e810206e7e8469?format=markdown)
