Skip to content

fix(opt): defensive panic on unmapped vreg instead of silent R0 fallback#101

Open
avrabe wants to merge 1 commit into
mainfrom
fix/defensive-vreg-fallback
Open

fix(opt): defensive panic on unmapped vreg instead of silent R0 fallback#101
avrabe wants to merge 1 commit into
mainfrom
fix/defensive-vreg-fallback

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 11, 2026

Follow-up to PR #97 (which fixed the silicon-blocking #93 memset bug).

The root cause of #93 was that optimizer_bridge::wasm_to_ir silently dropped three wasm ops (I64ExtendI32U/S, I32WrapI64). The downstream lookup helper get_arm_reg returned Reg::R0 as a silent fallback when a vreg had no assignment — so subsequent i64 shifts read R0 as their rm_lo/rm_hi, destroying memset's destination pointer.

This PR replaces the silent fallback with a diagnostic panic naming the offending vreg. Any future "wasm op silently dropped" bugs of this class will surface as a compiler crash with a useful error message, instead of producing miscompiled firmware that boots-and-loops on real silicon.

A compiler crash is strictly better than a hung MCU.

Test plan

🤖 Generated with Claude Code

Follow-up to issue #93 (silicon-blocking memset bug). The root cause was
optimizer_bridge::wasm_to_ir silently dropping three wasm ops
(I64ExtendI32U/S, I32WrapI64) — they produced vregs that never got mapped
to ARM registers. The downstream lookup in get_arm_reg returned Reg::R0
as a silent fallback, so subsequent i64 shifts read R0 as rm_lo/rm_hi,
destroying memset's destination pointer on real silicon.

Replace the silent fallback with a panic that names the vreg. Future
"wasm op silently dropped" bugs of this class will surface at the
boundary instead of producing miscompiled firmware. A compiler crash is
strictly better than a hung MCU.

Verified:
* cargo test --workspace — all pass (no path legitimately hits the
  fallback — the post-#97 codebase produces mappings for every wasm op
  it emits IR for)
* cargo clippy --workspace --all-targets -- -D warnings — clean
* cargo fmt --check — clean

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant