fix(cpu_reference): avoid debug-build overflow in mask isolation#116
Merged
Conversation
`mask & (-(mask as i32)) as u32` panics with "negate with overflow" in debug builds when `mask` has bit 31 set (negating i32::MIN). Release builds wrap silently. Use `mask.wrapping_neg()` so the lowest-set-bit isolation works identically in debug and release, making `cosim --check-with-cpu` runnable under debug builds. Co-developed-by: Claude Code v2.1.168 (claude-opus-4-8)
baa3b30 to
07203de
Compare
robtaylor
added a commit
that referenced
this pull request
Jun 7, 2026
Both PRs merged. Sync handoff to final state: backend-owned schedule (edge_ops_mut), P2/P3 merged in the plan, JTAG on xlarge + 40/45min timeout (validated 32.0min), amendment date refs. Co-developed-by: Claude Code v2.1.168 (claude-opus-4-8)
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.
What
cpu_reference::simulate_block_v1(and_xprop) isolate the lowest setbit of
maskviamask & (-(mask as i32)) as u32. Whenmaskhas bit31 set,
-(i32::MIN)overflows and panics in debug builds("negate with overflow"); release builds wrap silently, masking the bug.
Fix
Use
mask & mask.wrapping_neg()— same two's-complement lowest-set-bitisolation, but defined for all inputs. Behaviour is identical in release;
debug builds no longer panic, so
cosim --check-with-cpuis now runnableunder debug builds.
Carry-forward item flagged in #115 / the backend-alignment handoff.