<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVF1v4zYQ_DXyCxFDlj8SP_jB5zRAgCtQ5Nw79HFFUhLPFGnww6776ztLx3fNoUiLFhBEW-TuzswOt_XqstkPJgo8JI7Bt1aPIg2URMyhI6mVME48f_ntVxG01C7Zy7SqH6t6e30_V839iECd0oVDtDAJn6JQpuuMzDaJ5DnxyR94j7OlQQvpx6OxOvDWUYeq2YlonNSiWtU7iumn34-hmm_x9DrtvDvpEI13T9nJhBWnGLJ39iIkWXuFSZyjt1ocLZBzzs4HIKHe-ZiMjFOx995G0WYDYN6JnSXXA6G3CBTkVAEHphnlTlpsP-3FyUSTkEeSEx1q4QMwjMyLue7E4M8a-N7qIgZCfAHYag1sUJZDggZjlWURAwgAFcijz0GyKgoKNA_OJ9YUJ6WOUauqWXMhxlcyIkJ69_VVDHE2aSjAuzEJa9pA4cJphpSOkVVsnvD0OJXbKZTHH5zEwesPZJ-KbUokB9aRnTAaZ0ay4mX7uahTShsXU8ilZHxD5Q3zL2yekQ46ihGMB-MO_C4Wi37UZ96XwaAfKICPxW3_vu2wWg4AgG7g71ayQp-OWj5qaYst3LVchFspGM_CnQcjB9EGTQcEooXRhwT7dKXBzO3jx88_i5f9_hnxJ4SRS3DLMywdkTuJM-x0D3db7w_FKkn0FFrqtVCUqBiN2QEeRe84tBggBQNN2W-Kw3IbyVXNB8Jyd9VzxKXSVwBoRzEkQ25zKn31WFtdSr46KAWSB4C-sLa9UP7s3jTghdvC9-orgENJUS0_BDqVbk0ThWn_R7V8fN8e1p5uy90tE7yCGxux3j808_kSlnz6MS-c9Fco-4Hcocu2yAPEwijIw_SsTmyPg_NnYTqoxbeLlBKj5xniEDASt_wHap0OGmOiwL5uNNvreCqysCBt7pn1O-wwaGxW-o6teHfx-S5H_c7nGHOhvV7Ovtf8xSc0zsBMmHs08sFoRmMpiBLwDxD-XuBvpRaL-ex-ojZztZ6vaUIZRgibgxn7MMnBbv575uW8Xiwmw6bTUi3ncraYrWippJzJ1ZJUu2gfaN12Sk4stdrGDcxTNY3T51daTQPzTP4_ArNp6qapZ_Vqtpov68W0bfRiXdPDA8m6Uc2iWtR6JGOnnGfqQz8Jm5IS_Y3YtCbiin7bpBhN77QugIEwmWT15jZTeFy-zhLR3camwsS4TSUMdAws6UPIxzQpWDcF6J-wp2oU>53044</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            CastExpr conversion function decl is sometimes corrupt
        </td>
    </tr>

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

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

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

<pre>
    This is a problem that surfaced in IWYU recently.

I'm pretty sure it's difficult to provoke it in the compiler proper, since `CastExpr::getConversionFunction` is only called in a single place, for diagnostics. Tools built on Clang tooling and the recursive AST visitor can fall victim to it, however.

I have only been able to reproduce it on plain source code (not preprocessed), and only in conjunction with the fmt library (https://github.com/fmtlib/fmt). Attached is a minimal RAV tool and instructions to reproduce.

What makes me think this is somewhat critical is that `CastExpr::getConversionFunction` returns an `AccessSpecDecl` in this scenario, which breaks all sorts of AST and LLVM RTTI invariants. I suspect we're looking at garbage data for some reason. I have tried building ubsan+asan-instrumented LLVM/Clang, but without being able to track anything down.

Repro project: [ravrepro.tar.gz](https://github.com/llvm/llvm-project/files/7823359/ravrepro.tar.gz).

Thankful for any ideas, let me know if I can add more information.

References:
* IWYU tracking bug: https://github.com/include-what-you-use/include-what-you-use/issues/951
* Potentially same/similar issue: https://github.com/llvm/llvm-project/issues/44317
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE2P2zYQ_TXyhbAh0_au9-CD4-0CC6RAsXET9DiiKIkxRRr8sOv--r6h12k3KDZBAUGUSM7MmzdvpvHtZbMfTBR4SByDb6weRRooiZhDR0q3wjjx_OWP30XQSrtkL7Oqf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