Repository navigation
[AUTOMATED] Print a search tree of jump tables as one switch (option switchmerge) - #1863
Merged
Merged
Conversation
…old to its last copy The extent fold that names a function's jump tables walked each instruction's p-code linearly. AArch64 csel/csinc lift to a conditional branch over one copy, so the fold took the last copy as the register's value: a dispatch whose index a csel picks from constants read as a load from one address, and its table was never named. The byte-masked last table of the function before it then had no table to end at and kept 230 phantom rows. A Swift enum-to-string switch on Perplexity iOS (sub_1028ab1c8) printed its case bodies' mov/movk string-literal chains as `v1 & 0xffff0000ffffffff | 0x676100000000` joins. Both folds (decompiler and discovery Listing) now treat what an instruction writes after a branch inside it as unknown. This is part of option switchextent (default on). The stage test is kuna-switchnextcsel-a64.
…itch A sparse source switch compiles to several range-checked jump tables on one selector: a failed range check goes to the next table and the holes go to the default code. kuna printed each table as its own switch nested in the previous one's default arm, and every hole as a case label of an arm that only jumps to the code default runs. New option switchmerge (P8, default on, C output only) plans each switch's printed arms on the final structured tree: a default arm that starts with a switch on the same selector takes that switch's arms, and an arm that only jumps to the default code prints no labels. The goto census places break and labels for the printed switch. 0/675 datatest assertions move; with the option off the output is byte-identical to before. cmark-gfm cmark_utf8proc_case_fold (arm64): 2161 -> 1837 case labels, 17 -> 12 switches; GED vs source 2726 -> 1744. [AUTOMATED]
…(objcsdk)
A for-in loop sends countByEnumeratingWithState:objects:count: with the
address of a stack NSFastEnumerationState. The header reader spelled the
NSFastEnumerationState * parameter as a class pointer and could not spell
the (id [_Nonnull]) buffer or NSDictionary's generic (K []) form, so the
selector had no prototype, and the encoding decoder made every ^{...}
pointer a void *. The state printed as eight loose locals and the loop
read *(objc_object **)(v8 + v7 * 8) for state.itemsPtr[i].
The reader now lays out a pointer to a typedef'd struct with its member
names (^{NSFastEnumerationState="state"Q"itemsPtr"^@...}), spells an array
parameter as a pointer, a scalar pointer with its pointee and a generic
parameter as id; the decoder turns a named struct layout behind a pointer
into a pointer to that struct. The typelocked parameter then types the
stack object (gatherOpen), so the state is one local.
Perplexity 26.46: 3/3 for-in loops of a 390-function sample and 14/14 of
AppAuthCore print one NSFastEnumerationState and state.itemsPtr[i].
…ort's address A Mach-O __got slot of a data import (a Swift witness table, type metadata or conformance descriptor, an Objective-C class object) holds the import's address. Code that passes that address on, to swift_getWitnessTable or as a message receiver, printed the slot as dat_<slot>. With importdata on, a read of the value the loader put in a slot machodataslots marks as data now renders &<import>; function-import slots and values the function stored are unchanged. [AUTOMATED]
A Swift switch over a multi-payload enum indexes its jump table with the case swift_getEnumCaseMultiPayload returns, with no range check. When the table is its function's last, or the extent scan dropped the next table, switchextent had no bound and the dispatch stayed a computed call. The swiftmetadata pass now records each local enum's case count (payload cases plus empty cases, from the enum descriptor) by its metadata accessor. The extent scan follows an accessor's result in a preserved register into swift_getEnumCaseMultiPayload and the returned case into a table, and the re-bound uses that count. The scan's register set also drops its oldest value when full instead of refusing new ones, so a run of constants early in a function no longer hides later tables. [AUTOMATED]
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…an in-instruction branch as unknown Chapter 1 describes the discovery Listing's switchextent fold, which this change also touches; say there that a csel/csinc result is unknown to it. Rewrap the chapter 2 line the change left at 130 columns. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…ount Chapter 1's swiftmetadata section lists what the pass reads from a nominal type descriptor; an enum's payload and empty case counts are now among them, handed to the engine by the enum's metadata accessor for switchextent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
A data-import slot's value read by a mask, shift, multiply or division printed `&OBJC_CLASS_$_NSObject >> 0x20` and `&Swift.Int.type_metadata | 1`, which C rejects. Such a read, and a read narrower than the slot, keep `dat_<slot>` as before; an addition still reads `&<import> + 8`. The check returns early when the image marked no data-import slot. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…its printed code The plan drops or moves an arm only when the arm printed before it cannot run into it, and it judged that from the case's structured out-edges. Two kinds of arm run into the next arm with no such edge: one whose trailing jump goes to the arm after it in the switch's own order, which gotonext prints as nothing, and one whose tail the cross-jump reverter duplicated (the duplicated leaf carries no edges). Dropping the hole arm after either sent the arm's values into a different case. falls_through now asks whether the arm's printed code can run past its end: only a leaf whose basic block has no successor and a BlockGoto whose jump prints cannot. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
A struct decoded from an encoding padded every layout to a pointer and
placed a nested struct's members with no trailing padding. Now that a
pointer to a struct types the stack object a caller passes, a 12-byte
`{Tri2=iii}`, a 4-byte `{Pair16=ss}` or a 3-byte `{Three=ccc}` claimed
eight bytes too many and swallowed the neighbouring spill into a char array
(`*(objc_object **)&v2[0xc] = a0`), and `{Outer={Inner=ic}ci}` put `c` at 5,
not 8. The size is now padded to the widest member's alignment and a nested
struct is aligned and padded as a unit, so those stack objects read
`v2.x + v2.z`, `v2.a + v2.b` and `v2.c1 + v2.c3`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
… not on the fold's 16-value cap pick indexed its table with `ldrb w11, [x9, x8]`. SLEIGH lifts that index through an INT_LEFT by 0, which the fold never folds, so a constant index never made pick's load address constant there. What hid pick's table was the fold's 16-value cap: the csel/csinc chain's copies filled it, and the dispatch's last values were refused. With the join, fewer values are tracked, so the test passed for that reason, and Noelo-Lab#1877's change to drop the oldest value passes it too, without this change. pick now adds the index to the table's address (`add x9, x9, x8; ldrb w11, [x9]`), so a constant index really makes the load one from a constant address. The stage test now fails on main and with Noelo-Lab#1877 alone, and passes with the join. Fixture rebuilt with LLVM 21.1.8, README row, stage bytes and comment updated; assertions unchanged. The chapter 2 sentence now names that shape. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
The decoder reads a bitfield code `b<n>` as a 4-byte uint, so a layout
such as `^{Packed=b8b4b20[8S]}` gave each bitfield its own word: 36 bytes
for a 20-byte struct, with the array at the wrong offset. The encoding does
not say how the bits pack, so such a struct is not laid out; the pointer
stays `void *`, as before this change.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Contributor
|
[AUTOMATED] Pushed three commits on top of this branch:
I found the first issue by recompiling decompiled switches and running them against their source, on gcc/clang -O2/-O3 builds for x86-64, AArch64 and ARM. It shows up most easily together with #1872's hole drops: on clang -O2 AArch64, |
…nested An inner switch that is followed by more code in the default arm merges only when no arm leaves it, since its unlisted values must reach that code. The check covered fall-through exits and breaks inside arms but not a bare `case k: break;` arm (a goto case to the switch's exit), which in the merged switch would leave the outer switch and skip the code. Such a switch now stays nested. 0 of 8,588 corpus functions change. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
mahaloz
added a commit
to coleleavitt/kuna
that referenced
this pull request
Nov 22, 2026
… origin/main Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
mahaloz
added a commit
to coleleavitt/kuna
that referenced
this pull request
Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
mahaloz
pushed a commit
that referenced
this pull request
Nov 22, 2026
…ad guarded tables past jumptablemax (#1872) Extends switchmerge (stacked on #1863). An arm that is only a goto or a break now prints no labels when the default code reaches its target for each of its values before it prints a statement. Every test and switch on the selector is decided with the value, and the walk stops at a back edge. An `if (v == c) S` with no else at the head of a default arm prints as `case c: S`. An `if (v relop K)` whose two branches are switches on the selector prints as one switch when every value takes its own branch and the two defaults do the same. The planner reads each arm's labels in one pass over the table. jumptablemax stays 1024, but a table that a guard bounds to at most 65536 entries is read to that bound. It is refused when it reaches more than jumptablemax distinct destinations, or when it admits more than four values per table slot it reads. For example, gcc's `if (x <= 0x28ff) goto tbl[x >> 8]` stays a computed call. New stage tests kuna-switchmerge-values, kuna-switchmerge-split and kuna-jumptableslots. 0/675 datatest assertions move. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
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.
[AUTOMATED] A sparse
switchthat the compiler lowers to two range-checked jump tables on one value prints as two nested switches, and the holes of a table print ascaselabels of an arm that only reaches thedefaultcode. A reader sees two switches and agotowhere the source has one switch.With this change it prints one
switch(a0)with the twelve value labels and a singledefault: return a0 + 1U ^ 0x80;.switchmerge(P8, default on, C output only,p8_structure/kuna_switchmerge.rs) plans the arms each switch prints, on the final structured tree, and changes no code. Adefault:arm that starts with a switch on the same variable takes that switch's arms, when the inner switch prints nothing before itsswitch, has no label, repeats no value, and leaves the way the arm leaves. An inner switch followed by more code must have nodefault:and no arm that leaves it; that code stays thedefault:arm.gototo the codedefault:runs prints no labels. Ifdefault:is thatgoto, the arm holding the code printsdefault:.default:. The goto census placesbreak;and labels for the printed switch.Tests: new stage test
kuna-switchmerge.xml(both shapes, plus anoffrun that keeps the nested form; it fails without the change). 0/675 datatest assertions move. On cmark-gfm'scmark_utf8proc_case_fold(arm64) the labels go from 2161 to 1837 and the switches from 17 to 12, with the same wall time.Model:
anthropic/claude-opus-5-5:high