Skip to content
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

Expressions.JS: Bitwise left shift bugfixes, #1034 #1048

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

paulirwin
Copy link
Contributor

@paulirwin paulirwin commented Nov 26, 2024

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

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.

@paulirwin paulirwin added the notes:bug-fix Contains a fix for a bug label Nov 26, 2024
@paulirwin paulirwin changed the title Expressions.JS: Mask off 63 from shift operand, #1034 Expressions.JS: Bitwise left shift bugfixes, #1034 Nov 26, 2024
@paulirwin paulirwin marked this pull request as ready for review November 26, 2024 04:07
Copy link
Contributor

@NightOwl888 NightOwl888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I ran the tests 8x on Azure Devops and there were no x86 test failures. There was a new failing test found, but it was unrelated to this change (it also fails on master). See: #1050.

@paulirwin paulirwin merged commit e9c865c into apache:master Nov 26, 2024
20 checks passed
@paulirwin paulirwin deleted the issue/1034 branch November 26, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:bug-fix Contains a fix for a bug
Projects
None yet
2 participants