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

    <tr>
        <th>Summary</th>
        <td>
            IR Outliner: !dbg attachment points at wrong subprogram for function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:crash,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    See the reduced testcase below:

https://godbolt.org/z/EK31YqMfj

```
!dbg attachment points at wrong subprogram for function
!12 = distinct !DISubprogram(name: "outlined_ir_func_0", linkageName: "outlined_ir_func_0", scope: !2, file: !2, type: !3, flags: DIFlagArtificial, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !5, retainedNodes: !4)
void (%struct.hoge.0*)* @outlined_ir_func_0
  br i1 %tmp20, label %bb13, label %bb22.exitStub, !llvm.loop !13
!14 = !DILocation(line: 354, column: 13, scope: !15)
!15 = distinct !DISubprogram(name: "ham.outlined", linkageName: "ham.outlined", scope: null, file: !2, type: !3, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !5, retainedNodes: !4)
!15 = distinct !DISubprogram(name: "ham.outlined", linkageName: "ham.outlined", scope: null, file: !2, type: !3, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !5, retainedNodes: !4)
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVUtvm0AQ_jX4siqCBRz7wMGJEymq81DcVuop2pdh44Wl-0ia_vrOLq6dVK6URj1WAsx8MzuvbxhTzZ_rtRDItQIZwT0THDlhHSNWICqUfkqKRZItk2z3bJ0bbMDwBVyN5lQrl2rTgPQD7vOPRf7129Xm4eWhZJrtrlHEOacNIs4R1naid2jQsncWEPRkdN8g6-lgdGNIhzbaoI3vmZO63x_PMUqKJeLSOgkqBNDycr0_lOBZTzoBaYIGa--U7AW_l-Y-eLrPAEzwGQJ0Sxpx_QZTy_SwM8ojsJHqleye9_oi6hVpQp_Q8vICXhfGyY1kkqjobbg4qNe3QViKjexlKBIlJ2d7-GZwspM_BA_HPBjsYlRBNsKRkO215sLuFGWC52ObHrXkgMwSXFlnPHNpqxuRQkWLYIPBvMyOFBwPI0QNkjmcr1w34Cy2i8BABITSscYXAMap-C7d2nkaNJCIUo9dqrQeggD2e-rKSF1kbKUZibziWcgilFBUZXDAtPJdH4Ax1Mv-h-LnB3_VX4xCS7r0V8l_HIIjRvvwvVfqLfQfYTgUqz7pz0DiK4r_PfP_u3KsK6vVlyt0fnd3cxdUp0ZvRY86zb0SsGR8z8e56wap4lAiQrVxIVI-OrhdnS_W52E3dZAsQdQ3EHIAI-Q0-m0xStd6moI7EMKnsPv5AAQ8COZAlNZ6SBNfINJzBCwpz8dFzAyxLaKEbZ0hTKRj-DVsyy3ivhsOK_n1Xp3wuuDzYk4mTjol6ss7dDMyZnbdeN_anXij6vfXV5V5VU3amp1QMhWCkZyyKRPTiszzaQloOd-Us1k5ifvE1kl1CgMWnRaL2IvdvB1QPY5B5MkGbbWcyBpnGGcFPPLyBGcpJSWmGQTK5zN2kk9h3YmOSJXG1QR_WRNTx5yBSAtKBR-LPSiJtbLphYj5gH_iXatNrU1PHJnE6upY2k9G9T0x">