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

Hermes should throw an exception when BigInts use unsigned shift #1212

Closed
JimWongM opened this issue Dec 7, 2023 · 2 comments
Closed

Hermes should throw an exception when BigInts use unsigned shift #1212

JimWongM opened this issue Dec 7, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@JimWongM
Copy link

JimWongM commented Dec 7, 2023

Bug Description

Hermes should throw an exception when BigInts use unsigned shift, but it did not because of Dead Code Elimination.

BinaryOperatorInst is Eliminated by DCE and does not throw an exception. This optimization changes the semantics of JavaSript program.

The problem may be related to the side effect of BigInt for UnsignedRightShiftKind.

Hermes version: ebf7889 (latest version)
OS version (if any): Linux, MacOS

Steps To Reproduce

  1. Build latest hermes
  2. ./hermes -O test.js
  3. ./hermes -O0 test.js

code example:
test.js

function main() {
    try {
      -2512320511n >>> -2512320511n;
      print("hello");
    } catch (e10) {print(e10)}
  }
  main();

The Expected Behavior

The result of step 2 and step 3 is different. In full optimization level, Hermes shoud throw an exception "TypeError: BigInts have no unsigned shift".

@JimWongM JimWongM added the bug Something isn't working label Dec 7, 2023
@JimWongM
Copy link
Author

JimWongM commented Dec 7, 2023

This problem may also exists when BigInt mod zero.

@tmikov
Copy link
Contributor

tmikov commented Dec 7, 2023

Wow, these never end, do they? :-) Thanks for reporting this, we will fix it.

tmikov added a commit to tmikov/hermes that referenced this issue Dec 10, 2023
Summary:
BigInt differs from numbers - several bigint operations can throw an
exception, specifically:
- >>> is not allowed at all and throws
- / and % can result in division by zero

Improve the side effect model and add a test.

This diff was ported from SH.

Closes facebook#1212

Differential Revision: D52013223
tmikov pushed a commit to tmikov/hermes that referenced this issue Dec 15, 2023
Summary:

BigInt differs from numbers - several bigint operations can throw an
exception, specifically:
- >>> is not allowed at all and throws
- / and % can result in division by zero

Improve the side effect model and add a test.

This diff was ported from SH.

Closes facebook#1212

Differential Revision: D52013223
facebook-github-bot pushed a commit that referenced this issue Dec 15, 2023
Summary:
BigInt differs from numbers - several bigint operations can throw an
exception, specifically:
- >>> is not allowed at all and throws
- / and % can result in division by zero

Improve the side effect model and add a test.

Reported in #1212

Reviewed By: avp

Differential Revision: D52013220

fbshipit-source-id: 34606cb7d53a3db3ea49dd026661b7fd340583e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants