Expressions.JS: Bitwise left shift bugfixes, #1034 #1048
Merged
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.
Mask off 63 from shift operand to prevent overflow on x86, and cast to 32-bit operand.
Fixes #1034
Description
On x86 .NET Framework, the ANTLR/IL changes in #996 behave differently than other platforms. This seems to be due to x86 .NET Framework not masking off the operand correctly. Other platforms mask this off by 0x3f (63) since shifting by 64 or more would overflow, so this basically wraps the shift instead of overflowing. x86 netfx for some reason does not do this correctly. This adds a mask that does no harm on other platforms, but ensures that all are operating the same way.
Additionally, to fix an issue on .NET 5/6 (still usable with our netstandard2.1 target), the right operand must be an Int32 in case it overflows. If the operand is an Int64 and it is out of range, it can crash the process as an invalid program.
Note that this inlines the CompileBinary logic and no longer uses that method because we want to only mask off the second operand, not the first.