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

    <tr>
        <th>Summary</th>
        <td>
            [clangd] "Assertion `LocalDeclID < LocalNumDecls' failed." when using clangd with `--experimental-modules-support`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I'm trying out the new experimental module support of clangd with a ~25 KLOC large code base. On some files (~5 out of ~170), clangd crashes with an assertion failure in `clang/lib/Serialization/ASTReader.cpp`: "Assertion `LocalDeclID < LocalNumDecls' failed." With assertions disabled there are instead "random" crashes in the parser (I guess because of UB?).

The git hash is ff993f9a4c23cfaae54f2a2708bed23954b8d9c0 .

I haven't found a minimal, standalone reproducer yet, sadly. I have attached the output of `clangd --compile-commands-dir=. --experimental-modules-support --check=src/ldgr/core.cppm` and the backtrace in gdb.

Any ideas how to further debug this? I haven't found any pattern in the ~5 files that crash, although the crashes are reproducible.

[clangd-output.txt](https://github.com/user-attachments/files/19126557/clangd-output.txt)
[gdb-log.txt](https://github.com/user-attachments/files/19126556/gdb-log.txt)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyslMuO47YShp-G3hRk0NTNWmjhGUNA4wzOAJkJsi6RJYk9FCmQVHc7i372gJKdNJBgNsmKkMi6fX_hxxD0aIlaVn5i5fWAa5ycb5-1frs9H3qnbu0TE_UM0d-0HcGtEeJEYOkV6G0hr2eyEQ3MTq2GIKzL4nwEN4A0aEcFrzpOgPAuSvjfl6-fwaAfCaRTBD0GOsJXC8HNBIM2FICJ83u5lXEDvJ9qzkTDxOdHNukxTBTuWS1gCOSjdhYG1Gb1BNoCq_j2nInO6J6J7ht5jUb_juklE93l2_dfCBX5o1wWVnGWX4AJcfkzGav4FyfRXEmapy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