[llvm-dev] nocapture: affects aliasing or also numerical value?

Ariel Ben-Yehuda via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 29 09:59:01 PDT 2017


Hi,

I have a question about the meaning of the nocapture attribute:

In Rust, safe code can use pointers as, say, HashMap keys (by
reference equality) without regard to their lifetimes - of course, a
dead pointer might be reference-equal to other pointers, but users
should not face any other trouble with that (of course, dead pointers
can't be dereferenced).

Rust also has "anonymous &T" arguments, which are pointers that can't
be dereferenced after the function returns. However, because pointers
can be used as HashMap keys without regard to their lifetimes, their
identity can be inserted into an HashMap.

Now, we want to transfer this information to LLVM, which is quite
similar to the `nocapture` attribute.

However, according to the documentation for `nocapture`, "This
indicates that the callee does not make any copies of the pointer that
outlive the callee itself.".

This might mean that the pointer becomes some sort of indeterminate
value after the function returns - aka using it as a HashMap key would
be trouble. Or it could just mean that the pointer can't be
dereferenced after the function returns, which is the Rust semantics.

Does `nocapture` have Rust-compatible semantics, and if not, is there
some other way to emulate these semantics?

Thanks,
 - Ariel


More information about the llvm-dev mailing list