Change Offset.MakeLattice.to_index
to return bytes, not bits
#1679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up to #1676 (comment).
A TODO in
LockDomain
also anticipated this:(* TODO: is this bits or bytes? *)
.Fixes
Offset.MakeLattice.to_index
to return bytes instead of bits, as per documentation:analyzer/src/cdomain/value/cdomains/offset_intf.ml
Lines 92 to 96 in 153ce28
Also extracts a few other similar utility functions for offsets and sizes in bytes, not bits. These now assert divisibility by 8 before doing so. Usually this is fine because points to bitfields are impossible.
However,
to_index
violates it in some memOutOfBounds bitfield tests because the analysis also refers to things accessed more directly, not just those whose addresses have been taken. To handle that, an interval from floor to ceil division is constructed.Theoretically, doing it in bits is more precise than after having rounded to bytes, but I don't know if this has practical relevance.
The blind division by 8 from #1676 and others wouldn't have done it correctly either for bitfields spanning multiple bytes.