-
Notifications
You must be signed in to change notification settings - Fork 106
[Fix]: check division overflow for int32 and int64
#1287
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,19 +279,20 @@ private void EmitIncrementOrDecrement(SyntaxToken operatorToken, ITypeSymbol? ty | |
|
|
||
| private void EmitNegativeInteger(ITypeSymbol? typeSymbol) | ||
| { | ||
| if (typeSymbol is null || (typeSymbol.Name != "Int32" && typeSymbol.Name != "Int64")) | ||
| { | ||
| // -sbyte, -byte, -short, -ushort, -char -> int, -int, -uint -> long | ||
| AddInstruction(OpCode.NEGATE); // Emit NEGATE for other integer types | ||
| return; | ||
| } | ||
|
|
||
| if (typeSymbol is null) return; | ||
| while (typeSymbol.NullableAnnotation == NullableAnnotation.Annotated) | ||
| { | ||
| // Supporting nullable integer like `byte?` | ||
| typeSymbol = ((INamedTypeSymbol)typeSymbol).TypeArguments.First(); | ||
| } | ||
|
|
||
| if (typeSymbol.Name != "Int32" && typeSymbol.Name != "Int64") | ||
| { | ||
| // -sbyte, -byte, -short, -ushort, -char -> int, -int, -uint -> long | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unsigned types works with negate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He is right, - ushort => int |
||
| AddInstruction(OpCode.NEGATE); // Emit NEGATE for other integer types | ||
| return; | ||
| } | ||
|
|
||
| var minValue = typeSymbol.Name == "Int64" ? long.MinValue : int.MinValue; // int32 or int64 | ||
|
|
||
| JumpTarget negateTarget = new(), endTarget = new(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can push an exception message before throw, but not necesssary.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No exception message before other similar
THROWs.So no exception message here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL, that is actually a problem in other places, having exception message is the correct behavior, but its ok, no need to update. .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and others will be fixed by later PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should fix it in a different PR
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why LOL?
Many cases were written by you. 😏