Skip to content

Fix operand arity of v128.storeN_lane in GetExprArity - #2764

Merged
sbc100 merged 3 commits into
WebAssembly:mainfrom
aizu-m:storelane-arity
Jul 9, 2026
Merged

sbc100 merged 3 commits into
WebAssembly:mainfrom
aizu-m:storelane-arity

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Found this fuzzing wasm-decompile under a debug build: a valid module whose only instruction is v128.store8_lane aborts on the value-stack assert in decompiler-ast.h Construct.

  1. GetExprArity groups SimdLoadLane and SimdStoreLane together and reports both as {2, 1}.
  2. store_lane pops the address and the vector and pushes nothing, so its real effect is {2, 0}; the spare result throws value_stack_depth out by one.

The decompiler has since been removed, but GetExprArity still drives the folded wat writer, where the phantom result is equally observable: wasm2wat --fold-exprs folds the store into the next value consumer and strands the value beneath it. Split the case so SimdStoreLane returns {2, 0} and SimdLoadLane keeps {2, 1}. A reduced repro is added under test/roundtrip.

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread test/decompile/simd-store-lane.txt Outdated
;; first local.get must survive as a separate return value rather than being
;; folded into the store.
(func (param i32 v128) (result i32 i32)
local.get 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an f32 arg for stack value testing purposes (i32 is too common as a result), but the patch is ok this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Switched the surviving value to an f32 arg so it stands out from the i32 address. The store still consumes the i32/v128 pair and the float drops out as its own return value.

@aizu-m

aizu-m commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

any update?

@zherczeg

zherczeg commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

The patch is ok for me. @sbc100 what do you think?

Comment thread test/decompile/simd-store-lane.txt Outdated
@@ -0,0 +1,32 @@
;;; TOOL: run-wasm-decompile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasm-decompile was removed from wabt so I guess this test needs to be changed in some way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, rebased past the decompiler removal and reworked the test. GetExprArity still drives wasm2wat --fold-exprs, and the phantom result is observable there too: the writer folds the store into the next consumer and strands the value beneath it. Replaced the decompile test with test/roundtrip/fold-simd-store-lane.txt (kept the f32 stack value). It fails with the shared {2, 1} case and passes with the split one; the rest of test/roundtrip still passes locally.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself lgtm.

aizu-m added 3 commits July 9, 2026 14:19
wasm-decompile was removed, so the decompile-based regression test no
longer runs. GetExprArity still drives wasm2wat --fold-exprs: the
phantom store_lane result made the writer fold the store into the next
consumer and orphan the value beneath it. Replace the test with a
run-roundtrip fold test covering the same case.
@aizu-m
aizu-m force-pushed the storelane-arity branch from ad5d8b2 to d2284ca Compare July 9, 2026 08:52
@sbc100
sbc100 merged commit f93b921 into WebAssembly:main Jul 9, 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.

3 participants