wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Fix wasm2c generating undeclared identifier errors

Open squk opened this issue 8 months ago • 6 comments
trafficstars

Without this change, building generated wasm2c headers results in the following errors:

crystallize-impl.h:647:12: error: use of undeclared identifier 'RefFunc'
  647 |       case RefFunc:
      |            ^
crystallize-impl.h:652:12: error: use of undeclared identifier 'RefNull'; did you mean 'default'?
  652 |       case RefNull:
      |            ^~~~~~~
      |            default
crystallize-impl.h:652:12: error: expected expression
crystallize-impl.h:655:12: error: use of undeclared identifier 'GlobalGet'
  655 |       case GlobalGet:
      |            ^

squk avatar Mar 04 '25 19:03 squk

Seems like are lacking a test here?

sbc100 avatar Mar 04 '25 19:03 sbc100

Does the project have a way of updating the generated wasm2c code in all tests?

squk avatar Mar 04 '25 19:03 squk

Does the project have a way of updating the generated wasm2c code in all tests?

Yes, there's ./test/run-tests.py -r to rebase the tests. But... we do have tests for this (see the test/wasm2c/spec-multi-output directory) that are succeeding. Why aren't they catching this issue?

keithw avatar Mar 04 '25 19:03 keithw

Hmm, I just tried compiling our "fac" example with "--num-outputs=4" and wasn't able to replicate this failure (using gcc 13.3). Are you able to share more info about how you're seeing this? I wonder if the issue is related to the inline enum declaration requiring a more-recent C version as the compiler default or something like that.

keithw avatar Mar 04 '25 19:03 keithw

@keithw Could you share your setup for the "fac" example with --num-outputs(just a gist of the makefile would suffice)?

When I can cleanly reproduce only using code in the wabt repo, I'll come up with a test for this. Perhaps this is because our tooling uses clang to compile the generated code.

squk avatar Mar 04 '25 19:03 squk

For fac, I added --num-outputs=4 to the wasm2c invocation, e.g. ../../../bin/wasm2c fac.wasm -o fac.c --num-outputs=4 and then you can compile the individual .c files with something like clang -I../.. -c -o fac_0.o fac_0.c.

You can run any of the wasm2c spec tests this way by adding --num-outputs=4 to the invocation of run-spec-wasm2c.py (this is what the tests do in the test/wasm2c/spec-multi-output directory). You can see the individual commands run by adding -p to the command-line. E.g.:

$ ./test/run-tests.py -p spec-multi-output/call
/usr/bin/python3 /tmp/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec-multi-output/call.wast --bindir=/tmp/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec-multi-output/call --num-outputs=4
[+1|-0|%100] (1.05s) test/wasm2c/spec-multi-output/call.txt

and then adding "-p" to that command-line:

$ /usr/bin/python3 /tmp/wabt/test/run-spec-wasm2c.py out/test/wasm2c/spec-multi-output/call.wast --bindir=/tmp/wabt/bin --no-error-cmdline -o out/test/wasm2c/spec-multi-output/call --num-outputs=4 -p
/tmp/wabt/bin/wast2json out/test/wasm2c/spec-multi-output/call.wast -o out/test/wasm2c/spec-multi-output/call/call.json
/tmp/wabt/bin/wasm2c out/test/wasm2c/spec-multi-output/call/call.0.wasm -o out/test/wasm2c/spec-multi-output/call/call.0.c -n call_0_wasm --num-outputs 4
cc -I/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c out/test/wasm2c/spec-multi-output/call/call.0_0.c -o out/test/wasm2c/spec-multi-output/call/call.0_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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c out/test/wasm2c/spec-multi-output/call/call.0_1.c -o out/test/wasm2c/spec-multi-output/call/call.0_1.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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c out/test/wasm2c/spec-multi-output/call/call.0_2.c -o out/test/wasm2c/spec-multi-output/call/call.0_2.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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c out/test/wasm2c/spec-multi-output/call/call.0_3.c -o out/test/wasm2c/spec-multi-output/call/call.0_3.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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c out/test/wasm2c/spec-multi-output/call/call-main.c -o out/test/wasm2c/spec-multi-output/call/call-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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c /tmp/wabt/wasm2c/wasm-rt-impl.c -o out/test/wasm2c/spec-multi-output/call/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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c /tmp/wabt/wasm2c/wasm-rt-exceptions-impl.c -o out/test/wasm2c/spec-multi-output/call/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/tmp/wabt/wasm2c -I/tmp/wabt/third_party/simde -std=c99 -c /tmp/wabt/wasm2c/wasm-rt-mem-impl.c -o out/test/wasm2c/spec-multi-output/call/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-multi-output/call/call.0_0.o out/test/wasm2c/spec-multi-output/call/call.0_1.o out/test/wasm2c/spec-multi-output/call/call.0_2.o out/test/wasm2c/spec-multi-output/call/call.0_3.o out/test/wasm2c/spec-multi-output/call/call-main.o out/test/wasm2c/spec-multi-output/call/wasm-rt-impl.o out/test/wasm2c/spec-multi-output/call/wasm-rt-exceptions-impl.o out/test/wasm2c/spec-multi-output/call/wasm-rt-mem-impl.o -o out/test/wasm2c/spec-multi-output/call/call -lm
72/72 tests passed.

It does seem to work for me with gcc 13 and clang 18 (and the tests work on GitHub Actions).

keithw avatar Mar 04 '25 23:03 keithw