fix(opt): defensive panic on unmapped vreg instead of silent R0 fallback#101
Open
avrabe wants to merge 1 commit into
Open
fix(opt): defensive panic on unmapped vreg instead of silent R0 fallback#101avrabe wants to merge 1 commit into
avrabe wants to merge 1 commit into
Conversation
3530719 to
37b9787
Compare
6 tasks
37b9787 to
592fd27
Compare
This was referenced May 11, 2026
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>
592fd27 to
d752201
Compare
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to PR #97 (which fixed the silicon-blocking #93 memset bug).
The root cause of #93 was that
optimizer_bridge::wasm_to_irsilently dropped three wasm ops (I64ExtendI32U/S, I32WrapI64). The downstream lookup helperget_arm_regreturnedReg::R0as a silent fallback when a vreg had no assignment — so subsequent i64 shifts read R0 as theirrm_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
cargo test --workspace— all pass (the post-fix(opt): i64 lowering miscompiles memset-style loop counter on Cortex-M (#93) #97 codebase produces mappings for every wasm op it emits IR for, so no test legitimately hits the fallback path)cargo clippy --workspace --all-targets -- -D warnings— cleancargo fmt --check— clean🤖 Generated with Claude Code