-
Notifications
You must be signed in to change notification settings - Fork 13.3k
LLVM nocapture
attribute is used incorrectly
#137668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This example depends on the pointer address. But recently LLVM has started separating “address capture” from “provenance capture” — I think it’s correct to say the latter isn’t captured here, meaning that any pointer to |
Yes, I believe making these |
(Tagging this as unsound but feel free to readjust/reprioritize) |
Is this something that can be taken care upon upgrading to LLVM 21 or better discuss this earlier? I've tried digging a bit but I'm a bit unsure about the details: is indirect_pass_mode nightly-only? A git blame seem to indicate that that code was touched years ago (so I think it's ok to not consider this a regression). thanks |
This issue isn't nightly only. In fact, it has been known for a long time (I'm pretty sure we already have an issue for it somewhere, but I couldn't find it). As far as I know, the only thing this affects is ability to observe whether an intermediate copy has been optimized away, it doesn't allow you to do anything beyond that (like modify the memory of the original, as that would be UB due to reference semantics). |
Cc @rust-lang/opsem FWIW the intent I have with the operational semantics is that the assertion failure is a legal outcome here -- see the discussion in rust-lang/unsafe-code-guidelines#416 and #71117. However, it is so far unclear how that could be achieved. The unsoundness is the |
Note that the function can capture the provenance of this pointer, too. We are trying to make it so that that provenance ceases to be valid when the function returns, but that turns out to be in conflict with copy propagation (rust-lang/unsafe-code-guidelines#556). |
Can you give an example where captured pointer is used after the function returns? I thought it would be impossible to capture provenance through that argument (so that it remains valid to access) because either memory is temporary or protected.
Do we have a rust issue for miscompilation in the first example? |
You just As I mentioned, the provenance you get that way is invalid once the function returns, though the system we use to ensure that is causing problems (rust-lang/unsafe-code-guidelines#556).
Is it a miscompilation? This seems like an optimization we want to allow, so it's more of a spec bug. Now, whether that spec bug can be solved without other compromises is unclear... |
The implementation of
indirect_pass_mode
contains following code:The claim that a callee can't possibly capture the argument is incorrect. The callee can obtain the address of the parameter and use it in arbitrary way. Consider the following example. In the call to
f
,b
is an address of a staticS
, whose memory should be disjoint from parametera
. Consequentlyf
should returnfalse
:The text was updated successfully, but these errors were encountered: