# Safely reading uninitialized memory

**URL:** <https://internals.rust-lang.org/t/safely-reading-uninitialized-memory/7287>\
**Category:** Uncategorized\
**Created:** [April 11, 2018, 3:26am UTC](https://internals.rust-lang.org/t/safely-reading-uninitialized-memory/7287 "2018-04-11T03:26:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [April 11, 2018, 4:02am UTC](https://internals.rust-lang.org/t/safely-reading-uninitialized-memory/7287/4 "2018-04-11T04:02:07Z")

</div>

> [@canndrew](#):
>
> It doesn’t seem like it’s possible to implement this data structure in Rust because reading uninitialized bytes is always undefined behaviour.

Hmm, so reading uninitialized values in LLVM isn't UB; it's `undef` ([LLVM Language Reference Manual — LLVM 18.0.0git documentation](http://llvm.org/docs/LangRef.html#undefined-values)). But that doesn't save you, I don't think. In the code from the paper,

```rust
is-member(i):
    return sparse[i] < n && dense[sparse[i]] == i

```

I think that if `sparse[i]` is potentially `undef`, so that whole expression can probably become undef, since the guard just becomes undef.

I think what you need is `freeze`, which has been talked about for LLVM but I don't think it exists yet.

---

_[View the full topic](https://internals.rust-lang.org/t/safely-reading-uninitialized-memory/7287)._
