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

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

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

Visibility: public

Requested revision: d54ebf4356eaeeab4d256d0da4f81678226f81a6

Requested commit: d54ebf4356eaeeab4d256d0da4f81678226f81a6

Commit: d54ebf4356eaeeab4d256d0da4f81678226f81a6

Tree: 69129636312bc7c8fa02db2ad63f7cbaa74e1959

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

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

When lowering the `memset` instruction, LLVM will lower it to WebAssembly's
`memory.fill` instruction when the bulk-memory feature is enabled. This
instruction will trap when the destination address 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 memset instruction when the length is larger than 0.

```

## Parents

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

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