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

wasm2c/spec/float_exprs.txt test fails with GCC 15 on ppc64le and s390x #2542

Open
rathann opened this issue Feb 17, 2025 · 16 comments
Open

Comments

@rathann
Copy link
Contributor

rathann commented Feb 17, 2025

When building wabt-1.0.36 with GCC 15 (Fedora 42 and rawhide) and running the testsuite on ppc64le

- test/wasm2c/spec/float_exprs.txt
  expected error code 0, got 1.
  STDERR MISMATCH:
  --- expected
  +++ actual
  @@ -0,0 +1,8 @@
  +float_exprs.wast:2238: assertion failed: in w2c_float__exprs__86__wasm_f320x2Eno_trichotomy_lt(&float__exprs__86__wasm_instance, 0.f, make_nan_f32(0x400000)): expected 0, got 1.
  +float_exprs.wast:2239: assertion failed: in w2c_float__exprs__86__wasm_f320x2Eno_trichotomy_le(&float__exprs__86__wasm_instance, 0.f, make_nan_f32(0x400000)): expected 0, got 1.
  +float_exprs.wast:2240: assertion failed: in w2c_float__exprs__86__wasm_f320x2Eno_trichotomy_gt(&float__exprs__86__wasm_instance, 0.f, make_nan_f32(0x400000)): expected 0, got 1.
  +float_exprs.wast:2241: assertion failed: in w2c_float__exprs__86__wasm_f320x2Eno_trichotomy_ge(&float__exprs__86__wasm_instance, 0.f, make_nan_f32(0x400000)): expected 0, got 1.
  +float_exprs.wast:2242: assertion failed: in w2c_float__exprs__86__wasm_f640x2Eno_trichotomy_lt(&float__exprs__86__wasm_instance, 0.0000000000000000, make_nan_f64(0x8000000000000)): expected 0, got 1.
  +float_exprs.wast:2243: assertion failed: in w2c_float__exprs__86__wasm_f640x2Eno_trichotomy_le(&float__exprs__86__wasm_instance, 0.0000000000000000, make_nan_f64(0x8000000000000)): expected 0, got 1.
  +float_exprs.wast:2244: assertion failed: in w2c_float__exprs__86__wasm_f640x2Eno_trichotomy_gt(&float__exprs__86__wasm_instance, 0.0000000000000000, make_nan_f64(0x8000000000000)): expected 0, got 1.
  +float_exprs.wast:2245: assertion failed: in w2c_float__exprs__86__wasm_f640x2Eno_trichotomy_ge(&float__exprs__86__wasm_instance, 0.0000000000000000, make_nan_f64(0x8000000000000)): expected 0, got 1.
  STDOUT MISMATCH:
  --- expected
  +++ actual
  @@ -1 +1 @@
  -794/794 tests passed.
  +786/794 tests passed.

This does not happen with GCC 14.x and is not reproducible on x86_64 or aarch64.

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 17, 2025

at first glance, this looks like a GCC bug.

@rathann
Copy link
Contributor Author

rathann commented Feb 18, 2025

Ok, gcc bug opened: https://bugzilla.redhat.com/show_bug.cgi?id=2346233 . Could you help prepare a minimum piece of code to reproduce the issue and help gcc maintainers fix it?

@sharkcz
Copy link

sharkcz commented Feb 18, 2025

test/wasm2c/spec/float_exprs.txt points to https://github.com/WebAssembly/testsuite/blob/eeb6dac81be81151da0958ed955aba91230c1f25/float_exprs.wast#L2269 for the offending code, but how this is translated to a C code that GCC consumes is magic to me :-) Although maybe I am getting somewhere ...

@sharkcz
Copy link

sharkcz commented Feb 18, 2025

with reduced float_exprs.wast installed as out/test/wasm2c/spec/float_exprs.wast one can do

<mock-chroot> sh-5.2# /usr/bin/python3 test/run-spec-wasm2c.py -v -p out/test/wasm2c/spec/float_exprs.wast --bindir=redhat-linux-build --no-error-cmdline -o out/test/wasm2c/spec/float_exprs
/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/redhat-linux-build/wast2json out/test/wasm2c/spec/float_exprs.wast -o out/test/wasm2c/spec/float_exprs/float_exprs.json -v
/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/redhat-linux-build/wasm2c out/test/wasm2c/spec/float_exprs/float_exprs.0.wasm -o out/test/wasm2c/spec/float_exprs/float_exprs.0.c -n float_exprs_0_wasm --num-outputs 1
cc -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/third_party/simde -std=c99 -c out/test/wasm2c/spec/float_exprs/float_exprs.0.c -o out/test/wasm2c/spec/float_exprs/float_exprs.0.o -O2 -Wall -Werror -Wno-unused -Wno-array-bounds -Wno-ignored-optimization-argument -Wno-tautological-constant-out-of-range-compare -Wno-infinite-recursion -Wno-pass-failed -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE
cc -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/third_party/simde -std=c99 -c out/test/wasm2c/spec/float_exprs/float_exprs-main.c -o out/test/wasm2c/spec/float_exprs/float_exprs-main.o -O2 -Wall -Werror -Wno-unused -Wno-array-bounds -Wno-ignored-optimization-argument -Wno-tautological-constant-out-of-range-compare -Wno-infinite-recursion -Wno-pass-failed -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE
cc -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/third_party/simde -std=c99 -c /builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c/wasm-rt-impl.c -o out/test/wasm2c/spec/float_exprs/wasm-rt-impl.o -O2 -Wall -Werror -Wno-unused -Wno-array-bounds -Wno-ignored-optimization-argument -Wno-tautological-constant-out-of-range-compare -Wno-infinite-recursion -Wno-pass-failed -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE
cc -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/third_party/simde -std=c99 -c /builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c/wasm-rt-exceptions-impl.c -o out/test/wasm2c/spec/float_exprs/wasm-rt-exceptions-impl.o -O2 -Wall -Werror -Wno-unused -Wno-array-bounds -Wno-ignored-optimization-argument -Wno-tautological-constant-out-of-range-compare -Wno-infinite-recursion -Wno-pass-failed -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE
cc -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c -I/builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/third_party/simde -std=c99 -c /builddir/build/BUILD/wabt-1.0.36-build/wabt-1.0.36/wasm2c/wasm-rt-mem-impl.c -o out/test/wasm2c/spec/float_exprs/wasm-rt-mem-impl.o -O2 -Wall -Werror -Wno-unused -Wno-array-bounds -Wno-ignored-optimization-argument -Wno-tautological-constant-out-of-range-compare -Wno-infinite-recursion -Wno-pass-failed -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE
cc out/test/wasm2c/spec/float_exprs/float_exprs.0.o out/test/wasm2c/spec/float_exprs/float_exprs-main.o out/test/wasm2c/spec/float_exprs/wasm-rt-impl.o out/test/wasm2c/spec/float_exprs/wasm-rt-exceptions-impl.o out/test/wasm2c/spec/float_exprs/wasm-rt-mem-impl.o -o out/test/wasm2c/spec/float_exprs/float_exprs -lm

float_exprs.wast:13: assertion failed: in w2c_float__exprs__0__wasm_f320x2Eno_trichotomy_lt(&float__exprs__0__wasm_instance, 0.f, make_nan_f32(0x400000)): expected 0, got 1.
0/1 tests passed.

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 18, 2025

does this exhibit the problem?

/* min.c */
typedef uint32_t u32;
typedef float f32;

u32 w2c_float__exprs__88__wasm_f320x2Eno_trichotomy_lt_0(void* instance, f32 var_p0, f32 var_p1) {
  u32 var_i0, var_i1;
  f32 var_f0, var_f1, var_f2;
  var_f0 = var_p0;
  var_f1 = var_p1;
  var_i0 = var_f0 < var_f1;
  var_f1 = var_p0;
  var_f2 = var_p1;
  var_i1 = var_f1 >= var_f2;
  var_i0 |= var_i1;
  return var_i0;
}
/* main.c */
#include <string.h>
typedef uint32_t u32;
typedef float f32;

u32 w2c_float__exprs__88__wasm_f320x2Eno_trichotomy_lt_0(void* instance, f32 var_p0, f32 var_p1);

static f32 make_nan_f32(u32 x) {
  x |= 0x7f800000;
  f32 res;
  memcpy(&res, &x, sizeof(res));
  return res;
}

int main(int argc, char **argv) {
  return w2c_float__exprs__88__wasm_f320x2Eno_trichotomy_lt_0(NULL, 0.f, make_nan_f32(0x400000));
}

(compile with same flags and whatnot ofc, feel free to rename the function the name clearly doesn't matter)

@sharkcz
Copy link

sharkcz commented Feb 18, 2025

It does not AFAICT, but often there is more code required "surrounding" the minimal code snippets, so the compiler makes different decisions. I believe I should be able to reduce my example above to have something useful for the toolchains team.

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 18, 2025

we assume you did check the exit status? it doesn't output anything other than the exit status, but that might have been unclear, sorry.

@sharkcz
Copy link

sharkcz commented Feb 18, 2025

sorry, I haven't read the code :-) Is return code 1 a reproducer or not?

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 18, 2025

indeed, it's supposed to return 0.

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 18, 2025

it can be minimized further, but you can probably do that a lot easier now.

@sharkcz
Copy link

sharkcz commented Feb 18, 2025

#include <string.h>
#include <stdint.h>

typedef uint32_t u32;
typedef float f32;

__attribute__((noinline)) u32 w2c_float__exprs__88__wasm_f320x2Eno_trichotomy_lt_0(void* instance, f32 var_p0, f32 var_p1)
{
  u32 var_i0, var_i1;
  f32 var_f0, var_f1, var_f2;
  var_f0 = var_p0;
  var_f1 = var_p1;
  var_i0 = var_f0 < var_f1;
  var_f1 = var_p0;
  var_f2 = var_p1;
  var_i1 = var_f1 >= var_f2;
  var_i0 |= var_i1;
  return var_i0;
}

static f32 make_nan_f32(u32 x) {
  x |= 0x7f800000;
  f32 res;
  memcpy(&res, &x, sizeof(res));
  return res;
}

int main(int argc, char **argv) {
  return w2c_float__exprs__88__wasm_f320x2Eno_trichotomy_lt_0(NULL, 0.f, make_nan_f32(0x400000));
}

and compiled with gcc -std=c99 -O2 -Wall -fno-optimize-sibling-calls -frounding-math -fsignaling-nans -D_DEFAULT_SOURCE -o test test.c reproduces the issue with GCC 15, but runs OK with GCC 14

@rathann
Copy link
Contributor Author

rathann commented Feb 18, 2025

@SoniEx2 your assistance is much appreciated! Could you take a look at other failed test issues I opened?

@rathann
Copy link
Contributor Author

rathann commented Feb 21, 2025

I am getting this on s390x, too.

@rathann rathann changed the title wasm2c/spec/float_exprs.txt test fails with GCC 15 on ppc64le wasm2c/spec/float_exprs.txt test fails with GCC 15 on ppc64le and s390x Feb 21, 2025
@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 21, 2025

btw, does return (var_p0 < var_p1) | (var_p0 >= var_p1); exhibit the problem?

@sharkcz
Copy link

sharkcz commented Feb 21, 2025

btw, does return (var_p0 < var_p1) | (var_p0 >= var_p1); exhibit the problem?

it does

And I am confirming the s390x failure.

@SoniEx2
Copy link
Collaborator

SoniEx2 commented Feb 21, 2025

GCC, that's not how floats work 🤦🏻‍♀️

thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants