Repository: rust
Issue: LTO coordinator panics by unwrapping Option::None
Labels: I-ICE,T-compiler,C-bug

### Code

Discovered this error while fuzzing for https://github.com/rust-lang/rust/issues/81280

I used `cargo watch -- cargo build --profile incremental` for building [this binary crate](https://github.com/HULKs/hulk/tree/6b34bb12bd902dfc737c30d428f883a18e1dbebd/tools/twix), while `touch`-ing random files at random intervals to trigger rebuilds.

Fish script:
```fish
while true
    touch (find src | shuf -n1)
    sleep 0.(random 1 999)
end
```

### Meta

`rustc --version --verbose`:
```
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
```

### Error output

```
thread 'coordinator' panicked at compiler/rustc_codegen_llvm/src/back/lto.rs:836:36:
called `Option::unwrap()` on a `None` value
```

<!--
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>

```
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f5bbd68a3e5 - std::backtrace_rs::backtrace::libunwind::trace::h649ab3318d3445c5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f5bbd68a3e5 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4bb60c3387150c3
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5bbd68a3e5 - std::sys::backtrace::_print_fmt::hd9186c800e44bd00
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:     0x7f5bbd68a3e5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:     0x7f5bbd6d9eeb - core::fmt::rt::Argument::fmt::h351a7824f737a6a0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:     0x7f5bbd6d9eeb - core::fmt::write::h4b5a1270214bc4a7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f5bbd67ef6f - std::io::Write::write_fmt::hd04af345a50c312d
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:     0x7f5bbd68cbd1 - std::sys::backtrace::BacktraceLock::print::h68d41b51481bce5c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:     0x7f5bbd68cbd1 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:     0x7f5bbd68c8ac - std::panicking::default_hook::h3cacb9c27561ad33
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:     0x7f5bb9c93420 - std[1f2242ed6435445e]::panicking::update_hook::<alloc[7b1462a1eb55c293]::boxed::Box<rustc_driver_impl[8683aa37472b7dde]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f5bbd68d59f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hce7569f4ca5d1b64
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2084:9
  12:     0x7f5bbd68d59f - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:808:13
  13:     0x7f5bbd68d193 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:667:13
  14:     0x7f5bbd68a8a9 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:168:18
  15:     0x7f5bbd68ce54 - rust_begin_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
  16:     0x7f5bbd6d64a3 - core::panicking::panic_fmt::h3d8fc78294164da7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
  17:     0x7f5bbd6d652c - core::panicking::panic::hec978767ec2d35ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:148:5
  18:     0x7f5bbd6d6299 - core::option::unwrap_failed::hba6b08832f9ce30b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:2020:5
  19:     0x7f5bbbf72a6b - rustc_codegen_llvm[5ff2375b9bf6d639]::back::lto::thin_lto
  20:     0x7f5bbbf6d00b - <rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend as rustc_codegen_ssa[382a85cbfbe8c2f6]::traits::write::WriteBackendMethods>::run_thin_lto
  21:     0x7f5bbc1113ce - rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::start_executing_work::<rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend>::{closure#5}
  22:     0x7f5bbc10f876 - std[1f2242ed6435445e]::sys::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend as rustc_codegen_ssa[382a85cbfbe8c2f6]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::start_executing_work<rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend>::{closure#5}, core[3cad2706d8bdcdc4]::result::Result<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::CompiledModules, ()>>::{closure#0}, core[3cad2706d8bdcdc4]::result::Result<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::CompiledModules, ()>>
  23:     0x7f5bbc10f6ad - <<std[1f2242ed6435445e]::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend as rustc_codegen_ssa[382a85cbfbe8c2f6]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::start_executing_work<rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend>::{closure#5}, core[3cad2706d8bdcdc4]::result::Result<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::CompiledModules, ()>>::{closure#0}, core[3cad2706d8bdcdc4]::result::Result<rustc_codegen_ssa[382a85cbfbe8c2f6]::back::write::CompiledModules, ()>>::{closure#1} as core[3cad2706d8bdcdc4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  24:     0x7f5bbd6975fb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha1963004222e7822
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  25:     0x7f5bbd6975fb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1086ced1f7c494c2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
  26:     0x7f5bbd6975fb - std::sys::pal::unix::thread::Thread::new::thread_start::ha8af9c992ef0b208
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/pal/unix/thread.rs:108:17
  27:     0x7f5bbd466897 - start_thread
  28:     0x7f5bbd4eda5c - __GI___clone3
  29:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C opt-level=3 -C embed-bitcode=no -C incremental=[REDACTED] -C strip=debuginfo

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
thread 'rustc' panicked at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/compiler/rustc_codegen_ssa/src/back/write.rs:2057:17:
/rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/compiler/rustc_codegen_ssa/src/back/write.rs:2057:17: panic during codegen/LLVM phase
stack backtrace:
   0:     0x7f5bbd68a3e5 - std::backtrace_rs::backtrace::libunwind::trace::h649ab3318d3445c5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f5bbd68a3e5 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4bb60c3387150c3
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5bbd68a3e5 - std::sys::backtrace::_print_fmt::hd9186c800e44bd00
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:     0x7f5bbd68a3e5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:     0x7f5bbd6d9eeb - core::fmt::rt::Argument::fmt::h351a7824f737a6a0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:     0x7f5bbd6d9eeb - core::fmt::write::h4b5a1270214bc4a7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f5bbd67ef6f - std::io::Write::write_fmt::hd04af345a50c312d
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:     0x7f5bbd68cbd1 - std::sys::backtrace::BacktraceLock::print::h68d41b51481bce5c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:     0x7f5bbd68cbd1 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:     0x7f5bbd68c8ac - std::panicking::default_hook::h3cacb9c27561ad33
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:     0x7f5bb9c93420 - std[1f2242ed6435445e]::panicking::update_hook::<alloc[7b1462a1eb55c293]::boxed::Box<rustc_driver_impl[8683aa37472b7dde]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f5bbd68d59f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hce7569f4ca5d1b64
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2084:9
  12:     0x7f5bbd68d59f - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:808:13
  13:     0x7f5bba236ae2 - std[1f2242ed6435445e]::panicking::begin_panic::<alloc[7b1462a1eb55c293]::string::String>::{closure#0}
  14:     0x7f5bba22f626 - std[1f2242ed6435445e]::sys::backtrace::__rust_end_short_backtrace::<std[1f2242ed6435445e]::panicking::begin_panic<alloc[7b1462a1eb55c293]::string::String>::{closure#0}, !>
  15:     0x7f5bba221201 - std[1f2242ed6435445e]::panicking::begin_panic::<alloc[7b1462a1eb55c293]::string::String>
  16:     0x7f5bba2b98cd - rustc_middle[ba2289ab3ae064d4]::util::bug::opt_span_bug_fmt::<rustc_span[28a649581f99a5bd]::span_encoding::Span>::{closure#0}
  17:     0x7f5bba29f49a - rustc_middle[ba2289ab3ae064d4]::ty::context::tls::with_opt::<rustc_middle[ba2289ab3ae064d4]::util::bug::opt_span_bug_fmt<rustc_span[28a649581f99a5bd]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  18:     0x7f5bba29f31b - rustc_middle[ba2289ab3ae064d4]::ty::context::tls::with_context_opt::<rustc_middle[ba2289ab3ae064d4]::ty::context::tls::with_opt<rustc_middle[ba2289ab3ae064d4]::util::bug::opt_span_bug_fmt<rustc_span[28a649581f99a5bd]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  19:     0x7f5bb7c3a600 - rustc_middle[ba2289ab3ae064d4]::util::bug::bug_fmt
  20:     0x7f5bbc1081d0 - <rustc_codegen_llvm[5ff2375b9bf6d639]::LlvmCodegenBackend as rustc_codegen_ssa[382a85cbfbe8c2f6]::traits::backend::CodegenBackend>::join_codegen
  21:     0x7f5bbc1030c3 - <rustc_interface[53a414ae04dc6ffb]::queries::Linker>::link
  22:     0x7f5bbbf2d55c - rustc_interface[53a414ae04dc6ffb]::interface::run_compiler::<core[3cad2706d8bdcdc4]::result::Result<(), rustc_span[28a649581f99a5bd]::ErrorGuaranteed>, rustc_driver_impl[8683aa37472b7dde]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7f5bbbe7395b - std[1f2242ed6435445e]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[53a414ae04dc6ffb]::util::run_in_thread_with_globals<rustc_interface[53a414ae04dc6ffb]::interface::run_compiler<core[3cad2706d8bdcdc4]::result::Result<(), rustc_span[28a649581f99a5bd]::ErrorGuaranteed>, rustc_driver_impl[8683aa37472b7dde]::run_compiler::{closure#0}>::{closure#1}, core[3cad2706d8bdcdc4]::result::Result<(), rustc_span[28a649581f99a5bd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3cad2706d8bdcd
```

</p>
</details>