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: virtual-function-elimination #123955

Closed
sgkoishi opened this issue Apr 15, 2024 · 1 comment · Fixed by #130734
Closed

ICE: virtual-function-elimination #123955

sgkoishi opened this issue Apr 15, 2024 · 1 comment · Fixed by #130734
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sgkoishi
Copy link

sgkoishi commented Apr 15, 2024

Code

This happens when compiling the crate https://crates.io/crates/webbrowser x86_64-pc-windows-gnu with virtual-function-elimination.

# Cargo.toml
[dependencies]
webbrowser = "0.8"

[profile.release]
opt-level = 3
strip = true
codegen-units = 1
lto = true
panic = "abort"
incremental = false
# .cargo/config.toml
[build]
rustflags = [
    "-Clto",
    "-Zvirtual-function-elimination",
    "-Zlocation-detail=none"
]

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (0d8b3346a 2024-04-14)
binary: rustc
commit-hash: 0d8b3346a3992ab11ea35ff0fb95a6864b91f797
commit-date: 2024-04-14
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Error output

The backtrace and output here are obtained during cross-compilation (host x86_64-unknown-linux-gnu, target x86_64-pc-windows-gnu, build-std), but the panic also happens when the host is Windows and without build-std.

Backtrace

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/meth.rs:77:37:
expected principal trait object
stack backtrace:
   0:     0x7f23afd74b55 - std::backtrace_rs::backtrace::libunwind::trace::h0041d53520962ed0
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f23afd74b55 - std::backtrace_rs::backtrace::trace_unsynchronized::hf766828f611d7b85
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f23afd74b55 - std::backtrace::Backtrace::create::hd233542d9b78f687
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/backtrace.rs:331:13
   3:     0x7f23afd74aa5 - std::backtrace::Backtrace::force_capture::h664151d7068618d8
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/backtrace.rs:312:9
   4:     0x7f23b2e7a353 - std[28e079ecff9295a0]::panicking::update_hook::<alloc[f6e078dfec71fdaa]::boxed::Box<rustc_driver_impl[e4c67f8d11c8e5e4]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f23afd8fb2c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6b1d9df3b9d447c5
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/alloc/src/boxed.rs:2032:9
   6:     0x7f23afd8fb2c - std::panicking::rust_panic_with_hook::h32d6515ed3e50ef3
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:792:13
   7:     0x7f23afd8f8d6 - std::panicking::begin_panic_handler::{{closure}}::h747e30852c586aa5
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:657:13
   8:     0x7f23afd8d199 - std::sys_common::backtrace::__rust_end_short_backtrace::h29f2ae5b8f4a37f0
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7f23afd8f607 - rust_begin_unwind
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/panicking.rs:645:5
  10:     0x7f23afdd8466 - core::panicking::panic_fmt::h0db242b390fa423a
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:72:14
  11:     0x7f23afdd861c - core::panicking::panic_display::h191733efabdeadb5
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:256:5
  12:     0x7f23afdd820c - core::panicking::panic_str::hf4314323308839b3
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/panicking.rs:231:5
  13:     0x7f23afdd820c - core::option::expect_failed::h8cb1e01b3c84794d
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/core/src/option.rs:1994:5
  14:     0x7f23b2db3789 - rustc_codegen_ssa[e08ec6553c5b268c]::meth::expect_dyn_trait_in_self
  15:     0x7f23b5a08d6b - <rustc_codegen_ssa[e08ec6553c5b268c]::meth::VirtualIndex>::get_fn::<rustc_codegen_llvm[dea4b532a132fe1]::builder::Builder>.cold
  16:     0x7f23b10bc887 - <rustc_codegen_ssa[e08ec6553c5b268c]::mir::FunctionCx<rustc_codegen_llvm[dea4b532a132fe1]::builder::Builder>>::codegen_terminator
  17:     0x7f23b4f6b276 - rustc_codegen_ssa[e08ec6553c5b268c]::mir::codegen_mir::<rustc_codegen_llvm[dea4b532a132fe1]::builder::Builder>
  18:     0x7f23b4f5768e - rustc_codegen_llvm[dea4b532a132fe1]::base::compile_codegen_unit::module_codegen
  19:     0x7f23b4f538d6 - <rustc_codegen_llvm[dea4b532a132fe1]::LlvmCodegenBackend as rustc_codegen_ssa[e08ec6553c5b268c]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  20:     0x7f23b5175d67 - rustc_codegen_ssa[e08ec6553c5b268c]::base::codegen_crate::<rustc_codegen_llvm[dea4b532a132fe1]::LlvmCodegenBackend>
  21:     0x7f23b50d1474 - <rustc_codegen_llvm[dea4b532a132fe1]::LlvmCodegenBackend as rustc_codegen_ssa[e08ec6553c5b268c]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x7f23b50d0ddd - rustc_interface[6ffa910166101c62]::passes::start_codegen
  23:     0x7f23b50d0458 - <rustc_interface[6ffa910166101c62]::queries::Queries>::codegen_and_build_linker
  24:     0x7f23b4ecd2c4 - rustc_interface[6ffa910166101c62]::interface::run_compiler::<core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>, rustc_driver_impl[e4c67f8d11c8e5e4]::run_compiler::{closure#0}>::{closure#0}
  25:     0x7f23b4fad95d - std[28e079ecff9295a0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6ffa910166101c62]::util::run_in_thread_with_globals<rustc_interface[6ffa910166101c62]::util::run_in_thread_pool_with_globals<rustc_interface[6ffa910166101c62]::interface::run_compiler<core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>, rustc_driver_impl[e4c67f8d11c8e5e4]::run_compiler::{closure#0}>::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>
  26:     0x7f23b4fad76a - <<std[28e079ecff9295a0]::thread::Builder>::spawn_unchecked_<rustc_interface[6ffa910166101c62]::util::run_in_thread_with_globals<rustc_interface[6ffa910166101c62]::util::run_in_thread_pool_with_globals<rustc_interface[6ffa910166101c62]::interface::run_compiler<core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>, rustc_driver_impl[e4c67f8d11c8e5e4]::run_compiler::{closure#0}>::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b4e8c3011bb447ec]::result::Result<(), rustc_span[9e93fcdd45ee9b78]::ErrorGuaranteed>>::{closure#2} as core[b4e8c3011bb447ec]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7f23afd99a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2b96691ad6dafbe5
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/alloc/src/boxed.rs:2018:9
  28:     0x7f23afd99a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h39ccdff465ac8cd2
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/alloc/src/boxed.rs:2018:9
  29:     0x7f23afd99a1b - std::sys::pal::unix::thread::Thread::new::thread_start::h53dc0fc9f9e756a0
                               at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/sys/pal/unix/thread.rs:108:17
  30:     0x7f23afb7e55a - <unknown>
  31:     0x7f23afbfba3c - <unknown>
  32:                0x0 - <unknown>


rustc version: 1.79.0-nightly (0d8b3346a 2024-04-14)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@sgkoishi sgkoishi 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 Apr 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 15, 2024
@jieyouxu jieyouxu added requires-nightly This issue requires a nightly compiler in some way. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
@Luk-ESC
Copy link
Contributor

Luk-ESC commented Apr 17, 2024

Minimized:

pub fn main() {
    _ = Box::new(()) as Box<dyn Send>;
}

rustc -C lto -Z virtual-function-elimination

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 22, 2024
@bors bors closed this as completed in 0e43909 Sep 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 25, 2024
Rollup merge of rust-lang#130734 - Luv-Ray:fix_vfe, r=lcnr

Fix: ices on virtual-function-elimination about principal trait

Extract `load_vtable` function to ensure the `virtual_function_elimination` option is always checked.
It's okay not to use `llvm.type.checked.load` to load the vtable if there is no principal trait.

Fixes rust-lang#123955
Fixes rust-lang#124092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

5 participants