Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Failed to encode discriminator in DILocation #132900

Closed
Millione opened this issue Nov 11, 2024 · 8 comments · Fixed by #133194
Closed

ICE: Failed to encode discriminator in DILocation #132900

Millione opened this issue Nov 11, 2024 · 8 comments · Fixed by #133194
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Millione
Copy link

Millione commented Nov 11, 2024

Code

Can not reproduce it with minimized code for now, and the whole repository is private.

Update: Thanks for @buaazp providing a minimal reproduce codebase https://github.com/buaazp/rust-bug.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (143ce0920 2024-11-10)
binary: rustc
commit-hash: 143ce0920a2307b19831160a01f06f107610f1b2
commit-date: 2024-11-10
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Error output

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs:168:22:
Failed to encode discriminator in DILocation

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: please make sure that you have updated to the latest nightly

note: compiler flags: --crate-type lib -C opt-level=3 -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 -Z threads=8 -C target-cpu=native

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

query stack during panic:
end of query stack
error: could not compile `***` (lib)
Backtrace

stack backtrace:
   0:     0x7f9ccd2b0ada - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2f1c5db75869eef0
   1:     0x7f9ccda47126 - core::fmt::write::h43b2df425572a034
   2:     0x7f9ccea4c991 - std::io::Write::write_fmt::h77e35077f9fad7c4
   3:     0x7f9ccd2b0932 - std::sys::backtrace::BacktraceLock::print::h0c19526194593f74
   4:     0x7f9ccd2b2e36 - std::panicking::default_hook::{{closure}}::h865cf38b8deeb5bb
   5:     0x7f9ccd2b2c80 - std::panicking::default_hook::h69c14be83dcb49b3
   6:     0x7f9ccc329849 - std[3c0d0ff6ea8c1a1f]::panicking::update_hook::<alloc[f87dac715322685f]::boxed::Box<rustc_driver_impl[83ab483273712ee2]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7f9ccd2b3548 - std::panicking::rust_panic_with_hook::h583f6aaba9a390bd
   8:     0x7f9ccd2b331a - std::panicking::begin_panic_handler::{{closure}}::h02a363aabf2442f1
   9:     0x7f9ccd2b0f89 - std::sys::backtrace::__rust_end_short_backtrace::h84ecae8072aa78ac
  10:     0x7f9ccd2b2fdc - rust_begin_unwind
  11:     0x7f9cc9d15640 - core::panicking::panic_fmt::h514b8325f5f2609d
  12:     0x7f9cca2aa44b - core::option::expect_failed::h3eb9ea9a180694f7
  13:     0x7f9cca085139 - rustc_codegen_llvm[163141f4e00b7ecb]::debuginfo::create_scope_map::make_mir_scope
  14:     0x7f9cce998306 - rustc_codegen_ssa[b2545927768e4a09]::mir::codegen_mir::<rustc_codegen_llvm[163141f4e00b7ecb]::builder::Builder>
  15:     0x7f9cce995b85 - rustc_codegen_llvm[163141f4e00b7ecb]::base::compile_codegen_unit::module_codegen
  16:     0x7f9cce96c4d1 - <rustc_codegen_llvm[163141f4e00b7ecb]::LlvmCodegenBackend as rustc_codegen_ssa[b2545927768e4a09]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  17:     0x7f9ccc1619ca - rayon[c458d3a2004a12bf]::iter::plumbing::bridge_producer_consumer::helper::<rayon[c458d3a2004a12bf]::vec::DrainProducer<(usize, &rustc_codegen_ssa[b2545927768e4a09]::assert_module_sources::CguReuse)>, rayon[c458d3a2004a12bf]::iter::filter_map::FilterMapConsumer<rayon[c458d3a2004a12bf]::iter::extend::ListVecConsumer, rustc_data_structures[dd92c1caaaf932d5]::sync::parallel::enabled::par_map<(usize, &rustc_codegen_ssa[b2545927768e4a09]::assert_module_sources::CguReuse), alloc[f87dac715322685f]::vec::Vec<(usize, &rustc_codegen_ssa[b2545927768e4a09]::assert_module_sources::CguReuse)>, (usize, (rustc_codegen_ssa[b2545927768e4a09]::ModuleCodegen<rustc_codegen_llvm[163141f4e00b7ecb]::ModuleLlvm>, u64)), std[3c0d0ff6ea8c1a1f]::collections::hash::map::HashMap<usize, (rustc_codegen_ssa[b2545927768e4a09]::ModuleCodegen<rustc_codegen_llvm[163141f4e00b7ecb]::ModuleLlvm>, u64), rustc_hash[8e68038b4b9c783c]::FxBuildHasher>, rustc_codegen_ssa[b2545927768e4a09]::base::codegen_crate<rustc_codegen_llvm[163141f4e00b7ecb]::LlvmCodegenBackend>::{closure#6}::{closure#1}>::{closure#0}::{closure#0}>>
  18:     0x7f9cce96a340 - <rustc_codegen_llvm[163141f4e00b7ecb]::LlvmCodegenBackend as rustc_codegen_ssa[b2545927768e4a09]::traits::backend::CodegenBackend>::codegen_crate
  19:     0x7f9ccec310e7 - <rustc_interface[fd324feaaa946fb2]::queries::Linker>::codegen_and_build_linker
  20:     0x7f9cce907f6a - rustc_interface[fd324feaaa946fb2]::interface::run_compiler::<core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>, rustc_driver_impl[83ab483273712ee2]::run_compiler::{closure#0}>::{closure#1}
  21:     0x7f9ccc33497d - <rayon_core[b1c0e86ef95b0e5b]::job::StackJob<rayon_core[b1c0e86ef95b0e5b]::latch::LatchRef<rayon_core[b1c0e86ef95b0e5b]::latch::LockLatch>, <rayon_core[b1c0e86ef95b0e5b]::registry::Registry>::in_worker_cold<<rayon_core[b1c0e86ef95b0e5b]::thread_pool::ThreadPool>::install<rustc_interface[fd324feaaa946fb2]::util::run_in_thread_pool_with_globals<rustc_interface[fd324feaaa946fb2]::interface::run_compiler<core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>, rustc_driver_impl[83ab483273712ee2]::run_compiler::{closure#0}>::{closure#1}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}::{closure#0}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#0}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>> as rayon_core[b1c0e86ef95b0e5b]::job::Job>::execute
  22:     0x7f9ccbe081ae - <rayon_core[b1c0e86ef95b0e5b]::registry::WorkerThread>::wait_until_cold
  23:     0x7f9ccbe05c17 - <rayon_core[b1c0e86ef95b0e5b]::registry::ThreadBuilder>::run
  24:     0x7f9ccc32c4e6 - <<crossbeam_utils[fa9bdfd2dd3a184c]::thread::ScopedThreadBuilder>::spawn<<rayon_core[b1c0e86ef95b0e5b]::ThreadPoolBuilder>::build_scoped<rustc_interface[fd324feaaa946fb2]::util::run_in_thread_pool_with_globals<rustc_interface[fd324feaaa946fb2]::interface::run_compiler<core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>, rustc_driver_impl[83ab483273712ee2]::run_compiler::{closure#0}>::{closure#1}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[fd324feaaa946fb2]::util::run_in_thread_pool_with_globals<rustc_interface[fd324feaaa946fb2]::interface::run_compiler<core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>, rustc_driver_impl[83ab483273712ee2]::run_compiler::{closure#0}>::{closure#1}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[3a5812f1f6fa4837]::result::Result<(), rustc_span[8e1c5aac56eafb7b]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[3a5812f1f6fa4837]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f9ccc32099e - std[3c0d0ff6ea8c1a1f]::sys::backtrace::__rust_begin_short_backtrace::<alloc[f87dac715322685f]::boxed::Box<dyn core[3a5812f1f6fa4837]::ops::function::FnOnce<(), Output = ()> + core[3a5812f1f6fa4837]::marker::Send>, ()>
  26:     0x7f9ccc32c012 - <<std[3c0d0ff6ea8c1a1f]::thread::Builder>::spawn_unchecked_<alloc[f87dac715322685f]::boxed::Box<dyn core[3a5812f1f6fa4837]::ops::function::FnOnce<(), Output = ()> + core[3a5812f1f6fa4837]::marker::Send>, ()>::{closure#1} as core[3a5812f1f6fa4837]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7f9cce973839 - std::sys::pal::unix::thread::Thread::new::thread_start::h664ba273de986494
  28:     0x7f9cc8c10fa3 - start_thread
                               at /build/reproducible-path/glibc-2.28/nptl/pthread_create.c:486:8
  29:     0x7f9cc8b4206f - __GI___clone
                               at /build/reproducible-path/glibc-2.28/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  30:                0x0 - <unknown>

rustc-ice-2024-11-11T12_30_37-1345317.txt

@Millione Millione added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 11, 2024
@Millione
Copy link
Author

Corresponded PR: #132613

@jieyouxu jieyouxu added the S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. label Nov 11, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 11, 2024

cc @khuey but we really need a reproduction for this otherwise there's not much we can do here, it'll be guess work at best which is not very actionable.

@jieyouxu jieyouxu added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 11, 2024
@khuey
Copy link
Contributor

khuey commented Nov 11, 2024

We could fix the ICE pretty easily (by dropping debug information when we hit this case). But it would be good to verify that this really is a case with a proc-macro that ends up with the same function inlined into it a huge number of times first.

@workingjubilee
Copy link
Member

@Millione If you get some time to work on the minimization here, it will significantly improve the odds that we can fix this without losing debuginfo unnecessarily, and in general interesting reproduction cases make rustc's test suite more resilient.

@buaazp
Copy link

buaazp commented Nov 18, 2024

Hi everyone, I have constructed a minimal code base to reproduce this bug. This bug must be triggered by a function call with more than 4096 lines of code and containing macro expansion in the parameters. Because the code file is long, I submitted it to this repository: https://github.com/buaazp/rust-bug. The repository contains the replica code and generation script for comparison testing. Once the function is less than or equal to 4096 lines, rustc will not panic. You can give it a try and contact me anytime if you have any questions.

@khuey
Copy link
Contributor

khuey commented Nov 18, 2024

Thanks, I'll take a look. That this happens without a proc-macro is unexpected.

@khuey
Copy link
Contributor

khuey commented Nov 18, 2024

Ok, it's unexpected to me because I misunderstood how macro Spans work. I'll write a PR.

@khuey
Copy link
Contributor

khuey commented Nov 19, 2024

@rustbot claim

@bors bors closed this as completed in bcfea1f Nov 20, 2024
khuey added a commit to khuey/rust that referenced this issue Jan 17, 2025
… with dummy spans instead of not emitting locations at all when the correct location discriminator value exceeds LLVM's capacity.
khuey added a commit to khuey/rust that referenced this issue Jan 18, 2025
… with dummy spans instead of not emitting locations at all when the correct location discriminator value exceeds LLVM's capacity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants