-
Notifications
You must be signed in to change notification settings - Fork 58
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
Can we weaken the requirements for offset
? (Was: Should we / can we make all "getelementptr inbounds" into "getelementptr nowrap"?)
#350
Comments
Just saying "you can't wrap the address space" is extremely teachable. |
I always thought this was as much about aliasing information as anything. Is |
Yeah two pointers that each point to a separate stack object still can't index oob and access each other because they'd have separate provenance. |
If GEP was replaced by an untyped "pointer offset with integer dot product" operation (i.e. a sequence of constant strides and runtime indices, to cover the "nested arrays" case, if they do want to keep it as one instruction), it would be great to reuse (NUW/NSW standing for "No Unsigned/Signed Wrap", i.e. opting into to unsigned/signed overflow being UB) Alternatively, if LLVM had |
Even on the LLVM side there seems to be some desire for a |
I learned in the mean time that |
offset
? (Was: Should we / can we make all "getelementptr inbounds" into "getelementptr nowrap"?)
We had a t-opsem meeting on this subject; see rust-lang/opsem-team#10 for a summary:
|
The "inbounds" semantics of
offset
are notoriously tricky and confusing. From what I hear from @nikic, the "inbounds" part of them is also not nearly as useful as one might think, and the main payoff is being sure that the pointer is not wrapped around either end of the address space.So... is there a chance that we could significantly simplify the language at acceptable cost for analyses by changing the rules of
offset
(and all other "inbounds" offsets that the language does implicitly, like when applying place projections) such that the only case of UB here is overflow wrapping around the address space (both below0
and aboveusize::MAX
)? I think that would be great, but of course we have to be careful not to give up too much information here. (That said, we do have a ton of information of the form "this pointer is dereferenceable for size N", which conveys bounds information much more directly thangetelementptr inbounds
.)However, we'd probably need LLVM support for this, adding some sort of
getelementptr nowrap
. (There is the possible alternative of using plaingetelementptr
, and upgrading that toinbounds
whenever we can derive from other information that the pointer is indeed dereferenceable for a sufficiently large memory range. I am not sure how tricky that would be to implement though.)So I wonder, @nikic, do you think that would be a reasonable and realistic option? And everyone, do you think that would be a reasonable semantics to shoot for?
In particular, this would resolve #299.
The text was updated successfully, but these errors were encountered: