WebAssembly / wabt

The WebAssembly Binary Toolkit
Apache License 2.0
6.91k stars 702 forks source link

[wasm2c] Strange issue with double parsing in msvc #2422

Closed sbc100 closed 6 months ago

sbc100 commented 6 months ago

For some reason INT_MIN is not parsing correctly under MSVC..

#include <stdio.h>

int main() {
  double x = -2147483648;
  double y = -2147483648L;
  double z = -2147483648.0;
  printf("%f\n", x);
  printf("%f\n", y);
  printf("%f\n", z);
}

Under MSVC this produces:

2147483648.000000
2147483648.000000
-2147483648.000000

i.e. only adding .0 at the end causes the sign bit to be preserved.

Gcc and clang both (correctly I believe) produce:

-2147483648.000000
-2147483648.000000
-2147483648.000000
SoniEx2 commented 6 months ago

isn't this #2389 ?

SoniEx2 commented 6 months ago

INT_MIN/etc are notorious for being a pain as a numeric constant, the usual workaround is to write it as an expression (-2147483647 - 1).

(something about it being technically UB?)

sbc100 commented 6 months ago

Ah yes, I think #2389 will fix this. My fix was to append .0 which also seems to work.

sbc100 commented 6 months ago

-fsanitize=undefined doesn't warn here..

sbc100 commented 6 months ago

Closing as duplicate of #2388