cfallin opened PR #14655 from cfallin:fix-debug-uninit-non-nullable-gc-ref to bytecodealliance:main:
Right now, before a non-nullable local is in-scope semantically (from the bytecode's point of view), if guest debugging is enabled, that local's value is (i) still accessible via debug APIs, and (ii) still exposed as a GC root.
This is a problem, because non-nullable-ref-typed locals are compiled with the first def (write) to that local at the point that the local enters scope, not at the start of the function. So if a GC occurs, or if a debug API observes the value, early on (say at a breakpoint or when single-stepping before the initial def point), it will observe garbage.
This PR adds an explicit init for all such locals: they are
nullinternally in the debug state slot, even if the Wasm-level type is non-nullable. This satisfies the GC when tracing values, and also provides something for the debug API to return.The alternative would be to represent their absence (not-yet-in-scope status) explicitly, but I figured this would be much more complicated: it would mean we would need a locals-valid bitmask at any given PC for the debug API to read out. The debug API is not defining the actual Wasm semantic model, it is just presenting a shadow view of the world, so (IMHO) it's fine for that shadow view to have a (well-defined) simplification in this case. In essence, we are lowering the more complicated (non-nullable) type to a nullable type, initially null, in the debug state.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease review the Bytecode Alliance's AI tool usage policy at
https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.mdPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
cfallin requested alexcrichton for a review on PR #14655.
cfallin requested wasmtime-core-reviewers for a review on PR #14655.
cfallin requested wasmtime-compiler-reviewers for a review on PR #14655.
cfallin commented on PR #14655:
Another alternative could be to have an explicit
undefinedsentinel value that aVMGcRefcan take on, and that the GC ignores (and that the debug API would translate to an appropriateOptionprobably). This is analogous to what SpiderMonkey does -- lexically-scoped locals have a "hole"MagicValue. Happy to go that way if that's what folks want, it just touches more -- @fitzgen for thoughts maybe?
alexcrichton requested fitzgen for a review on PR #14655.
alexcrichton unassigned alexcrichton from PR #14655 Debugging: explicitly null-initialize non-nullable locals' state slots..
Last updated: Oct 11 2026 at 02:20 UTC