[PATCH] D158081: [IR] Add writable attribute

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 01:13:20 PDT 2023


nikic added a comment.

In D158081#4594615 <https://reviews.llvm.org/D158081#4594615>, @RalfJung wrote:

>> For that reason the writable attribute is specified to perform a spurious store of dereferenceable bytes on function entry.
>
> That makes a lot of sense; FWIW I also don't know any better way to specify the regular `dereferenceable` attribute (i.e., as spurious reads). In particular those accesses are relevant for `noalias`. See here <https://github.com/rust-lang/unsafe-code-guidelines/issues/435> for me exploring this in the Rust context.
>
> For this particular attribute however, just to be sure: it is still the responsibility of the optimization to ensure that the spuriously written value does not cause wrong results elsewhere, right? In other words, an empty function with a pointer argument that is 4-byte writeable can *not* just get a spurious store of `0`, since someone might actually look at that memory after the function returns and they would be able to see the difference?

That's right. The attribute always allows you to introduce `*p = *p` on function entry (in conjunction with dereferenceable), but introducing `*p = 0` would require you to prove that this does not change observable behavior (e.g. because you're moving up a later `*p = 0` store and there are no reads/unwinds in between). Another caveat is that once you move away from function entry, you also need to ensure that the pointer does not escape to a different thread.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158081/new/

https://reviews.llvm.org/D158081



More information about the llvm-commits mailing list