binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

wasm-as outputting an integer too big to fit in 32 bits

Open 4y8 opened this issue 7 months ago • 1 comments

Given the following code:

(func $test
  (drop (i32.const 3049323471)))

The version 123 of wasm-as output codes that, when displayed with wasm-dis is:

(func $0
  (drop (i32.const -1245643825)))

In fact 3049323471 is too big to fit in a signed 32-bit integer. Is it the expected outcome, or should the program be invalid ?

4y8 avatar Jun 13 '25 09:06 4y8

wasm constants do not have a sign, they are basically just bits, so they can be printed in text as either signed or unsigned. Either way, the bits in this case are 0xb5c0fbcf.

When the sign matters for an operation, like say division, there is a signed and unsigned operation. But constants, and most operations like add that do not care about the sign, are sign-agnostic.

kripken avatar Jun 13 '25 15:06 kripken

Thanks, I misunderstood the spec

4y8 avatar Jun 17 '25 09:06 4y8