Repository navigation
[AUTOMATED] Print a chain of tests into one no-return call as one if (condfold noreturn) - #1982
Merged
Merged
Conversation
…ld noreturn) [AUTOMATED] work in progress: relax the stale mainloop isComplex verdict for the later tests of a chain into a no-return block, verify at the final position, keep the structuring with fewer gotos, and orient the folded if so the no-return call is its body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…only goto-free structurings [AUTOMATED] A relaxed chain test that prints too wide is analyzed again without the relaxation (its own veto set), not seeded complex, so a late re-structure keeps folding it as main does. A relaxed structuring that prints a goto is replaced by the unrelaxed one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
…; fixture and stage test [AUTOMATED] A relaxed test may print as many statements before its comparison as condstmts allows (that option's reanalysis handles a wider one), the target's call must carry the no-return note, and the fatalchain fixture (gcc -O2/-O0) with tests/stages/kuna-fatalchain.xml. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] condfold row (values off|noreturn|on|wide, default noreturn), spec prose in chapter 08, the round-trip test, the regenerated catalog fixtures and counts, and condfold off pins in two stage tests that isolate guardarm and tailform. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
[AUTOMATED] Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU # Conflicts: # docs/baseline-stages.json
mahaloz
added a commit
that referenced
this pull request
Nov 26, 2026
…timized code (condfold auto) (#1983) In optimized code, a run of calls whose failures all go to one error block, `if ((r = put(b, x)) != 0 || (r = put(b, 2 * x)) != 0) { note(r); return; }`, prints as a ladder of nested `if`s. #1982 fixed this when the error block ends in a call that does not return; this does the same when it is an ordinary block (a return, the target of a `goto out`), in functions that are not compiled without optimization. ``` kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/chainfold_gcc_O2_x86_64 store ``` (the fixture is added here; it is `chainfold.c` built with gcc 11.4 `-O2 -fno-reorder-blocks-and-partition`) Before: ```c v1 = put(a0,a1); if (!v1) { v1 = put(a0,(int)a1 * 2); if (!v1) { sink = *a0; note(0); // tail-call return; } } note(v1); // tail-call ``` After: ```c v1 = put(a0,a1); if ((!v1) && (v1 = put(a0,(int)a1 * 2), !v1)) { sink = *a0; note(0); // tail-call return; } note(v1); // tail-call ``` - `condfold` gets a value `auto`, the new default: everything `noreturn` does, plus, in a function the unoptimized detector does not flag, a chain into any block only the chain enters. `noreturn` keeps its meaning, so the old print is `--option condfold noreturn`. In unoptimized code authors nest these tests often enough that the fold loses there, so it stays off. - The no-return case's guards all apply: the `condstmts` width cap, the comment check, and replacing a structuring that prints a goto. A later print-tree pass can still leave a goto (`taildup` did on one function), so a function whose fold into an ordinary block prints a goto at the end is decompiled again without it, and the copy with fewer gotos wins (the unfolded one on a tie). - On the decbench gcc corpus, against `noreturn` in the same build: 73 more functions at O2 without inlining match the source's control flow exactly (102 gained, 29 lost), positive on both project halves; 14 more at O0 from functions the detector does not flag; no function gains a goto. The losses are sources that really nest the second test, mostly because they use its value afterwards. - Whole-binary analysis time against `noreturn` on sshd, bash and ls: +1.0%, +2.4%, +3.1%. To keep it there, the goto fallback only re-structures when a relaxed test actually folded, and a large function (64 blocks or more) stops relaxing once such a fold has fallen back. Tests: `tests/stages/kuna-chainfold.xml` decompiles the fixture with `condfold noreturn` (the -O2 ladder) and the default (one condition), and checks that the -O0 build keeps its ladder under both. The round-trip test gains a second case that compiles the printed functions beside the source with gcc and clang at -O0 and -O2, with `put` failing at each call in turn, and compares the results, stored values and call order. `gh6904-ppc-e500-concat44.xml`, `structsynth-locals.xml` and the ELFv1 `callmechanisms` CLI test now pin `condfold noreturn`, since they check other features (under `callmechanisms on` the chain now folds as it does by default: the TOC store it keeps after each call does not print). No datatest assertion moves. Model: `anthropic/claude-opus-5-5` 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU
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.
Code that checks a run of calls and stops in one fatal call,
if ((r = put(b, x)) != 0 || (r = put(b, y)) != 0) fatal(r, "first");, prints as a ladder of nestedifs with the continuation innermost and the fatal call after all of them. With this change it prints as oneifover the||chain, the fatal call as its body, and the rest of the function after it.(the fixture is added here; it is
fatalchain.cbuilt with gcc 11.4-O2 -fno-reorder-blocks-and-partition)Before:
After:
BlockBasic::isComplexcounts call, store and branch andruleBlockOrdeclines every later test. For a chain of two-way blocks whose taken edges all reach one block ending in a call with the no-return note, the later tests are now structured as not complex. A test that then prints more statements before its comparison thancondstmtsallows goes through that option's existing reanalysis and keeps its ladder, and a structuring that relaxed and prints a goto is replaced by the one that did not.if (chain) { R } f();(R not falling through) intoif (!chain) f(); R, at any depth. Neither form reaches pastf(), so the tests run in the same order with the same short-circuit.condfold:noreturn, the new default (onandwideinclude it).condfold offprints the ladder.Tests:
tests/stages/kuna-fatalchain.xmldecompiles the -O2 and -O0 fixtures withcondfold off(ladders) and the default (oneifper chain; a test with four calls before it keeps its ladder).kuna-cli/tests/fatalchain_round_trip.rscompiles the printed functions beside the source with gcc and clang at -O0 and -O2 and runs them withputfailing at each call in turn, comparing the result, the stored state, the valuefatalreceives and the order of theputcalls.ghdec-guardarm.xmlandkuna-tailform-noreturn.xmlnow pincondfold off, since they isolateguardarmandtailform. No datatest assertion moves.Model:
anthropic/claude-opus-5-5🤖 Generated with Claude Code
https://claude.ai/code/session_013BBaWVABMswm9QwjnywGWU