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 when specific compilation optimization passes are enabled/disabled #125823

Closed
cicilzx opened this issue May 31, 2024 · 4 comments
Closed

ICE when specific compilation optimization passes are enabled/disabled #125823

cicilzx opened this issue May 31, 2024 · 4 comments
Labels
A-mir-opt Area: MIR optimizations C-gub Category: the reverse of a compiler bug is generally UB

Comments

@cicilzx
Copy link

cicilzx commented May 31, 2024

Code

I'm using a crate named aHash, following the usual compilation and testing methods, it's running well:

git clone https://github.com/tkaitchuck/aHash.git
cd aHash
cargo build
cargo test

But I've tried some specific compilation optimization passes, such as:

RUSTFLAGS="-Z mir-enable-passes=-SanityCheck,-UnreachablePropagation,-AddCallGuards,-DeadStoreElimination,+SimplifyCfg" cargo test

It triggers ICE.

Meta

rustc --version --verbose:

1.80.0-nightly (d84b90375 2024-05-19)

Error output

query stack during panic:
#0 [optimized_mir] optimizing MIR for `hir::<impl at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.8.3/src/hir/mod.rs:253:1: 253:9>::class`
#1 [optimized_mir] optimizing MIR for `hir::translate::<impl at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.8.3/src/hir/translate.rs:328:1: 328:45>::visit_post`
end of query stack
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/transform/validate.rs:412:26:
broken MIR in Item(DefId(0:939 ~ regex_syntax[c242]::hir::{impl#5}::class)) (after phase change to runtime-optimized) at bb2[1]:
encountered critical edge in `Call` terminator _0 = Hir::fail() -> [return: bb10, unwind: bb12]
stack backtrace:
   0:     0x7f1f119a5d95 - std::backtrace_rs::backtrace::libunwind::trace::h3584992836d3fbbe
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f1f119a5d95 - std::backtrace_rs::backtrace::trace_unsynchronized::h865f81351202189f
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1f119a5d95 - std::backtrace::Backtrace::create::h30948aa5edf96654
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/backtrace.rs:331:13
   3:     0x7f1f119a5ce5 - std::backtrace::Backtrace::force_capture::had1b801792222bac
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/backtrace.rs:312:9
   4:     0x7f1f14b27cc9 - std[6297c21057101fb8]::panicking::update_hook::<alloc[7e13e290523b950f]::boxed::Box<rustc_driver_impl[e20a0da03b31dfb7]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f1f119c0a8b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb564346ea13651a2
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/alloc/src/boxed.rs:2036:9
   6:     0x7f1f119c0a8b - std::panicking::rust_panic_with_hook::hf8bca4696aa0179f
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/panicking.rs:799:13
   7:     0x7f1f119c0804 - std::panicking::begin_panic_handler::{{closure}}::h83080272bbecfd37
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/panicking.rs:664:13
   8:     0x7f1f119be049 - std::sys_common::backtrace::__rust_end_short_backtrace::h1bfc03d655e7db7e
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7f1f119c0537 - rust_begin_unwind
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/panicking.rs:652:5
  10:     0x7f1f11a09243 - core::panicking::panic_fmt::h88ae93bb9f3a46ce
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/panicking.rs:72:14
  11:     0x7f1f13f82d49 - <rustc_const_eval[3bc430fcd9c8a0aa]::transform::validate::CfgChecker>::fail::<alloc[7e13e290523b950f]::string::String>
  12:     0x7f1f13f81289 - <rustc_const_eval[3bc430fcd9c8a0aa]::transform::validate::Validator as rustc_middle[ac419db0aedf4fc9]::mir::MirPass>::run_pass
  13:     0x7f1f15e32b7e - rustc_mir_transform[5f6a42c238b75f5f]::pass_manager::run_passes_inner
  14:     0x7f1f166c11a6 - rustc_mir_transform[5f6a42c238b75f5f]::optimized_mir
  15:     0x7f1f166c036b - rustc_query_impl[9f2686db69ad98de]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9f2686db69ad98de]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>
  16:     0x7f1f15ea02d7 - rustc_query_system[95d03348241a091e]::query::plumbing::try_execute_query::<rustc_query_impl[9f2686db69ad98de]::DynamicConfig<rustc_query_system[95d03348241a091e]::query::caches::DefIdCache<rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9f2686db69ad98de]::plumbing::QueryCtxt, false>
  17:     0x7f1f15e9fa1e - rustc_query_impl[9f2686db69ad98de]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7f1f162eb3f5 - <rustc_middle[ac419db0aedf4fc9]::ty::context::TyCtxt>::instance_mir
  19:     0x7f1f16734e1b - <rustc_mir_transform[5f6a42c238b75f5f]::inline::Inliner>::try_inlining
  20:     0x7f1f1672e605 - <rustc_mir_transform[5f6a42c238b75f5f]::inline::Inliner>::process_blocks
  21:     0x7f1f167306c3 - <rustc_mir_transform[5f6a42c238b75f5f]::inline::Inline as rustc_middle[ac419db0aedf4fc9]::mir::MirPass>::run_pass
  22:     0x7f1f15e3280d - rustc_mir_transform[5f6a42c238b75f5f]::pass_manager::run_passes_inner
  23:     0x7f1f166c11a6 - rustc_mir_transform[5f6a42c238b75f5f]::optimized_mir
  24:     0x7f1f166c036b - rustc_query_impl[9f2686db69ad98de]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9f2686db69ad98de]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f1f15ea02d7 - rustc_query_system[95d03348241a091e]::query::plumbing::try_execute_query::<rustc_query_impl[9f2686db69ad98de]::DynamicConfig<rustc_query_system[95d03348241a091e]::query::caches::DefIdCache<rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9f2686db69ad98de]::plumbing::QueryCtxt, false>
  26:     0x7f1f15e9fa1e - rustc_query_impl[9f2686db69ad98de]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7f1f16730b27 - rustc_middle[ac419db0aedf4fc9]::query::plumbing::query_get_at::<rustc_query_system[95d03348241a091e]::query::caches::DefIdCache<rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>>
  28:     0x7f1f1391da6b - rustc_mir_transform[5f6a42c238b75f5f]::cross_crate_inline::cross_crate_inlinable
  29:     0x7f1f1617ebf5 - rustc_query_impl[9f2686db69ad98de]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9f2686db69ad98de]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7f1f1617fb98 - rustc_query_system[95d03348241a091e]::query::plumbing::try_execute_query::<rustc_query_impl[9f2686db69ad98de]::DynamicConfig<rustc_query_system[95d03348241a091e]::query::caches::DefIdCache<rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9f2686db69ad98de]::plumbing::QueryCtxt, false>
  31:     0x7f1f1617f749 - rustc_query_impl[9f2686db69ad98de]::query_impl::cross_crate_inlinable::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f1f162c9746 - rustc_passes[686eb54dafee1ba]::reachable::recursively_reachable
  33:     0x7f1f162c6d37 - rustc_passes[686eb54dafee1ba]::reachable::reachable_set
  34:     0x7f1f16bec262 - rustc_query_impl[9f2686db69ad98de]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9f2686db69ad98de]::query_impl::reachable_set::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>
  35:     0x7f1f16be7c12 - rustc_query_system[95d03348241a091e]::query::plumbing::try_execute_query::<rustc_query_impl[9f2686db69ad98de]::DynamicConfig<rustc_query_system[95d03348241a091e]::query::caches::SingleCache<rustc_middle[ac419db0aedf4fc9]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9f2686db69ad98de]::plumbing::QueryCtxt, false>
  36:     0x7f1f16be7302 - rustc_query_impl[9f2686db69ad98de]::query_impl::reachable_set::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f1f165b097d - <rustc_metadata[461dcbe0c1ce682d]::rmeta::encoder::EncodeContext>::encode_crate_root
  38:     0x7f1f16c12718 - rustc_metadata[461dcbe0c1ce682d]::rmeta::encoder::encode_metadata
  39:     0x7f1f16c0d932 - rustc_metadata[461dcbe0c1ce682d]::fs::encode_and_write_metadata
  40:     0x7f1f16c0c3da - rustc_interface[fb674f9ecc44cad9]::passes::start_codegen
  41:     0x7f1f16c0bb1a - <rustc_interface[fb674f9ecc44cad9]::queries::Queries>::codegen_and_build_linker
  42:     0x7f1f16a65b2e - rustc_interface[fb674f9ecc44cad9]::interface::run_compiler::<core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>, rustc_driver_impl[e20a0da03b31dfb7]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7f1f16a51009 - std[6297c21057101fb8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fb674f9ecc44cad9]::util::run_in_thread_with_globals<rustc_interface[fb674f9ecc44cad9]::util::run_in_thread_pool_with_globals<rustc_interface[fb674f9ecc44cad9]::interface::run_compiler<core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>, rustc_driver_impl[e20a0da03b31dfb7]::run_compiler::{closure#0}>::{closure#1}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>::{closure#0}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>
  44:     0x7f1f16a50db6 - <<std[6297c21057101fb8]::thread::Builder>::spawn_unchecked_<rustc_interface[fb674f9ecc44cad9]::util::run_in_thread_with_globals<rustc_interface[fb674f9ecc44cad9]::util::run_in_thread_pool_with_globals<rustc_interface[fb674f9ecc44cad9]::interface::run_compiler<core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>, rustc_driver_impl[e20a0da03b31dfb7]::run_compiler::{closure#0}>::{closure#1}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>::{closure#0}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10ea89227602499e]::result::Result<(), rustc_span[d4e6cc84b2dc2c94]::ErrorGuaranteed>>::{closure#2} as core[10ea89227602499e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7f1f119ca86b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h22a0540ca3730804
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/alloc/src/boxed.rs:2022:9
  46:     0x7f1f119ca86b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha4ec028e8180a669
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/alloc/src/boxed.rs:2022:9
  47:     0x7f1f119ca86b - std::sys::pal::unix::thread::Thread::new::thread_start::h204d4931f51cce4b
                               at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/sys/pal/unix/thread.rs:108:17
  48:     0x7f1f118c9609 - start_thread
                               at /build/glibc-LcI20x/glibc-2.31/nptl/pthread_create.c:477:8
  49:     0x7f1f117ec353 - clone
                               at /build/glibc-LcI20x/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  50:                0x0 - <unknown>


rustc version: 1.80.0-nightly (d84b90375 2024-05-19)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [optimized_mir] optimizing MIR for `hir::<impl at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.8.3/src/hir/mod.rs:253:1: 253:9>::class`
#1 [optimized_mir] optimizing MIR for `hir::translate::<impl at /local/home/zixliu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.8.3/src/hir/translate.rs:328:1: 328:45>::visit_post`
#2 [cross_crate_inlinable] whether the item should be made inlinable across crates
#3 [reachable_set] reachability
end of query stack

@cicilzx cicilzx 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 May 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 31, 2024
@bjorn3
Copy link
Member

bjorn3 commented May 31, 2024

The CriticalCallEdges pass is a mandatory part of lowering MIR into something that codegen can handle. You disabled it with -AddCallGuards however.

@cicilzx
Copy link
Author

cicilzx commented May 31, 2024

The CriticalCallEdges pass is a mandatory part of lowering MIR into something that codegen can handle. You disabled it with -AddCallGuards however.

So, there are some passes that can't be disabled, right? I thought that when mir-opt level was set to 0, all passes were disabled. And may I ask which passes may have a similar problem if they are disabled?

@bjorn3
Copy link
Member

bjorn3 commented May 31, 2024

Check if there is an is_enabled method in the MirPass impl in https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_transform/src. If not, it will not be disabled with -Zmir-opt-level=0 and disabling it manually may cause issues like this. -Zmir-opt-level=0 disables all optimization passes, but not correctness passes like CriticalCallEdges.

@cicilzx
Copy link
Author

cicilzx commented May 31, 2024

Oh I see. Thank you so much!

@cicilzx cicilzx closed this as completed May 31, 2024
@saethlin saethlin added A-mir-opt Area: MIR optimizations C-discussion Category: Discussion or questions that doesn't represent real issues. and removed 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. C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 1, 2024
@workingjubilee workingjubilee added C-gub Category: the reverse of a compiler bug is generally UB and removed C-discussion Category: Discussion or questions that doesn't represent real issues. labels Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-gub Category: the reverse of a compiler bug is generally UB
Projects
None yet
Development

No branches or pull requests

5 participants