Fix possible overflow in optAssertionPropGlobal_RelOp #123201
Closed
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.
Fixes #122288
We deal with
1 >= (2147483646 + X)expression. Since getting the range of the whole op2(2147483646 + X)didn't get us anything, we have this hack where we peel the offset (so2147483646) and try to find the range ofX. (I'll move this logic intoryGetRangeFromAssertionsitself in the future).We end up with
[0...65535]range of X which clearly may overflow when2147483646is added. The previous logic was trying to just move the constant to the left1 - 2147483646 >= Xwhere Subtract didn't overflow.I want to do some refactoring around overflow handling. Today, e.g. for
range1=[0..int.MaxValue]andrange2=[10..20]theRangeOps::Add(range1, range2)returns[10..unknown], I want it to return[unknown..unknown](or maybe[-2147483639..0]?). It seems to be not a problem today except for 2 places in global assertion prop.This fix doesn't contain the refactoring to be backport-friendly.
A few diffs correctness related.