Skip to content

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

Closed

Description

@rathann

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.

Activity

  1. SoniEx2 commented on Feb 17, 2025

    @SoniEx2
    Collaborator

    at first glance, this looks like a GCC bug.

  2. rathann commented on Feb 18, 2025

    @rathann
    ContributorAuthor

    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?

  3. sharkcz commented on Feb 18, 2025

    @sharkcz

    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 ...

  4. sharkcz commented on Feb 18, 2025

    @sharkcz

    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.
    
  5. SoniEx2 commented on Feb 18, 2025

    @SoniEx2
    Collaborator

    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)

  6. sharkcz commented on Feb 18, 2025

    @sharkcz

    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.

  7. SoniEx2 commented on Feb 18, 2025

    @SoniEx2
    Collaborator

    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.

  8. sharkcz commented on Feb 18, 2025

    @sharkcz

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

  9. SoniEx2 commented on Feb 18, 2025

    @SoniEx2
    Collaborator

    indeed, it's supposed to return 0.

  10. SoniEx2 commented on Feb 18, 2025

    @SoniEx2
    Collaborator

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

  11. sharkcz commented on Feb 18, 2025

    @sharkcz
    #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

  12. rathann commented on Feb 18, 2025

    @rathann
    ContributorAuthor

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

  13. rathann commented on Feb 21, 2025

    @rathann
    ContributorAuthor

    I am getting this on s390x, too.

  14. 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[/+] on Feb 21, 2025
  15. SoniEx2 commented on Feb 21, 2025

    @SoniEx2
    Collaborator

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

  16. sharkcz commented on Feb 21, 2025

    @sharkcz

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

    it does

    And I am confirming the s390x failure.

  17. SoniEx2 commented on Feb 21, 2025

    @SoniEx2
    Collaborator

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

    thanks for confirming!

  18. rathann commented on Nov 17, 2025

    @rathann
    ContributorAuthor

    This is fixed in GCC and tests pass now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions