fix(encoder): route AND/CMN immediates through ThumbExpandImm — close the class#266
Merged
Merged
Conversation
… the class The last two unguarded data-processing immediate encoders: - AND.W immediate raw-packed i:imm3:imm8 (correct only <=0xFF, silently wrong above — the fold guard kept it in range, but the encoder itself was unsafe). - CMN.W immediate fell back to a silent 0xBF00 NOP for imm > 0xFF. Both now go through the shared `try_thumb_expand_imm` (added in #255): encode any valid modified immediate correctly, else `Err` (forcing register materialization). This closes the silent-miscompile class across the whole data-proc immediate family — AND/ORR/EOR/CMP/CMN/ADD/SUB/ADDS/SUBS now share one correct, Ok-or-Err path (#251/#253/#255/#259 lineage). Behavior-frozen: for imm <= 0xFF the encoding is byte-identical (try_thumb_expand_imm returns the same field), so the cmp/cmn/and folding output is unchanged — the three differentials stay result-identical (control_step 0x00210A55, flight_seam 0x07FDF307, div_const 338/338). Test and_cmn_immediate_thumb_expand_else_error: byte-range unchanged, a replicated modified immediate now encodes, and 0x101 errors (AND was raw-pack, CMN was a NOP). Part of #242. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
The last two unguarded data-processing immediate encoders:
i:imm3:imm8(correct only<=0xFF, silently wrong above — the fold guard kept it in range, but the encoder itself was unsafe).0xBF00NOP forimm > 0xFF.Both now go through the shared
try_thumb_expand_imm(#255): encode any valid modified immediate correctly, elseErr. This closes the silent-miscompile class across the whole data-proc immediate family — AND/ORR/EOR/CMP/CMN/ADD/SUB/ADDS/SUBS now share one correct, Ok-or-Err path (#251/#253/#255/#259 lineage).Behavior-frozen
For
imm <= 0xFFthe encoding is byte-identical (try_thumb_expand_immreturns the same field), so folding output is unchanged — the three differentials stay result-identical (control_step0x00210A55, flight_seam0x07FDF307, div_const 338/338). Testand_cmn_immediate_thumb_expand_else_error: byte-range unchanged; a replicated modified immediate now encodes;0x101errors (AND was raw-pack, CMN a NOP).Part of #242.
🤖 Generated with Claude Code