Repository navigation
x8664-cvs-863633: collapse duplicate scalar local declarations (option dedupvardecls) - #42
Merged
Merged
Conversation
…n dedupvardecls, DIV-7) Close the angr-vs-kuna gap on test_decompiling_x8664_cvs::main (x86_64/cvs): kuna emitted a wall of duplicate local-variable declarations (the stack slot `stack - 0x3c` declared 166x, `stack - 0x38` 53x) where angr declares each local once -- the dominant cause of main being ~30% longer than angr (677 vs 472 loc). kuna's C printer walks HighVariables (the W4 ScopeLocal Symbol walk is the missing surface), so many distinct scalar highs sharing one stack slot, mapped by the angr-style naming to the same name+type+storage, each emit one declaration line -- textually identical, strictly invalid C re-declarations. emit_local_var_decls now skips a declaration whose fully-rendered signature (type + name + array adornment + storage comment) is byte-identical to one already emitted: the scalar analogue of the existing composite-symbol collapse, approximating Ghidra's once-per-Symbol emitScopeVarDecls walk. Pure presentation: body markup is unchanged. option dedupvardecls (arch flag dedup_var_decls, ElementId 4091), DIV-7 default-on: ablation 0/675 (PARITY OK without re-pin), speed +0.14% (within 5% budget). New module s9_emit/kuna_dedupvardecls.rs; stage test tests/stages/ghangr-x8664-cvs-863633.xml (+2). main 680 -> 461 loc with the flag on. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
APPROVED |
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
Bring the dedupvardecls feature branch up to current main. Conflicts were mechanical, additive registrations resolved by UNION: - stages.toml: 39 settable blocks (foldcallret + dedupvardecls), header count updated - catalog_bytecompat / kuna_stages tests: settable count 39 - xml corpus count: 135 (83 datatests + 52 stage testcases) - kuna-catalog.xml / baseline KUNA-CATALOG #6: 5 angr-derived options (loweredswitch, namestyle, stackguard, foldcallret, dedupvardecls) - PROGRESS.md: both session entries kept - assertions.md + baseline-stages.json regenerated Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (163/163). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Bring the dedupvardecls feature branch up to current main. Conflicts were mechanical, additive registrations resolved by UNION: - stages.toml: 39 settable blocks (foldcallret + dedupvardecls), header count updated - catalog_bytecompat / kuna_stages tests: settable count 39 - xml corpus count: 135 (83 datatests + 52 stage testcases) - kuna-catalog.xml / baseline KUNA-CATALOG #6: 5 angr-derived options (loweredswitch, namestyle, stackguard, foldcallret, dedupvardecls) - PROGRESS.md: both session entries kept - assertions.md + baseline-stages.json regenerated Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (163/163). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
force-pushed
the
feat/angr-x8664-cvs-863633
branch
from
June 25, 2026 15:23
2ecbe48 to
736f11a
Compare
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.
x8664-cvs-863633: collapse duplicate scalar local declarations (
option dedupvardecls, DIV-7)Closes the angr-vs-kuna gap on
test_decompiling_x8664_cvs::main(x86_64/cvs). kuna emitted awall of duplicate local-variable declarations — on cvs
mainthe single stack slotstack - 0x3c(option_index) was declared 166 times,stack - 0x3853×, etc. — where angrdeclares each local exactly once. This was the dominant cause of kuna's
mainbeing ~30% longerthan angr (677 vs 472 loc); with the fix on,
maindrops to 461 loc.See
docs/features/x8664-cvs-863633/analysis.mdforthe full side-by-side analysis.
Why angr is better
angr's variable recovery yields one variable per storage location, so its declaration block lists
each local once. kuna's C printer instead walks HighVariables (the W4
ScopeLocalSymbol walkis the documented missing surface), so when the angr-style naming maps many distinct scalar
HighVariables that share one stack slot to the same name + type + storage, kuna emits one
declaration line per high — textually identical, and (strictly) invalid C re-declarations. The
function body refers to all of them by the one shared name, so the duplicate declaration lines
are pure noise.
Mechanism (S9 emit)
emit_local_var_decls(s9_emit/printc.rs) now skips a declaration whose fully-renderedsignature (final declarator type + name + array adornment + storage comment) is byte-identical to
one already emitted — the scalar analogue of the composite-symbol (array/struct/union) collapse kuna
already performs, approximating Ghidra's once-per-Symbol
emitScopeVarDeclswalk. The option parserand the
DeclDedupsignature tracker live in the new modules9_emit/kuna_dedupvardecls.rs(ElementId 4091). Pure presentation: the statement body markup, naming, and which HighVariables
exist are all unchanged — only redundant declaration lines are removed (provably lossless: it
removes only lines whose emitted bytes are character-identical to an already-emitted one).
Option
option dedupvardecls on|off(arch flagdedup_var_decls), DIV-7 default-on.option dedupvardecls off, orkuna decompile <bin> <fn> --option dedupvardecls off.kuna catalog --json(provenance:source_decompiler="angr").Ablation / parity / speed
(
make teststays PARITY OK without baseline regeneration).tests/stages/ghangr-x8664-cvs-863633.xml(+2 assertions);make test-stagesPARITY OK.🤖 Generated with Claude Code
Before / after —
mainincvsReal captured kuna output on the function this feature was built for, with
option dedupvardeclsflipped. Ported from angr — test_decompiling_x8664_cvs; angr variable recovery (one variable per storage location, declared once); main.dedupvardecls offdedupvardecls on(default)kuna — before (
option dedupvardecls off)kuna — after (
option dedupvardecls on)angr reference (the goal, v9.2.213)