Skip to content

wasm2c: reject contradictory imports instead of aborting - #2813

Merged
shravanrn merged 4 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/wasm2c-contradictory-import-abort
Aug 18, 2026
Merged

wasm2c: reject contradictory imports instead of aborting#2813
shravanrn merged 4 commits into
WebAssembly:mainfrom
ANAMASGARD:fix/wasm2c-contradictory-import-abort

Conversation

@ANAMASGARD

@ANAMASGARD ANAMASGARD commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #2751

Summary

  • Replace UNIMPLEMENTED("contradictory import declaration") with a stderr diagnostic and Result::Error
  • Preflight ComputeUniqueImports() at the start of WriteModule() so codegen never runs on unlinkable modules
  • Add test/wasm2c/contradictory-imports.txt

Test plan

  • Manual: wasm2c dup.wasm exits 1 with error message (no abort)
  • python3 test/run-tests.py test/wasm2c/contradictory-imports.txt
  • python3 test/run-tests.py test/wasm2c/
  • ./out/wabt-unittests
image

@shravanrn
shravanrn requested review from keithw and sbc100 August 8, 2026 18:28
@sbc100

sbc100 commented Aug 8, 2026

Copy link
Copy Markdown
Member

Seems reasonable to me

Comment thread src/c-writer.cc
@ANAMASGARD
ANAMASGARD requested review from sbc100 and shravanrn August 16, 2026 03:57
Comment thread src/c-writer.cc
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

@shravanrn I have removed the WriteModule preflight and kept a single ComputeUniqueImports() in BeginInstance(). On failure it now sets result_ and returns, with Failed(result_) checks in WriteModuleInstance, WriteCHeader, and WriteModule so we don't keep emitting after an error.

@ANAMASGARD
ANAMASGARD requested a review from shravanrn August 17, 2026 08:40
Comment thread src/c-writer.cc Outdated
@shravanrn

Copy link
Copy Markdown
Collaborator

@ANAMASGARD Feel free to rebase and land. (Let me know if you need me to click the land button)

Preflight ComputeUniqueImports() before codegen and return Result::Error
when the same module/field name is imported with different external kinds,
instead of hitting UNIMPLEMENTED/abort on valid-but-unlinkable modules.
Fixes WebAssembly#2751

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
Clear import accumulators at the start of ComputeUniqueImports() so it
can run from both WriteModule() preflight and BeginInstance(). Keeps
early rejection of contradictory imports while making the unique_imports_
dependency explicit at the point of use.
Fixes WebAssembly#2751

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
Remove duplicate ComputeUniqueImports() from WriteModule(). Keep one
call in BeginInstance(), set result_ on failure, and stop emission in
WriteModuleInstance, WriteCHeader, and WriteModule when result_ is Error.
Fixes WebAssembly#2751

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
Single call site in BeginInstance() no longer needs accumulator clears
added for the earlier dual-call approach.

Fixes WebAssembly#2751

Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
@ANAMASGARD
ANAMASGARD force-pushed the fix/wasm2c-contradictory-import-abort branch from 4f769c3 to 1a0967d Compare August 18, 2026 02:21
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

@shravanrn thanks for review I have removed the clears, rebased onto latest main .
Ready for you to land now .

@ANAMASGARD
ANAMASGARD requested a review from shravanrn August 18, 2026 02:26
@shravanrn
shravanrn merged commit 68a7ed2 into WebAssembly:main Aug 18, 2026
17 checks passed
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.

wasm2c: abort (UNIMPLEMENTED contradictory import declaration) on a valid module with same-named imports of different kinds

3 participants