WebAssembly / WebAssembly/binaryen

wasm::is{U,S}Integer64() doesn't work well around INT64_MAX

Open
#2,291 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

The latest clang points a minor bug for -Wimplicit-int-float-conversion.

On the implementation of wasm::wasm::isUInteger64, std::numeric_limits<uint64_t>::max() is implicitly converted to double.
As double has only 53 bit for digits on typical systems, and the conversion rounds the value to 0x1p64 rather than 0x1p64 - 1, that implies isUInteger64(0x1p64) returns true, which is wrong.

We should probably use fixed double literals like 0x1p64, -0x1p63, and 0x1p63 for the boundary check here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/support/safe_integer.cpp at wasm::wasm::isUInteger64 and the related isInteger64 boundary checks. Reproduce the issue with the latest clang and inspect how the uint64_t limits are converted to double. Done means the boundary checks use the intended fixed floating-point values, avoid the implicit-conversion warning, and reject values at or beyond the incorrect rounded boundary.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.