Skip to content

[SpillPointers] Spill operand stack pointers across calls - #9432

Open
akasakariko wants to merge 1 commit into
WebAssembly:mainfrom
akasakariko:fix/spill-pointer-operands
Open

akasakariko wants to merge 1 commit into
WebAssembly:mainfrom
akasakariko:fix/spill-pointer-operands

Conversation

@akasakariko

@akasakariko akasakariko commented Nov 25, 2026 •

Copy link
Copy Markdown

--spill-pointers can miss a pointer held as an earlier operand while a later operand calls, allowing conservative GC to reclaim a live object

Capture these values in fresh locals before liveness analysis, preserving evaluation order and values from locals that later operands overwrite, including indirect-call targets and non-call expressions

Restore the shadow stack after tail-call operands finish so the spill frame remains visible during nested calls and is released before transferring control

The original WAT reproducer now spills all three functions without --flatten, and the focused regression, full wasm-opt suite, lit suite, GTest, clang-format 21, clang-tidy 21 and Ruff pass locally

This is an original contribution

Fixes #9307

@@ -0,0 +1 @@
spill-pointers_enable-tail-call

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.

Please add new tests as lit tests, maybe test/lit/passes/spill-pointers-stack.wast. We are moving tests to lit over time.

(call $spill-args
(call $spill-call-call0 (i32.const 1))
(call $spill-call-call0 (i32.const 2))
)

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.

It will be easier to read this once it is a lit test, but please also add brief comments in each test, like here, maybe

;; The i32 constants might be pointers, so we must spill them.

return;
}
needsLocals |= pointer && hasCalls.contains(child);
pointer |= child->type == pointerType && !child->is<Const>();

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.

Why are consts excluded?

Comment thread src/abi/stack.h
} else if (func->body->type == Type::unreachable) {
block->list.push_back(func->body);
// no need to restore the old stack value, we're gone anyhow
// There is no fallthrough. Returns and tail calls restore the stack above.

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.

Are the changes to this file related to the main change to SpillPointers? They look like they could be separated out, or maybe I don't quite understand them?

This branch has not been deployed

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

--spill-pointers does not spill a value held on the Wasm value stack across a call

2 participants