<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/94314>94314</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Crash in TokenAnnotator::calculateFormattingInformation since llvm 17
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zeyugao
      </td>
    </tr>
</table>

<pre>
    I tried to minimize poc to

```cpp
int midiSystem(audioMain *audiomain, bristolMidiMsg *msg)
{
        palette[
                sound[msg->operator]->index
        ]->param(
                palette[
                        sound[msg->operator]->index
                ]
        );
}
```

Using llvm apt for ubuntu 22.04, for both clang-format-17 and clang-format-18

Crash backtrace:

```
Stack dump:
0.      Program arguments: clang-format-17 1-Z9VNL6ZNYOQFEXIW.c
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM-17.so.1    0x00007fc571a34406 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 54
1  libLLVM-17.so.1    0x00007fc571a325b0 llvm::sys::RunSignalHandlers() + 80
2  libLLVM-17.so.1    0x00007fc571a34a9b
3  libc.so.6          0x00007fc57084c520
4  libclang-cpp.so.17 0x00007fc57b329d03 clang::format::TokenAnnotator::calculateFormattingInformation(clang::format::AnnotatedLine&) const + 1411
5  libclang-cpp.so.17 0x00007fc57b2f1bed
6  libclang-cpp.so.17 0x00007fc57b326366 clang::format::TokenAnalyzer::process(bool) + 1142
7  libclang-cpp.so.17 0x00007fc57b301efd
8  libclang-cpp.so.17 0x00007fc57b2ea10a clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*) + 2298
9  libclang-cpp.so.17 0x00007fc57b2eb571 clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) + 81
10 clang-format-17    0x0000564dff8030d5
11 clang-format-17    0x0000564dff801b54
12 libc.so.6          0x00007fc570833d90
13 libc.so.6          0x00007fc570833e40 __libc_start_main + 128
14 clang-format-17    0x0000564dff7fed25
fish: Job 1, 'clang-format-17 1-Z9VNL6ZNYOQFE…' terminated by signal SIGSEGV (Address boundary error)
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVs1y2zYQfhrosiMNAP4fdJBjK3HHTlIrTZtcNCC5pNCQAAcAnchP3wFJWUpiV85MD-V4LGL54dtfYFdYK2uFuCTRBYkuZ6J3O22WD7jva6FnuS73y2twRmIJTkMrlWzlA0KnC3Ca0EtCV9P_mI5_RdeNEqkctLKUm7112BKeir6U-lZIBYSvhkUrpCL8FeRGWqebW1nKW1v7z62tCc8m6uTioCnrRIPOoTf3ICI0s7pXJYkuWlvPSXClOzTCaUOiS7-UqsRvR_go7IQR3qhTmqfJf5V_UHFc8owEB77k8odgnUbwDytVDU1z34LoHFTaQJ_3yvXA-YKGPk5elmu3g6IRqp5X2rTCzVkCQpU_yNJT6ldG2B3kovjijCiQBKsnUzcuN04UX6Ds2-4RRxcwPO-Nro1oQZi6b1E5S4LVT7aw-efs49ub-PPbT-9-X1_9df3noviRGb5Kt9O9A7tvc92AEi1aIDxFZXuDsNc97MQ9DuGYjyD5gAak8t8MvF99eAPagEUHboeA6l4arbxRcC8MkJje3Hy83W4-3V68u7n-fHW39VtITH0dd9oXp9Mg3ZCfg5sAjcz9vjlLFlYvmHeafqOU0qQqooSJIAxpPFjldwUru7fjy3sjlRsc_DCEmKdHkBFft9o6g77iYp9IqbxiIPwConBUzl6gnEc5fUr5Xa82slaieSNU2aCxvrAn_nRKK3-JcyLLR3QwoAuPi-HxOUHTNCwiPnGHI3oohKLrBvbkFJ0HPCtpMN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