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

Fix wasm2c generating undeclared identifier errors #2554

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

squk
Copy link
Contributor

@squk squk commented Mar 4, 2025

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:
      |            ^

@sbc100
Copy link
Member

sbc100 commented Mar 4, 2025

Seems like are lacking a test here?

@sbc100 sbc100 requested a review from keithw March 4, 2025 19:14
@squk
Copy link
Contributor Author

squk commented Mar 4, 2025

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

@keithw
Copy link
Member

keithw commented Mar 4, 2025

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
Copy link
Member

keithw commented Mar 4, 2025

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.

@squk
Copy link
Contributor Author

squk commented Mar 4, 2025

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

@keithw
Copy link
Member

keithw commented Mar 4, 2025

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

@squk squk changed the title Fix wasm2c generating undeclared identifier errors with --num-outputs specified Fix wasm2c generating undeclared identifier errors Mar 14, 2025
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

Successfully merging this pull request may close these issues.

3 participants