Repository navigation
[AUTOMATED] fix(p3): a 64-bit return whose high register is zero keeps its zero-extension - #794
Merged
Merged
Conversation
mahaloz
force-pushed
the
fix/zext-return-sign
branch
from
October 1, 2026 19:03
83404e7 to
f97f46d
Compare
…s its zero-extension
On a 32-bit target a function returning a 64-bit integer whose high word it
sets to zero (ARM `mov r1,#0`, MIPS `$3 = 0`, i386 `xor %edx,%edx`) was
printed returning its low word, typed by that word's own operations:
`u64 ins16(unsigned a, unsigned short b) { return ((a + 1) << 16) | b; }`
printed as `int ins16(int a0,unsigned int a1)`, so a caller widening the
result sign-extended what the binary zero-extends (0x80000000 became
0xffffffff80000000), and `(unsigned)(a + b)` lost its zero-extension.
Return recovery joins the pair and the RETURN reads ZEXT(lo); dead-code
analysis counts only its possibly-nonzero bits as consumed, so RuleSubvarZext
trimmed the RETURN to the low register. SubvariableFlow::try_return_pull now
refuses to trim a value of at most eight bytes that is wider than every single
integer output register of the prototype model and laid out as one integer in
the register file's byte order: a join such as ARM r1:r0, or a register naming
both halves such as SPARC o0_1. The function returns `unsigned long long` and a
signed word is cast to `unsigned int` before the widening. A pair joined
against the register order (big-endian pairs on main, which #763 reorders) and
a 16-byte pair (x86-64 RDX:RAX, where a zeroed RDX is usually
-fzero-call-used-regs after an int function) keep the trim. Functions whose
bytes are a zero-extended return but that mean a word (i386
-fzero-call-used-regs, gcc -O0 `int f(u64 a){return a>>32;}`) now print as
`unsigned long long`; `--option returnpair single` restores the word.
Tests: stage test kuna-zextpair (5 of 6 assertions fail before the fix, the
control passes on both); kuna-cli round trip zext_pair_returns compiling the
printed C for ARM, MIPS, PowerPC little-endian and i386 objects, callers
included, against the source with gcc and clang at -O0/-O2 (544 wrong values
on the ARM build before the fix), plus a return-width check under -m32 for
ARM, i386 and SPARC (MIPS and PowerPC name an eight-byte integer `long`, so
each function must be declared like the 64-bit control); passthrough_own_return's
`bl provider; mov r1,#0` forwarder now returns `unsigned long long`.
decompile-all over 99 ARM firmware and i386 binaries (45,490 functions), 38
x86-64 binaries (14,836) and zlib for seven 32-bit targets (1,493) changes no
function; datatests 675/675 unchanged.
Fixes #769
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
…d base Re-recorded on origin/main 5eb9733 plus this branch: the 6 ZEXTPAIR keys are the only additions, none removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
force-pushed
the
fix/zext-return-sign
branch
from
October 2, 2026 00:21
f97f46d to
0792c7b
Compare
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 2, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 3, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 3, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
mahaloz
added a commit
that referenced
this pull request
Oct 3, 2026
…ifted, not its return form With the zero-extension of a 64-bit return kept (#794), sel_const prints as a 64-bit return of its zero-extended 10 or 20 instead of two 32-bit returns, so the assertion now rejects the old join's shift rather than requiring one spelling. The header describes main's output as it is now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
sjkim1127
added a commit
to sjkim1127/kuna
that referenced
this pull request
Nov 19, 2026
… honest bounds - Return values: compare only the bytes the physical ABI defines for the claimed type; a width or signedness verdict needs a typed contract (fixture source, DWARF). Noelo-Lab#794 is a DIFFERS against its source's u64 contract. - Inputs: both sides start from the same raw state; an undeclared live-in is PROTOTYPE_SUSPECT, not a poison-induced DIFFERS. - Calls: stubs write reachable memory and the decompiled side replays it; Tier S models calls as (regs, memory) -> (regs, memory) and never encodes a function Tier C could not fully execute. - The Funcdata interpreter is new work; EmulateFunction's stores are no-ops. Unsupported ops give UNKNOWN(unsupported-op). - EQUIVALENT(<=k) covers inputs on which both sides finish within the bound; one-sided overruns are replayed, not dropped. Unreplayable sat models are separated from encoder bugs. - Localization reports a 1-minimal candidate set; log2 k only for a single culprit. - Declared divergences are predicates (option, arch, observable, pattern). - Slices: C1 pure integer, C2 memory and calls, C3 localization, C4 corpus. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 problem
On a 32-bit target, a function that returns a 64-bit integer with its high word set to zero is printed as returning only its low word, typed as a signed
int. A caller that widens the result then sign-extends it.ins16(0x7fff, 0)is0x80000000, but through the printed prototype(unsigned long long)ins16(0x7fff, 0)is0xffffffff80000000. MIPS and PowerPC little-endian, RISC-V 32 and i386 (xor %edx,%edx; ret) print the sameint, andu64 f(int a, int b) { return (unsigned)(a + b); }printsint f(...) { return a1 + a0; }.The fix
r1:r0,$3:$2andEDX:EAX, and SPARC'so0_1, a register that names both halves. With the high register zero the RETURN readsZEXT(lo), andRuleSubvarZextused to cut it back to the low register.unsigned long long ins16(int a0,unsigned int a1). A word whose C type is signed gets the cast that makes C zero-extend it:return (unsigned int)(a1 + a0);.RDX:RAX) keep the trim, because a zeroedRDXthere is almost always-fzero-call-used-regsafter anintfunction. Where a 32-bit function's bytes are exactly those of a zero-extended return, it now readsunsigned long longthough the source returns a word: an i386intfunction scrubbed that way, gcc -O0'sint f(u64 a) { return a >> 32; }, or ChibiOS'schEvtGetAndClearEvents, which zeroesr1formsr basepribefore returning. The value is unchanged, and--option returnpair singlegives the word back.What this does not fix:
ins16round-trips on all four.return zsum(a, b) | 0xff00000000ULL;, now printsvoidindecompile-all, as single-functionkuna decompilealready does on main and as main does for any 64-bit callee ([AUTOMATED] A caller that changes only the high word of a 64-bit callee result prints void #808). Main'sdecompile-allprinted a return, but one that sign-extends the low word.u64 zx(unsigned a) { return a; }on ARM (mov r1,#0; bx lr) andlong long sx(int a) { return a + 3; }printvoidbefore and after ([AUTOMATED] A 64-bit return whose high word is the sign of the low word, or whose low word is the untouched argument, prints void #807).Tests
tests/stages/kuna-zextpair.xml(ARM): 5 of 6 assertions fail on main. The control passes on both.kuna-cli/tests/zext_pair_returns.rsbuilds ARM, MIPS and PowerPC little-endian and i386 objects. It compiles the printed C, callers included, with gcc and clang at -O0/-O2 and compares it with the source over 289 input pairs (544 wrong values on main for ARM). It also checks under-m32that every return is eight bytes on ARM, i386 and SPARC.passthrough_own_return.rs, the forwarderbl provider; mov r1,#0now returnsunsigned long long.decompile-allchanges no function over Lua 5.3 built for nine 32-bit targets (5,015 functions, including SPARC, ARM hard-float, MIPS and PowerPC big-endian). Over 15 decbench ARM firmware and i386 PE binaries (14,181 functions) it changes 7: one 64-bit return now right (betaflight,lsrs r0,r0,#8; movs r1,#0), the ChibiOS function above and four of its callers (variable numbering only), and one stretch of data decoded as code. Datatests are unchanged at 675/675. CPU time (min of 21 to 31 interleaved runs, five witnesses) moves between −4.9% and +1.4%.Fixes #769
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU