fix: stop treating arithmetic negation as bitwise NOT - #24666
Closed
Amogh-2404 wants to merge 2 commits into
Closed
Conversation
`Expr::Negative` represents unary minus, but these rules used bitwise-NOT identities. Remove the unsound rewrites and leave arithmetic negation unchanged. Closes apache#24665 Signed-off-by: Amogh Ramesh <ramogh2404@gmail.com>
Signed-off-by: Amogh Ramesh <ramogh2404@gmail.com>
Contributor
Author
|
Continued in #24668 after renaming the branch. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24666 +/- ##
==========================================
- Coverage 81.44% 81.43% -0.01%
==========================================
Files 1118 1118
Lines 399550 399478 -72
Branches 399550 399478 -72
==========================================
- Hits 325398 325333 -65
+ Misses 55154 55152 -2
+ Partials 18998 18993 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Rationale for this change
Expr::Negativerepresents unary minus, but the simplifier applied identities for bitwise NOT. This produced wrong results in bitwise expressions and could hide signed-integer overflow when removing double negation.What changes are included in this PR?
Expr::Negative.scalar.slt.Are these changes tested?
Yes. Unit tests cover both operand orders for AND, OR, and XOR, the two De Morgan shapes, and double negation.
scalar.sltchecks the resulting values end to end.Are there any user-facing changes?
Yes. Unary minus in bitwise expressions now returns the correct results, and double negation preserves overflow behaviour. There are no API changes.