mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-28 11:52:25 +00:00
`MachineBasicBlock::printName` writes the IR basic-block name after `bb.<N>.` unquoted, and the MIR lexer reads it back with `isIdentifierChar` only. If the name contains anything else -- a comma, say -- the name is cut short on the way in and the remainder is treated as syntax, so `llc` cannot parse the MIR that `llc` just wrote: ```console $ llc -mcpu=gfx90a -stop-before=greedy bb-comma-name.ll -o out.mir $ llc -mcpu=gfx90a -x mir -start-before=greedy out.mir -o /dev/null error: out.mir:170:8: expected ':' ``` because the printer emitted ``` bb.1., bb71: ``` This breaks the `-stop-before` / `-start-before` round-trip normally used to reduce a backend bug to a MIR test. Fortran front ends emit such names routinely, which is where I hit it. Fixes #212785. Both sides need the change: * `MachineBasicBlock::printName` now uses `printLLVMNameWithoutPrefix`, which quotes and escapes only when the name is not a plain identifier. Names that already round-tripped are printed exactly as before, so existing MIR output is unchanged. * `maybeLexMachineBasicBlock` accepts a quoted name after `bb.<id>.`, via the same `lexStringConstant` / `unescapeQuotedString` pair that `lexName` already uses for `%ir-block.` and that the printer's `printEscapedString` output matches. The `%ir-block.` reference printed by `PrintBBRef` had the same hole and is fixed the same way. The parse side there was already correct, since `maybeLexIRBlock` goes through `lexName`. ### Testing New test round-trips a module whose block names contain commas and spaces, checking both that the name is quoted on the way out and that the result parses back. Verified the test fails without the patch: the unpatched `llc` emits `bb.1., bb71:` and then rejects it with `expected ':'`. `llvm/test/CodeGen/X86`, `llvm/test/CodeGen/AMDGPU` and `llvm/test/CodeGen/MIR` are clean, 10902 tests, no failures. Those are the targets my build enables; I have not run the other backends. --- Parts of this change were written or audited with Claude Code. I have reviewed all of it and take full responsibility for the contribution. See `llvm/docs/AIToolPolicy.md`. |
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| MILexer.cpp | ||
| MILexer.h | ||
| MIParser.cpp | ||
| MIRParser.cpp | ||