Files
BFM-decomp/cookbook/C0332.md
T

2.0 KiB
Raw Blame History

§298 — THE SHARED-TAIL POSITION DIAGNOSTIC: A FOLDED TAIL BETWEEN SWITCH ARMS MEANS PER-ARM DUPLICATED STATEMENTS, NOT A HOISTED POST-SWITCH STATEMENT (P31 S61; waves g0e/g0f, func_80181B68, ov_SC06_016, byte-proven 68/68)

Ghidra renders arms 0–3 jumping into ONE lhu/addiu/sh increment tail with arm 4 skipping it — which seduces every drafter into a single state++ AFTER the switch. That spelling emits 70 ins with the tail physically after arm 4. The target's tail sits at .L80181C24–C34, BETWEEN case 3 and case 4 (case 3's arm ends j .L80181C24; .L80181C38 — case 4 — follows immediately; asm/ov_SC06_016/nonmatchings/ov_SC06_016_jr_801816DC/func_80181B68.s). gcc produces that layout only when the SOURCE duplicates the increment per contributing arm — banked src/ov_SC06_016/ov_SC06_016_jr_801816DC.c:3125: the increment statement appears INSIDE case 0's guard, as case 1's LEADING statement (before falling through into case 2), at case 2's end, and inside case 3's guard; case 4 early-returns with no increment. Cross-jump then folds the copies into one block placed after the LAST CONTRIBUTING arm — which is before the non-contributing arm 4.

THE DIAGNOSTIC. A folded tail placed AFTER the final switch arm ⇒ a hoisted post-switch statement in the source. A folded tail anywhere EARLIER ⇒ the statement is duplicated inside each contributing arm, and the fold lands after the last arm that contributes. Composes with §224 (write the duplicate — this is its switch-arm face) and bounds the §162-region merged-tail law (L11268's write-ONCE-at-the-last-arm form is for goto-shared tails; here every contributing arm carries its own copy and jump2 does the folding).

Also byte-confirmed on this card: READ THE JUMP TABLE before reaching for §161a/§162a's empty-case constructions — all 5 entries of jtbl_8019E2C0 are real bodies; neither edge equals the epilogue. The negative control generalizes: the table's own words, not the arm count, decide whether an empty-case construction exists.