Repository: rust
Issue: CFI: segfault with debuginfo=2 since llvm18
Labels: I-crash,A-LLVM,T-compiler,A-sanitizers,C-bug,PG-exploit-mitigations

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
//@ run-pass
// Ensure that both `Box<dyn Error + Send + Sync>` and `Box<dyn Error>` can be
// obtained from `String`.

use std::error::Error;

fn main() {
    let _err1: Box<dyn Error + Send + Sync> = From::from("test".to_string());
    let _err2: Box<dyn Error> = From::from("test".to_string());
    let _err3: Box<dyn Error + Send + Sync + 'static> = From::from("test");
    let _err4: Box<dyn Error> = From::from("test");
}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.79.0-nightly (0824b300e 2024-03-24)
binary: rustc
commit-hash: 0824b300eb0dae5d9ed59719d3f2732016683d66
commit-date: 2024-03-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
```

### Error output
`rustc file.rs -Copt-level=3 -Zsanitizer=cfi -Ccodegen-units=1 -Clto -Zsanitizer-cfi-generalize-pointers=yes  -Cdebuginfo=2`
```
<output>
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
!dbg attachment points at wrong subprogram for function
!625 = distinct !DISubprogram(name: "main", linkageName: "_ZN5crash4main17h4641422eb1201da3E", scope: !627, file: !626, line: 7, type: !176, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized | DISPFlagMainSubprogram, unit: !75, templateParams: !55, retainedNodes: !628)
ptr @_ZN5crash4main17h4641422eb1201da3E.cfi
  tail call void @free(ptr noundef %23) #54, !dbg !1506, !noalias !1515
!1506 = !DILocation(line: 42, column: 9, scope: !394, inlinedAt: !1507)
!1242 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1179, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!1242 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1179, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!dbg attachment points at wrong subprogram for function
!625 = distinct !DISubprogram(name: "main", linkageName: "_ZN5crash4main17h4641422eb1201da3E", scope: !627, file: !626, line: 7, type: !176, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized | DISPFlagMainSubprogram, unit: !75, templateParams: !55, retainedNodes: !628)
ptr @_ZN5crash4main17h4641422eb1201da3E.cfi
  tail call void @free(ptr noundef %24) #54, !dbg !1505, !noalias !1514
!1505 = !DILocation(line: 42, column: 9, scope: !394, inlinedAt: !1506)
!1241 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1178, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
!1241 = distinct !DISubprogram(name: "drop_in_place<alloc::boxed::{impl#71}::from::StringError>", linkageName: "_ZN4core3ptr205drop_in_place$LT$$LT$alloc..boxed..Box$LT$dyn$u20$core..error..Error$u2b$core..marker..Sync$u2b$core..marker..Send$GT$$u20$as$u20$core..convert..From$LT$alloc..string..String$GT$$GT$..from..StringError$GT$17h2fa14967bc1556e6E", scope: !40, file: !1178, line: 514, type: !402, scopeLine: 514, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !178, templateParams: !55)
error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x2fee106)[0x70f5dcdee106]
/usr/lib/libc.so.6(+0x40770)[0x70f5d9c5a770]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm10DwarfDebug18finalizeModuleInfoEv+0x3ce)[0x70f5d7ef5f8e]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm10DwarfDebug9endModuleEv+0x142)[0x70f5d8494842]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(+0x65b2094)[0x70f5d87b2094]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm13FPPassManager14doFinalizationERNS_6ModuleE+0x4a)[0x70f5d84d1bd2]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-nightly(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x378)[0x70f5d84896b8]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(LLVMRustWriteOutputFile+0x190)[0x70f5dee89290]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5088ea4)[0x70f5dee88ea4]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5086d52)[0x70f5dee86d52]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x5086a42)[0x70f5dee86a42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x508b5dc)[0x70f5dee8b5dc]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-3947d2bdd0a593c6.so(+0x508aba3)[0x70f5dee8aba3]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-eb900a948ffb2e3b.so(rust_metadata_std_aca912f18be40d2b+0xc2a49)[0x70f5e0417a49]
/usr/lib/libc.so.6(+0x8f55a)[0x70f5d9ca955a]
/usr/lib/libc.so.6(+0x10ca3c)[0x70f5d9d26a3c]

note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
[1]    1450268 segmentation fault  rustc /tmp/crash.rs -Copt-level=3 -Zsanitizer=cfi -Ccodegen-units=1 -Clto
```

</p>
</details>