Skip to content

[AUTOMATED] feat(p5): ptrfromuse void by default - #690

Merged
mahaloz merged 1 commit into
mainfrom
feat/ptrfromuse-on
Sep 20, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/ptrfromuse-on

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

The problem

A pointer-width parameter that a function only ever dereferences is declared long, so every
field access through it prints as integer arithmetic and the declaration says nothing. The
qsort-style wrappers that only forward such a pointer inherit the same long:

$ cat c.c
struct fi { char *name; long mtime; };
__attribute__((noinline)) int cmp_mtime(struct fi const *a, struct fi const *b) { return (a->mtime > b->mtime) - (a->mtime < b->mtime); }
int rev_mtime(void const *a, void const *b) { return -cmp_mtime(a, b); }
int main(int argc, char **argv) { return rev_mtime(argv, argv + 1); }
$ gcc -O0 -o c c.c && kuna decompile-all c | grep -A3 '^int [a-z_]*_mtime('
int cmp_mtime(long a0,long a1)
{
  return (unsigned int)(*(long *)(a1 + 8) < *(long *)(a0 + 8)) - (unsigned int)(*(long *)(a0 + 8) < *(long *)(a1 + 8));
}
--
int rev_mtime(long a0,long a1)
{
  return -cmp_mtime(a0,a1);
}

--option ptrfromuse void already prints both as (void *a0,void *a1), which is what the
source declares. This makes that the default.

The change

  • ptrfromuse defaults to void (was off). Field accesses keep their byte arithmetic with a
    cast on the base (*(long *)((long)a0 + 8)); --option ptrfromuse off restores the integer.
  • void over byte: on the 444-slice decbench type sweep void moves 204 functions onto a
    perfect type_match and 85 more up, byte 7 and 21, and neither moves any function down.
    What void wins is the void const * callbacks — ls's sort comparators and gnulib's hash
    and comparator callbacks — reached through protoorder from the callee that dereferences the
    pointer.
  • Where it is wrong is a parameter the program declares as an integer and casts to a pointer in
    its first statement: seven betaflight bus callbacks (busStatus_e mpuIntCallback(uint32_t arg))
    go from 0.0 to a worse score on four firmware images, against 30 that improve. That ambiguity
    is what the option's use_when names.

The tests

  • make test 675/675 unchanged; make test-stages 1250/1250 (13 assertions and 1 cargo test
    pinned a dereferenced-only parameter's spelling and follow the void * one — the read-before-store
    order ALIASOVERLAP asserts does not move); make test-cli 209/209 with one new probe,
    ptrfromuse-default-declares-a-dereferenced-parameter-void.
  • Whole-corpus diff (11 binaries, 4,490 functions: 836 change, all declarations, casts, reordered
    sums and two address-temporary folds; no argument, variable, call or load-order change) and speed:
    docs/features/ptrfromuse/default-on-evaluation.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG

@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 20, 2026
A pointer-width parameter whose every use in the body is a dereference is now
declared `void *` instead of `long`, and with `protoorder` a function that only
forwards such a pointer is declared with `void *` too. Field accesses keep
their byte arithmetic with a cast on the base (`*(long *)((long)a0 + 8)`);
`--option ptrfromuse off` restores the integer declaration and the uncast
arithmetic.

Measured on this base: 444-slice type sweep 1,147 -> 1,351 perfect type_match
(+204), aggregate +232.71, 85 more improved, 0 worse (`byte` is +7); on four
firmware images 216 = 216 perfect, 30 improved and 7 worse, all seven betaflight
bus callbacks the program declares `uint32_t arg` and casts to a device pointer
in their first statement. Arity, call arguments and variable counts are
unchanged over 4,490 corpus functions; 836 of them change, all declarations,
casts, reordered sums and two address-temporary folds; speed worst +2.09%
(pooled min-of-30, budget +5%).

13 stage assertions, one kuna-cli test and four CLI probes pinned a
dereferenced-only parameter's old spelling and follow the new one.

Evidence: docs/features/ptrfromuse/default-on-evaluation.md.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
@mahaloz
mahaloz merged commit d8b9c0b into main Sep 20, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/ptrfromuse-on branch September 20, 2026 04:08
mahaloz added a commit that referenced this pull request Sep 20, 2026
…d speed after the body clause

770 binaries re-swept: identical DIFF set (21), every hunk identical except
e2fsck's int8 -> void * which is #690 on the base. Arity counters on the JSON
variables[] surface across the 21 changed binaries: 23,510 functions, 0
gained/lost, 47,887 arg rows in both arms, 0 functions with a changed arg or
variable-row count. Typesweep 444 slices 1351 -> 1351, 0/0. Speed interleaved
min-of-15 worst +0.47%.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz added a commit that referenced this pull request Sep 20, 2026
…d speed after the body clause

770 binaries re-swept: identical DIFF set (21), every hunk identical except
e2fsck's int8 -> void * which is #690 on the base. Arity counters on the JSON
variables[] surface across the 21 changed binaries: 23,510 functions, 0
gained/lost, 47,887 arg rows in both arms, 0 functions with a changed arg or
variable-row count. Typesweep 444 slices 1351 -> 1351, 0/0. Speed interleaved
min-of-15 worst +0.47%.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant