Repository navigation
[AUTOMATED] fix(p9): (NOVEL) realtypes keeps an unknown pointee size (DIV-48) - #232
Merged
Merged
Conversation
…ealtypes relabel
`realtype_unknown_base` short-circuited to `void` for EVERY size when the
residual `TYPE_UNKNOWN` base sat under a pointer modifier, so `undefined1 *`,
`undefined4 *` and `undefined8 *` all rendered `void *`.
Only the DECLARATION was relabelled. `opLoad` / `opPtradd` keep building index
and cast expressions from the ORIGINAL pointee size, so the declaration and the
expressions disagreed about the stride:
int4 set_acl_fd(unsigned long a0,uint a1,uint a2,void *a3)
if ((code *)a3[1]) // byte offset 1 under GCC's
a0 = (*(code *)a3[1])(a3,a0); // void-arithmetic extension; the
// expression was built for offset 8
`gcc -std=gnu11 -fsyntax-only` on that body reports 12 "invalid use of void
expression" errors and 12 "dereferencing 'void *' pointer" warnings. The same
short-circuit dropped the access width from stores (`*(void *)
__errno_location() = 0x16;` for a 4-byte store).
The relabel now runs a `TYPE_UNKNOWN` pointee through the SAME size table a
scalar uses -- `undefined8 *` -> `unsigned long *`, `undefined4 *` ->
`unsigned int *` -- and keeps `void` only as the fallback for residual sizes
with no natural single C type (0, 3, 5, 6, 7, 10, ...).
P5 never mis-typed anything: `--option realtypes off` already produced the
stride-consistent `xunknown8 *a3` with the same `a3[1]`. This was purely the
P9 presentation policy, and the off path is untouched. A genuine `TYPE_VOID`
pointee is not a residual unknown and never enters the relabel, so
`free`/`malloc`/`memcpy`/`realloc` keep their opaque `void *` (pinned by a new
unit test).
Strict bug fix inside an existing default-on option (DIV-6), so no new flag;
recorded as DIV-47.
Measured on 5 whole-binary `decompile-all --mode reliable` runs (libacl, gzip,
mydoom, mirai, coreutils fmt): `*(void *)` cast sites 737 -> 1, `void *`
occurrences 1,585 -> 198, emitted line counts byte-for-byte unchanged. The one
residual is a 10-byte x87 `long double` pointee, where `void` is the designed
fallback. Least-contended-run timings over 7 interleaved pairs: gzip +0.51%,
libacl +0.13%, mirai -1.48%.
Gates: make test PARITY OK (675/675, baseline untouched), make test-stages
PARITY OK (321/321), make rust-test green, make check-spec OK (strict),
kuna catalog --check OK.
inspiration = "decbench:O2-noinline-libacl-libacl.so.1.1-set_acl_fd; NOVEL pool"
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo
…-size # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # docs/baseline-stages.json # tests/stages/README.md
mahaloz
added a commit
that referenced
this pull request
Aug 1, 2026
mahaloz
added a commit
that referenced
this pull request
Aug 1, 2026
…#235) * [AUTOMATED] fix(p8): (NOVEL) print the entry component first (DIV-48) Port `BlockGraph::orderBlocks` (block.hh:437) and call it where upstream does, as the first line of `ActionFinalStructure::apply` (blockaction.cc:2192). Structuring does not always end with a single top-level component; when it leaves several, the printer walks the root component list in order. kuna had never ported the sort that puts that list in final order, so the list stayed in COLLAPSE order -- whichever component the collapse happened to append first printed first. A function could therefore open in the middle of its body and reach its real entry only after an unconditional `goto`, i.e. emit the entry as unreachable dead code. On the campaign case (libopencm3 sdram `main`) the body opened on the 'p'/'P' command handler and printed `clock_setup(); console_setup(); sdram_init(); ...` after `goto label_8000792;`. The producer of the ordering key was already ported -- `BlockGraph::add_block` keeps a composite's `index` at the minimum over its members -- so only the sort was missing. It now runs with upstream's key (`FlowBlock::compareFinalOrder`, block.cc:709): entry component (`index == 0`) first, RETURN-terminated components last, everything else by ascending index; root graph only (upstream does not recurse). `FlowBlock::lastOp` gains its missing `t_copy` / `t_goto` / `t_multigoto` overrides so the RETURN half of the key can resolve a structured component through the `BlockCopy` mirror into `bblocks`; the sort is stable, so the several RETURN-terminated components upstream's comparator reports as equal keep a deterministic order rather than `std::sort`'s unspecified one. Both structuring engines are covered: `CollapseStructure` and the default-on region structurer hand `ActionFinalStructure` the same root list. Strict bug fix restoring upstream behavior -- no option (the current output is unambiguously wrong C). Gates: 675/675 PARITY OK, 324/324 stages PARITY OK (delta is purely the 6 new keys -- no re-pin, no per-test opt-out), rust-test green, check-spec OK (strict), catalog OK. Measured over 12 decbench binaries / 3,434 functions: "unconditional goto followed by a statement" 25 -> 0, "body opens with a label" 29 -> 3 (the 3 residual labels sit at the entry block's own address, a legitimate back-edge target). Blast radius 30 of 3,434 functions (0.87%) change text at all, and the whole changed set keeps its goto count and line count exactly (1,172 gotos / 16,123 lines before and after) -- the statements are a permutation. Speed, interleaved medians of `decompile-all --mode reliable`: O0 diffutils `diff` 7.38 s -> 7.07 s, O2 `bzip2` 15.06 s -> 15.18 s (+0.8%). inspiration = "decbench:O0-libopencm3-sdram-main; NOVEL pool" Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo * [AUTOMATED] renumber DIV-48 -> DIV-49 (DIV-48 taken by #232) --------- Co-authored-by: Claude Opus 5 (1M context) <[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 bug
realtype_unknown_base(decompiler/crates/kuna-decomp/src/p9_emit/printc.rs) returnedSome("void")unconditionally when the residualTYPE_UNKNOWNbase sat under a pointermodifier.
declarator_partssets that flag for any pointer-to-unknown, soundefined1 *,undefined4 *andundefined8 *all printedvoid *.Only the declaration was relabelled.
opLoad/opPtraddkeep building index and castexpressions from the ORIGINAL pointee size, so the declaration and the expressions disagreed
about the stride.
voidis also the one pointee spelling that carries no width, so a storecast down to
*(void *)lost its access width entirely.realtypesis a P9 presentation policy — P5 never mis-typed anything.--option realtypes offalready produced the stride-consistentxunknown8 *a3alongside the samea3[1].Provenance:
inspiration = "decbench:O2-noinline-libacl-libacl.so.1.1-set_acl_fd; NOVEL pool"(kuna already ties or beats every rival decompiler on this source function and still emitted
non-compiling C, so no rival surfaced it).
Reproduction 1 — libacl
set_acl_fd@ 0x56c0Before / after (unchanged lines elided; the only difference in the whole function is the
parameter type):
Stride 8 is what the source says:
struct error_contextis three function pointers at+0/+8/+16
(
results/full_run/O0/libacl/compiled/la-perm_copy_fd.i:5348).--option realtypes offindependently agrees:
xunknown8 *a3, samea3[1].Reproduction 2 — libacl
acl_calc_mask@ 0x2820 (the width loss)Both are 4-byte stores;
*(void *)claimed no width at all.--option realtypes offshows*(xunknown4 *)in both places — the exact width the relabel now preserves.gcc -fsyntax-onlydemonstrationReproduction 1's emitted body, with a 12-line prelude declaring
int4/int8/codeand thesix libc callees, no other edits:
(The one remaining diagnostic in both is my prelude's
dcgettextdeclaration disagreeing withthe GCC builtin — not kuna's output.)
The fix
voidbecomes the fallback, not the answer: aTYPE_UNKNOWNpointee now runs through thesame size table a scalar unknown uses (
char/unsigned short/unsigned int/unsigned long|unsigned long long), and only residual sizes with no natural single C type(0, 3, 5, 6, 7, 10, …) degrade to
voidunder a pointer. As a scalar those sizes still keepundefined<N>, exactly as before. One call site, no second mapping introduced.RealTypeCtx::OFFand the whole--option realtypes offpath are untouched.Genuine
TYPE_VOIDpointers are unaffected. They are not residual unknowns, sorealtype_relabelalready returnedNonefor them — provable from the fact that they rendervoid *withrealtypes offtoo. In the libacl whole-library run the 35 survivingvoid *occurrences are byte-identical to the
realtypes offrun (free(void *),memcpy(void *, void *, uint8),malloc,realloc,void *v1; // rax, …), the onlydifference being the one parameter this PR fixes. Pinned by a new unit test,
realtypes_keeps_genuine_void_pointers, which assertsvoid/void */void **areidentical with the gate ON and OFF.
Whole-binary scale
kuna decompile-all --mode reliable, same build except the one-line policy:*(void *)casts beforevoid *occurrences beforefmtLine counts are identical binary-for-binary, as expected for a pure rendering change.
The single residual cast is gzip's
*(void *)&v3[4] = *v4;, where the pointee is a 10-bytex87
long double(realtypes offrenders it*(undefined10 *)). Size 10 has no naturalsingle C type, so
voidis the designed fallback there.For libacl specifically the post-fix
*(...)cast census (93*(unsigned long *),54
*(unsigned int *), 3*(char *)) matches therealtypes offcensus(93
*(xunknown8 *), 54*(xunknown4 *), 3*(xunknown1 *)) one-for-one — the declarationand the expressions now agree everywhere the off path already did.
Why no new flag
realtypesis already a named, default-ON option (DIV-6). This PR does not add a decisionpoint; it corrects what that option does. Per
CLAUDE.md, "a strict bug fix that only correctswrong output needs no flag", and the output being corrected does not compile (
error: invalid use of void expression) and silently discards access width. There is also no coherent"keep the old behavior" setting to expose: the old rendering was self-contradictory with
expressions the same printer emitted, and the stride-preserving spelling is already what
--option realtypes offproduced. Recorded as DIV-47 indocs/history.md.Tests
tests/stages/ghdec-realtypes-pointee.xml— real machine code (libaclset_acl_fd@ 0x56c0and
acl_calc_mask@ 0x2820, callees stubbed at their real addresses), two passes: default,then
option realtypes off.no-
void *-anywhere invariant (Port to Rust #2), and the two store widths (cleanup: Rust-first restructure + terminology refresh #3, Recover PLT/GOT import names in ELF decompilation #4).xunknown8 *a3,*(xunknown4 *)__errno_location()).(code *)a3[1]is the same in both passes — i.e. thedeclaration moved to match the expressions, the expressions did not move.
tests/stages/gh6930-inferfuncentry.xml— two assertion regexes updated. They pinbufferevent_setcb(*(void *)(v2 + 0x10),0,…); the cast is incidental context for that test(its subject is
0x100000resolving toevhttp_write_cb) and is exactly the width-losingform this PR fixes, so it now reads
*(unsigned long *)(v2 + 0x10). Both assertions stillpass under their original names, so
docs/baseline-stages.jsonrecords no rename.realtypes_relabels_unknown_bases(unit) updated for pointer-to-unknown;realtypes_keeps_genuine_void_pointers(unit) added.docs/baseline.jsonis not re-pinned — the datatest corpus does not move.Gates
make testdocs/baseline.jsonuntouched)make test-stagesmake rust-testmake check-spec--strictkuna catalog --checkcatalog OK: documents exactly the registered kuna optionsdecompiler/crates/kuna-base/src/xml.rscorpus file count bumped 176 → 177.docs/spec/09-emission.md(§9.2 literal format) describes the new pointee rule, thevoidfallback and the
TYPE_VOIDexemption in prose.Speed
decompile-all --mode reliable, 7 interleaved before/after pairs. The box was heavilycontended (several concurrent builds), which makes the medians bimodal; the least-contended
run per side is the robust estimator:
Well inside the +5% budget — as expected, the change is one
matcharm on a rendering path.🤖 Generated with Claude Code
https://claude.ai/code/session_011RXVU58TKJxb518oViChwo