Repository navigation
Conversation
…atural loops angr's RegionIdentifier (Phoenix) structures sub_442300 (Go Windows PE, 0x442300) as a single clean while(true) with continue and one goto; kuna emits 31 goto/label tokens, rendering the natural-loop head at 0x4425a0 as a goto target instead of a loop header. The gap lives in kuna's S7/S8 collapse-based structurer (blockaction.rs); unlike loweredswitch there is no single upstream artifact to inject, so it cannot be a single option-gated Action/Rule. Decider verdict: scope=large. Escalated as a [PROPOSAL] draft PR (analysis + reproduction artifacts only, no engine change) for human go/no-go on path A (extend collapse structurer) vs B (wire in the ported RegionIdentifier). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
…dmap
Append an "Inc 1 - implementation status & findings" section recording: the
landed parity-safe seam (sequence + structural-ITE + SAILR virtualize, RI over
the real CFG, honest-partial fallback), and the empirical finding that the
roadmap's "one fewer goto on if(c){A}else{B}->join->tail" target does not
reproduce - Ghidra's CollapseStructure already emits zero gotos on all acyclic
shapes tested (25+, gcc -O0/1/2 + clang), emitting only minimal crossing-edge
gotos that need Inc 2 ITE. The goto-count reduction belongs to the cyclic
increments (Inc 3 loops: the PR #44 / 1after909 multi-exit-cleanup family).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Jun 25, 2026
Merged
Contributor
Author
|
Closing — folded into the loop-refinement follow-up (PR #95 landed the parity-safe infra; the goto-win for these irreducible/multi-exit loops is documented as Inc-6 in docs/region-structurer-roadmap.md: acyclic-schema completion + SAILR continuation hoisting). |
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.
[PROPOSAL] phoenix-natural-loop-region: recover head-in-body natural loops (angr Phoenix)
Status: proposal / draft — no engine code changed. Human go/no-go requested on
which implementation path to fund.
The problem
angr's decompiler structures
sub_442300(
test_decompiling_phoenix_natural_loop_region_head_in_body, 0x442300, a Go WindowsPE) as a single clean
while (true) { … continue; … }with exactly onegoto.kuna renders the same function with 31
goto/label_tokens: the natural-loophead at
0x4425a0becomeslabel_4425a0:withgoto label_4425a0;back-edges, andthe loop body is scattered across ~10 more labels. See
docs/features/phoenix-natural-loop-region-1c12bf/analysis.md,angr-vs-kuna.txt,kuna-full.txt.(kuna currently loads this binary only under
--experimental-formats; the defaultloader rejects the PE. A stage testcase would therefore need a synthesised bytechunk
of just the loop CFG, not the whole Go function.)
angr reference
RegionIdentifier(Phoenix structuring),angr/analyses/decompiler/region_identifier.py— natural-loop region constructionwhere the loop head node is also reachable inside the loop body.
Why it is large (not a single Action/Rule)
kuna's printed C comes from the upstream Ghidra collapse-based structurer
(
s8_structure/blockaction.rs:CollapseStructure/LoopBody/TraceDAG), notfrom a region identifier. Unlike
kuna_loweredswitch.rs— which manufactures an S2BRANCHIND+JumpTableartifact upstream and lets the existing structurer+printeremit the
switch— there is no single artifact to inject here; the loop-recoverylogic lives inside the structurer. The decider subagent returned
scope: "large".Two candidate implementation paths (pick one to fund)
Path A — extend the collapse structurer's loop detection (in-place)
Teach
blockaction.rsLoopBody/CollapseStructureto recognise the head-in-bodynatural loop and prefer a loop-header collapse over emitting a back-edge goto,
gated by a new
option naturalloophead on|off(default off).the option can be ablated against the 675-datatest corpus like every other feature.
regression risk across the datatest corpus; requires careful guards so it only fires
on the head-in-body shape. Multi-step: (1) detect the shape on the collapsed graph,
(2) reorder/relabel the loop-edge so the header collapses, (3) verify goto/label
count drops with no datatest churn.
Path B — wire the ported
RegionIdentifierinto emitPromote
s7_regions/kuna_regionid.rs(today analysis-only) into a real structuringpass that produces the region tree the printer consumes, gated by the new option.
head-in-body case is already handled in that port; closest to "do what angr does."
adapter,
getStart()/lastOp()block-graph adapter that is currently SEAM'd off).The largest of the two; effectively a second structurer.
Speed / risk assessment
~O(n²)(the portcarries
2n²+64guard caps). Either path must measure decompile wall-time off vs on(Hard rule 6) and stay within the +5% budget, else ship default-OFF opt-in.
Path B risks correctness drift between two structurers but isolates blast radius
behind the option (default-off, only the gated path uses the region tree).
the smaller bet if the head-in-body shape can be detected cheaply; Path B is the
faithful-to-angr bet if a second structurer is acceptable. Human decision requested.
Proposed option
option naturalloophead on|off(default off),change_kind = structure-recovery,source_decompiler = angr,inspiration = "test_decompiling_phoenix_natural_loop_region_head_in_body; RegionIdentifier (Phoenix); 0x442300".What this PR contains
Analysis + reproduction artifacts + this proposal only. No
kuna_*.rs, no optionregistration, no stage test, no baseline change.