mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-05-16 11:22:09 -04:00
A `catchswitch` instruction has the form:
catchswitch within none [label %catch.start] unwind to caller
The LLVM IR parser then extracts the labels out of this expression.
However, the regex is too greedy, and (incorrectly) matches
`%catch.start]`. We update the regex to match what LLVM's lexer does.
The [language reference](https://llvm.org/docs/LangRef.html#identifiers)
states that quoted identifiers can include `\xx` escapes, however as far
as I can tell [that is *not*
true](413cafa462/llvm/lib/AsmParser/LLLexer.cpp (L391-L421)),
so I have elected not to support them.
For the following program (targetting WASM, compiled with
`-fwasm-exceptions`):
```c
void bar(int x);
void foo() {
try {
bar(1);
} catch(int x) {
}
}
```
**Before:**
<img width="1492" height="411" alt="A CFG of the above program. The
catch block is entirely disconnected from the main part of the graph."
src="https://github.com/user-attachments/assets/ad9038cc-f372-4109-bc25-328537bcea88"
/>
**After:**
<img width="1286" height="639" alt="A CFG of the above program. The
catch block is now correctly connected to the rest of the graph."
src="https://github.com/user-attachments/assets/27cce7b3-dd67-4c1c-928c-93f7eaa53fa2"
/>