mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 15:16:08 -06:00
Fixes #6902 ## What was happening Reproducing the Clean example from the issue, the CFG pane didn't just draw a wrong graph — it actually crashed the whole compile with: TypeError: Cannot set properties of undefined (setting 'nameId') at BaseCFGParser.extractAltJmpTargetName ## Root cause `extractAltJmpTargetName` assumes a conditional jump is never the last instruction of a function — it always tries to write a generated name onto "the next basic block" (`arrBB[bbIdx + 1]`). When a function's last basic block ends in a conditional jump with no fallthrough block after it, `arrBB[bbIdx + 1]` doesn't exist, and the code crashes trying to set a property on `undefined`. I couldn't get a working Clean compiler locally, so I wasn't able to confirm Clean's exact label format, but I could reliably reproduce the exact same crash/stack trace with 3 lines of synthetic assembly (see the added test case) — any input that leaves a conditional jump as the final instruction of a function hits this. ## Fix Guard the write so it only happens when a next block actually exists. The frontend layout code (`graph-layout-core.ts`) already tolerates edges that point at a node ID that doesn't exist (there's an existing comment there about exactly this: "Backend can return dest: null"), so this degrades gracefully instead of crashing. ## Note This fixes the crash. The original report also mentioned Clean's *labels* getting misidentified as separate functions in the graph itself — that's a related but separate issue (in `isFunctionEnd()`'s assumption that local labels are dot-prefixed, GNU-`as`-style). I didn't have a way to verify Clean's actual label format to fix that part with confidence, so I've left it for a possible follow-up. ## Testing Added `test/cfg-cases/cfg-base.cond-jmp-last-instruction.json` and a new `describe('base', ...)` block in `test/cfg-tests.ts`. Confirmed it fails with the original crash on unpatched code and passes with the fix.