Skip to content

[AUTOMATED] voidret: a returned value its function also indexes with is returned - #1885

Merged
mahaloz merged 7 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/retvoid
Nov 22, 2026
Merged

mahaloz merged 7 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/retvoid

Conversation

@coleleavitt

Copy link
Copy Markdown
Contributor

[AUTOMATED] A function that returns a value it also uses as an array index prints as void, even when its callers read the result.

#include <string.h>
__attribute__((noinline)) size_t base_len(char const *name) {
  size_t len;
  for (len = strlen(name); 1 < len && name[len - 1] == '/'; len--) continue;
  return len;
}
int main(int argc, char **argv) { (void)argc; return (int)base_len(argv[0]) + 1; }
$ gcc -O2 -fno-inline -fno-pie -no-pie -fcf-protection=none t.c -o t
$ kuna decompile-all t
  return base_len(v1) + 1;
...
void base_len(char *a0)
{
  unsigned long len; // rax

  for (len = strlen(a0); (2 <= len && (a0[len - 1] == '/')); len = len - 1) {
  }
}

This is gnulib's base_len, so grep, find and gzip carry it; find's base_name and dir_len are the same shape.

Fix

  • When callers read the return register, score_forced lets the returned value also be stored, branched on, or handed back in another register (returned_use). It now also lets the value be added to another non-constant value: name + len - 1 makes len an index, and the load that sum reaches is not a use of len itself.
  • An addition of a constant still carries the value on, so a load or store through the value or the value plus a constant (a stream pointer, a record) still refuses it.

Tests

  • tests/cli/voidret-a-returned-index-is-still-returned.json (fixture voidret_indexed_x86_64, source beside it) fails without the change.
  • datatests 675/675 and the stage corpus are unchanged. On gcc -O2 -fno-inline builds of bzip2, gzip, grep, find and libcmark, functions with a DWARF return type printed void go from 79 to 75, and no void function gains a return.

Model: anthropic/claude-opus-5-5:high

coleleavitt and others added 7 commits November 22, 2026 06:48
…it alone

gcc keeps an argument in rdi across a call to a function it knows does not
write it. Inside a loop heritage then joins the incoming rdi with the rdi
carried back past the call, AncestorRealistic reads the call's INDIRECT as a
kill and marks the trial definitely not used, and the call printed
add_pair() while add_pair(S *) was recovered in the same run.

passthrough now follows copies, phis and non-creating INDIRECTs back to the
function's own incoming register, and check_input_trial_use scores such a
trial inactive when the callee's statement has a parameter there. Over gcc
-O2 -fno-inline bzip2, gzip, grep, find and libcmark, 37 of 121 calls that
passed nothing to a callee with parameters now pass its argument.

[AUTOMATED]
gnulib base_len loads through name + len - 1 and returns len, and its
callers read rax, yet it printed void: onlyOpUse followed the sum to the
LOAD and refused the trial. An addition to another variable makes the value
an index, so under forced return scoring that use no longer competes; a
load or store through the value plus a constant still refuses it.

[AUTOMATED]
…register alone

forwarded_own_input followed every non-creating INDIRECT back to the
incoming register, but the cspec gives every call an unknown effect on the
argument registers it does not list as killed (x86-64 rdi/rsi/rcx/r8/r9,
AArch64 x2..x7), so the INDIRECT says nothing about whether the value
survived. On AArch64 C code that invented parameters: dash killcmd became
killcmd(int, void *, unsigned long a2) forwarding x2 past kill/strerror to
sh_warnx, whose va_start save reads x2.

Each INDIRECT on the chain must now guard a direct call (not a PLT stub)
whose decoded callee body the callee-write probe proves never writes the
register. This is only an extra refusal: a refused chain falls back to
upstream's definitely-not-used scoring, which is main's behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…obbered-register probe

The spec paragraph and the phases.toml summary say the INDIRECTs followed
must belong to calls proven not to write the register (options.md and
phase_catalog.json regenerated). New CLI probe
passthrough-drops-a-register-an-unproven-call-may-clobber on fixture
passthrough_clobbered_aarch64 (clang-21 AArch64 .so, recipe in the .c):
check(int, char **) calls the import ext and then a variadic vlog without
setting x2; it must keep two parameters and pass vlog no a2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
@mahaloz
mahaloz merged commit 4f6a995 into Noelo-Lab:main Nov 22, 2026
2 checks passed
@coleleavitt
coleleavitt deleted the fix/retvoid branch November 22, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants