# Rules for alignment and non-NULLness of references

**URL:** <https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430>\
**Category:** Unsafe Code Guidelines\
**Created:** [June 23, 2017, 3:51am UTC](https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430 "2017-06-23T03:51:58Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [July 15, 2017, 11:59pm UTC](https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430/21 "2017-07-15T23:59:30Z")

</div>

> [@scottmcm](#):
>
> Hmm, but if the @llvm.memcpy call states an alignment (greater than one), LLVM is presumably allowed to optimize under the assumption that the alignment is correct, so even though nothing is read it might still be UB.

True. It would be helpful to know when and where exactly LLVM starts making alignment assumptions (in the IR generated by rustc) -- then we could define Rust's alignment assumptions accordingly. Currently miri does not check empty accesses, but it does check on every `&` -- which can't be entirely right, because you are supposed to be able to do `&unaligned.field as *const _`.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:28am UTC](https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430/22 "2019-03-25T08:28:41Z")

</div>

Closed on March 25, 2019, 8:28am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

[Previous page](https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430.md?page=1)
