Description
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 below 0
and above usize::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 than getelementptr inbounds
.)
However, we'd probably need LLVM support for this, adding some sort of getelementptr nowrap
. (There is the possible alternative of using plain getelementptr
, and upgrading that to inbounds
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.