Repository navigation
[AUTOMATED] fix(p4): a caller that changes only the high word of a callee result prints void - #855
Merged
Merged
Conversation
…llee result returns all eight bytes
`u64 full_or(unsigned a) { return full(a) | 0xff00000000ULL; }` is, on 32-bit
ARM, `bl full; orr r1,r1,#255; bx lr`: r0 comes back from full untouched and
only r1 is written. Return recovery refused r0 as the call's INDIRECT
creation, and the output model never returns r1 without r0, so the function
printed as `void full_or(int a0) { full(a0); }`.
The new p4_calls/kuna_retcallhalf.rs makes the first register of the pair
active when, at every live RETURN, it is a call's untouched result, the second
register is computed on purpose and read only by the RETURN, and the model
returns exactly those two registers. "On purpose" excludes the other output of
a two-register instruction, frame restores and reloads, an argument set up for
a later call or svc, and the -fzero-call-used-regs zero. Pairs of unequal
width and big-endian pairs are refused.
Tests: tests/stages/kuna-retcallhalf.xml (ARM callers plus four controls) and
kuna-cli/tests/call_result_pair_returns.rs (ARM, MIPS and i386 decompile-all
output compiled back with gcc and clang and checked against the source).
Fixes #808
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz
force-pushed
the
fix/hi-word-only-return
branch
from
October 2, 2026 21:47
0cb0006 to
8e1a6d6
Compare
mahaloz
added a commit
to phix33/kuna
that referenced
this pull request
Oct 2, 2026
Brings in Noelo-Lab#855. Corpus count 382 (main 381 + kuna-stackstoreguard); stages baseline re-recorded (1707 = main 1704 + the 3 STACK STORE keys). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz
added a commit
that referenced
this pull request
Oct 3, 2026
…ow word, or whose low word is the argument, printed void (#879) ## The problem On 32-bit targets, a function returning a 64-bit integer whose high word is computed from the low word, or whose low word is its own argument left in place, printed as `void f(void)`, losing both the return value and the parameter. ```sh printf 'typedef unsigned long long u64;\nu64 zx(unsigned a) { return a; }\nlong long sx(int a) { return a + 3; }\n' > fu.c clang --target=arm-linux-gnueabi -O2 -c fu.c -o fu.o # zx: mov r1,#0; bx lr sx: add r0,r0,#3; asr r1,r0,#31; bx lr kuna decompile-all fu.o ``` ```c // Function: zx @ 0x400000 void zx(void) { return; } // Function: sx @ 0x400008 void sx(void) { return; } ``` `sx` is also `void` on i386 (`sar $31,%edx`, gcc `cltd`) and MIPS (`sra $3,$2,31`). With this change they print `unsigned long long zx(unsigned int a0) { return a0; }` and `long long sx(int a0) { return a0 + 3; }`. ## The fix - The #855 rule that keeps a call's untouched result as the low register of a pair now also keeps the function's own argument left in place, and a low word read only by the RETURN and by what turns it into the high word. - The high register must be computed by the function and read by nothing but the RETURN. A load does not count, a zero counts only when the function names that register nowhere else (so a `-fzero-call-used-regs` scrub stays `void`), and a register also handed to a store, a call or `vmsr fpscr`/`msr cpsr_c` stays `void`. - The late pair repair kept the high register alone when the low one was the argument reloaded from its spill (clang `-O0` printed `return 5;` for `a | 5ULL << 32`); it keeps the pair now. - No option: the rule only fires where the function returns nothing today. The argument kinds turn off with `retinputhalf`. Not fixed: RISC-V `li a1,0; ret` (no instruction names `a0`), a loaded high word beside the argument, a high register that feeds the low one (also how an `int` division by a constant ends), and an ARM conditional return (`asrlt r1,r0,#31; bxlt lr`) whose `r1` is also taken as an argument of a later call. ## Tests - `tests/stages/kuna-retpairhalf.xml`: 5 of 8 assertions fail on main; the rest are controls (`int div7`, a stored sign word, a scrubbed `r1`, an `svc` argument, `r1` written to `fpscr` or `cpsr`). - `kuna-cli/tests/pair_return_halves.rs` compiles the ARM, MIPS and i386 output back with gcc and clang at -O0 and -O2 and checks it against the source over 225 input pairs; it fails on main. - `decompile-all` over 38 stripped ARM, i386 and x86-64 decbench binaries (30,964 functions) changes 20: `__aeabi_dadd`/`__aeabi_ddiv` exits in eight firmware images, which printed the new high word alone and now return `CONCAT44(hi,a0)`; u-boot's `memcpy` and `__of_translate_address`; and two copies of a betaflight `tbb` jump table decoded as code. Lua 5.4 for five 32-bit targets at O0 and O2 (12,503 functions) changes none. - `decompile-all` CPU time over betaflight, crazyflie and nuttx (O2), paired runs, min of 11: 70.3 s on main, 69.7 s with the change. Fixes #807 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz
added a commit
that referenced
this pull request
Oct 6, 2026
…s part of a callee's high word gcc's i386 code pushes a call's argument, so a function that returns a callee's 64-bit result with part of the high word changed never names %eax. Heritage gave it no EAX return trial, and it printed void in single-function mode (#853); a byte write (or $0xff,%dl) made a one-byte DL trial that the output model joined with a planted EAX into undefined5, and or $0xff,%dh was dropped (#852). kuna_retcallhalf::plant runs at the end of ActionFuncLink: when every live RETURN is reached from a direct call along single-predecessor blocks and the last write on the way is to the second register of a two-piece join entry, each RETURN gets a read of the first register if nothing names it and of the whole second register if only part of it is named. A write that also moves the stack pointer (pop %edx) ends the rule, and so does any write of the first register. kuna_retcallhalf::accept_pieced takes the pair when the second register is the call's result with some bytes rewritten (upstream's ancestorOpUse follows a PIECE through its low part only) and the first is the call's untouched result. No option: this extends retcallhalf (#855) to the shapes where heritage never made the trials. Only two-piece join entries take part, so x86-64's RAX/RDX pair is untouched. Fixes #852 Fixes #853 Part of #890 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Qihrih8NnnexavqvZxp8CF
mahaloz
added a commit
that referenced
this pull request
Oct 6, 2026
…s part of a callee's high word gcc's i386 code pushes a call's argument, so a function that returns a callee's 64-bit result with part of the high word changed never names %eax. Heritage gave it no EAX return trial, and it printed void in single-function mode (#853); a byte write (or $0xff,%dl) made a one-byte DL trial that the output model joined with a planted EAX into undefined5, and or $0xff,%dh was dropped (#852). kuna_retcallhalf::plant runs at the end of ActionFuncLink: when every live RETURN is reached from a direct call along single-predecessor blocks and the last write on the way is to the second register of a two-piece join entry, each RETURN gets a read of the first register if nothing names it and of the whole second register if only part of it is named. A write that also moves the stack pointer (pop %edx) ends the rule, and so does any write of the first register. kuna_retcallhalf::accept_pieced takes the pair when the second register is the call's result with some bytes rewritten (upstream's ancestorOpUse follows a PIECE through its low part only) and the first is the call's untouched result. No option: this extends retcallhalf (#855) to the shapes where heritage never made the trials. Only two-piece join entries take part, so x86-64's RAX/RDX pair is untouched. Fixes #852 Fixes #853 Part of #890 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Qihrih8NnnexavqvZxp8CF
mahaloz
added a commit
that referenced
this pull request
Oct 6, 2026
…s part of a callee's high word (#955) On i386, a function that returns a callee's 64-bit result with part of the high word changed lost that part. gcc pushes the call's argument, so the function never names %eax: single-function decompile printed void (#853), and a byte write to %edx came back five bytes wide (or $0xff,%dl) or was dropped (or $0xff,%dh) (#852). - kuna_retcallhalf::plant (end of ActionFuncLink): when every live RETURN is reached from a direct call along single-predecessor blocks and the last write on the way is to the second register of an EDX:EAX-style join entry, each RETURN gets a read of the first register if nothing names it and of the whole second register if only part of it is named. Not when that write also moves the stack pointer (pop %edx), when a later instruction reads the bytes it wrote, or when the function writes or otherwise reads the first register. - kuna_retcallhalf::accept_pieced takes the pair when the second register is a PIECE of the call's untouched bytes and at least one computed byte (constant or arithmetic), and the first is the call's untouched result. A one-byte global no longer counts as a flag in the read-only test. - Only join entries whose low register the model also returns alone take part (i386 EDX:EAX); ARM, MIPS o32 and x86-64 pairs and cspecs listing the low register first are untouched. - The uncomputed-half repair no longer keeps EDX alone on i386; that RETURN returns nothing. No option: extends #855's rule; decompile-all over 66 binaries (13,269 functions) changes no function, and the new paths fire nowhere outside the test shapes. Fixes #852 Fixes #853 Part of #890 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Qihrih8NnnexavqvZxp8CF
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.
A function that returns a callee's 64-bit result with only the high word changed printed as
void, and the call's result was thrown away. The same happened to a sign-extended call result and to a call result next to a constant high word.full_orisbl full; orr r1,r1,#255; pop {r11,lr}; bx lr, sor0comes back fromfullas it is. With this change it printsunsigned long long full_or(int a0) { return full(a0) | 0xff00000000; }, andkuna decompile fo.o full_or(alsovoidbefore) prints the same.The fix
r0because at the return it is the call's untouched result, and the output model never returnsr1withoutr0. The newp4_calls/kuna_retcallhalf.rsaccepts the first register when, at every return, it is a call's untouched result, the second register is computed and read only by the return, and the model then returns exactly those two registers.smulllow word), a restore or reload from the frame (gcc'spop {r1,r2,r4,pc}, an-O0reload), an argument for a later call orsvc, and the-fzero-call-used-regszero.voidtoday while computing a register only a pair return can use.Not fixed here: a byte write such as gcc's i386
or $0xff,%dl(#852), i386 code that pushes its arguments and never names%eax, in single-function mode (#853), and big-endian pairs. On Cortex-M, a caller that builds the high word from a narrower piece of the callee's own (uxtb r1,r1) now returns eight bytes, but the call still loses that piece (#851, which already shows on main).Tests
tests/stages/kuna-retcallhalf.xml(ARM): 5 of 7 assertions fail on main; the other two are the controls (thesmullword, the hardening zero, the dummy pop and thesvcargument stayvoid; a low-word-only caller keepsint).kuna-cli/tests/call_result_pair_returns.rsbuilds ARM, MIPS and i386 objects, compiles the printed C with gcc and clang at -O0 and -O2, and checks it against the source. It fails on main.decompile-allover 31 stripped ARM, i386, MIPS and x86-64 binaries (26,265 functions) changes one function: in cf2 (-O2 -fno-inline), a function that tail-calls libgcc's__fixunssfdinow returns its result.__fixunsdfdiand__fixunssfdithemselves already return theirs on main since [AUTOMATED] fix(p5): float returns printed as integers and callee results printed as void #757.decompile-alltime over five of them is unchanged (min of 11, user+sys: 39.1 s on main, 38.5 s with the change).Fixes #808
🤖 Generated with Claude Code
https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt