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: !layout.abi.is_uninhabited() #120337

Closed
matthiaskrgr opened this issue Jan 25, 2024 · 11 comments · Fixed by #120367
Closed

ice: !layout.abi.is_uninhabited() #120337

matthiaskrgr opened this issue Jan 25, 2024 · 11 comments · Fixed by #120367
Labels
-Zvalidate-mir Unstable option: MIR validation A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

fn test_questionmark() -> Result<(), ()> {
    { 
    Ok(Ok(())) }??;
    Ok(())
}

fn main() {
    test_questionmark().unwrap();
}

Meta

rustc --version --verbose:

rustc 1.77.0-nightly (039d88792 2024-01-25)
binary: rustc
commit-hash: 039d887928361df98ca530471b609378be93983a
commit-date: 2024-01-25
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Error output

rustc --edition=2021 -Zvalidate-mir -Zmir-opt-level=5 -Zunsound-mir-opts treereduce.out

<output>
Backtrace

thread 'rustc' panicked at /rustc/039d887928361df98ca530471b609378be93983a/compiler/rustc_const_eval/src/interpret/projection.rs:222:9:
assertion failed: !layout.abi.is_uninhabited()
stack backtrace:
   0:     0x7f5446c60e86 - std::backtrace_rs::backtrace::libunwind::trace::h6cfe1dadce630036
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f5446c60e86 - std::backtrace_rs::backtrace::trace_unsynchronized::h5abdc3a3af169812
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5446c60e86 - std::sys_common::backtrace::_print_fmt::hcccf5f4ed8ac28ec
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f5446c60e86 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0cd6b2504011a18d
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f5446cb3740 - core::fmt::rt::Argument::fmt::hebc7f15d5b5e154a
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/core/src/fmt/rt.rs:142:9
   5:     0x7f5446cb3740 - core::fmt::write::h78ef4d880a3b55e6
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f5446c5484f - std::io::Write::write_fmt::h75a99451377d7b6f
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/io/mod.rs:1810:15
   7:     0x7f5446c60c64 - std::sys_common::backtrace::_print::h8a38d616c1aebba6
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f5446c60c64 - std::sys_common::backtrace::print::h79c60f2fb75766d0
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f5446c639f7 - std::panicking::default_hook::{{closure}}::h813367f17128fa78
  10:     0x7f5446c63759 - std::panicking::default_hook::h9a25a86054ecacab
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/panicking.rs:292:9
  11:     0x7f544395b54c - std[2d71ddef07c6339c]::panicking::update_hook::<alloc[562726949fe228d0]::boxed::Box<rustc_driver_impl[b5150a49514b53ca]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f5446c64146 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hcf7035261c2dc2f4
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/alloc/src/boxed.rs:2030:9
  13:     0x7f5446c64146 - std::panicking::rust_panic_with_hook::h4227801d760693f2
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/panicking.rs:785:13
  14:     0x7f5446c63e59 - std::panicking::begin_panic_handler::{{closure}}::h27ae2df27d1bb7d2
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/panicking.rs:651:13
  15:     0x7f5446c61386 - std::sys_common::backtrace::__rust_end_short_backtrace::h08fba0b4aacd23ed
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f5446c63be4 - rust_begin_unwind
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/panicking.rs:647:5
  17:     0x7f5446cafe45 - core::panicking::panic_fmt::haba40cee92bb0ca8
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/core/src/panicking.rs:72:14
  18:     0x7f5446caff03 - core::panicking::panic::h7ad960fca41cf254
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/core/src/panicking.rs:144:5
  19:     0x7f54461d9dbc - <rustc_const_eval[ed1a705a637fd062]::interpret::eval_context::InterpCx<rustc_mir_transform[963d0b588447d95f]::dataflow_const_prop::DummyMachine>>::project_downcast::<rustc_const_eval[ed1a705a637fd062]::interpret::operand::OpTy>.cold.0
  20:     0x7f5443f9d12f - <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#0}
  21:     0x7f5443ee8acb - <rustc_mir_dataflow[c9588bf85862e893]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[ed1a705a637fd062]::interpret::operand::OpTy, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#1}>
  22:     0x7f5443ee8b06 - <rustc_mir_dataflow[c9588bf85862e893]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[ed1a705a637fd062]::interpret::operand::OpTy, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#1}>
  23:     0x7f5443ee8b06 - <rustc_mir_dataflow[c9588bf85862e893]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[ed1a705a637fd062]::interpret::operand::OpTy, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_constant::{closure#1}>
  24:     0x7f5443f9d732 - <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::process_operand
  25:     0x7f5443f9ca01 - <rustc_mir_transform[963d0b588447d95f]::jump_threading::TOFinder>::find_opportunity
  26:     0x7f5443f9b459 - <rustc_mir_transform[963d0b588447d95f]::jump_threading::JumpThreading as rustc_middle[4fa995cc45e7b4f0]::mir::MirPass>::run_pass
  27:     0x7f5444cc0a6e - rustc_mir_transform[963d0b588447d95f]::pass_manager::run_passes_inner
  28:     0x7f5444df8789 - rustc_mir_transform[963d0b588447d95f]::optimized_mir
  29:     0x7f5444c5e975 - rustc_query_impl[9793c2de2b9a9b0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9793c2de2b9a9b0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7f5444c5ef61 - rustc_query_system[822af879e6e17ac5]::query::plumbing::try_execute_query::<rustc_query_impl[9793c2de2b9a9b0]::DynamicConfig<rustc_query_system[822af879e6e17ac5]::query::caches::DefIdCache<rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9793c2de2b9a9b0]::plumbing::QueryCtxt, false>
  31:     0x7f5444c5e79e - rustc_query_impl[9793c2de2b9a9b0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f5444dca77c - rustc_middle[4fa995cc45e7b4f0]::query::plumbing::query_get_at::<rustc_query_system[822af879e6e17ac5]::query::caches::DefIdCache<rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 8usize]>>>
  33:     0x7f5444dc9b34 - rustc_mir_transform[963d0b588447d95f]::cross_crate_inline::cross_crate_inlinable
  34:     0x7f5444dc571b - rustc_query_impl[9793c2de2b9a9b0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9793c2de2b9a9b0]::query_impl::cross_crate_inlinable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7f5444dc59f4 - rustc_query_system[822af879e6e17ac5]::query::plumbing::try_execute_query::<rustc_query_impl[9793c2de2b9a9b0]::DynamicConfig<rustc_query_system[822af879e6e17ac5]::query::caches::DefIdCache<rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[9793c2de2b9a9b0]::plumbing::QueryCtxt, false>
  36:     0x7f5444dc544d - rustc_query_impl[9793c2de2b9a9b0]::query_impl::cross_crate_inlinable::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f544556e2c3 - <rustc_mir_transform[963d0b588447d95f]::inline::Inliner>::try_inlining
  38:     0x7f5445572c91 - <rustc_mir_transform[963d0b588447d95f]::inline::Inliner>::process_blocks
  39:     0x7f5444dca38b - <rustc_mir_transform[963d0b588447d95f]::inline::Inline as rustc_middle[4fa995cc45e7b4f0]::mir::MirPass>::run_pass
  40:     0x7f5444cc0a6e - rustc_mir_transform[963d0b588447d95f]::pass_manager::run_passes_inner
  41:     0x7f5444df8789 - rustc_mir_transform[963d0b588447d95f]::optimized_mir
  42:     0x7f5444c5e975 - rustc_query_impl[9793c2de2b9a9b0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9793c2de2b9a9b0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7f5444c5ef61 - rustc_query_system[822af879e6e17ac5]::query::plumbing::try_execute_query::<rustc_query_impl[9793c2de2b9a9b0]::DynamicConfig<rustc_query_system[822af879e6e17ac5]::query::caches::DefIdCache<rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[9793c2de2b9a9b0]::plumbing::QueryCtxt, false>
  44:     0x7f5444c5e79e - rustc_query_impl[9793c2de2b9a9b0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7f5441be32fa - <rustc_middle[4fa995cc45e7b4f0]::ty::context::TyCtxt>::instance_mir
  46:     0x7f544292a6c1 - rustc_monomorphize[48429395c8d43f8f]::collector::collect_items_rec::{closure#0}
  47:     0x7f5445a98aa7 - rustc_monomorphize[48429395c8d43f8f]::collector::collect_items_rec
  48:     0x7f5445a9457b - rustc_monomorphize[48429395c8d43f8f]::partitioning::collect_and_partition_mono_items
  49:     0x7f5445a93bd6 - rustc_query_impl[9793c2de2b9a9b0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9793c2de2b9a9b0]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 24usize]>>
  50:     0x7f5445a93ba5 - <rustc_query_impl[9793c2de2b9a9b0]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[240f245c4852827c]::ops::function::FnOnce<(rustc_middle[4fa995cc45e7b4f0]::ty::context::TyCtxt, ())>>::call_once
  51:     0x7f5445a92f47 - rustc_query_system[822af879e6e17ac5]::query::plumbing::try_execute_query::<rustc_query_impl[9793c2de2b9a9b0]::DynamicConfig<rustc_query_system[822af879e6e17ac5]::query::caches::SingleCache<rustc_middle[4fa995cc45e7b4f0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[9793c2de2b9a9b0]::plumbing::QueryCtxt, false>
  52:     0x7f5445a92c49 - rustc_query_impl[9793c2de2b9a9b0]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7f54456a12d6 - rustc_codegen_ssa[c09e93a0fed8f3a3]::base::codegen_crate::<rustc_codegen_llvm[f9a1bb7d58de6587]::LlvmCodegenBackend>
  54:     0x7f54456a0f75 - <rustc_codegen_llvm[f9a1bb7d58de6587]::LlvmCodegenBackend as rustc_codegen_ssa[c09e93a0fed8f3a3]::traits::backend::CodegenBackend>::codegen_crate
  55:     0x7f544569f370 - rustc_interface[1f676e8d56904132]::passes::start_codegen
  56:     0x7f544569eab4 - <rustc_interface[1f676e8d56904132]::queries::Queries>::codegen_and_build_linker
  57:     0x7f544598d74a - rustc_interface[1f676e8d56904132]::interface::run_compiler::<core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>, rustc_driver_impl[b5150a49514b53ca]::run_compiler::{closure#0}>::{closure#0}
  58:     0x7f5445bddb06 - std[2d71ddef07c6339c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1f676e8d56904132]::util::run_in_thread_with_globals<rustc_interface[1f676e8d56904132]::util::run_in_thread_pool_with_globals<rustc_interface[1f676e8d56904132]::interface::run_compiler<core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>, rustc_driver_impl[b5150a49514b53ca]::run_compiler::{closure#0}>::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>
  59:     0x7f5445bdd933 - <<std[2d71ddef07c6339c]::thread::Builder>::spawn_unchecked_<rustc_interface[1f676e8d56904132]::util::run_in_thread_with_globals<rustc_interface[1f676e8d56904132]::util::run_in_thread_pool_with_globals<rustc_interface[1f676e8d56904132]::interface::run_compiler<core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>, rustc_driver_impl[b5150a49514b53ca]::run_compiler::{closure#0}>::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[240f245c4852827c]::result::Result<(), rustc_span[6ce47fc6caf6b4a2]::ErrorGuaranteed>>::{closure#1} as core[240f245c4852827c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  60:     0x7f5446c6d735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hce32de47adeb9ab6
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/alloc/src/boxed.rs:2016:9
  61:     0x7f5446c6d735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h22cf91fbafc72b5d
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/alloc/src/boxed.rs:2016:9
  62:     0x7f5446c6d735 - std::sys::pal::unix::thread::Thread::new::thread_start::h4f77d8ca10599a35
                               at /rustc/039d887928361df98ca530471b609378be93983a/library/std/src/sys/pal/unix/thread.rs:108:17
  63:     0x7f5440aaa9eb - <unknown>
  64:     0x7f5440b2e7cc - <unknown>
  65:                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: please attach the file at `/tmp/im/rustc-ice-2024-01-25T11_27_00-1814810.txt` to your bug report

note: compiler flags: -Z validate-mir -Z mir-opt-level=5 -Z unsound-mir-opts

query stack during panic:
#0 [optimized_mir] optimizing MIR for `test_questionmark`
#1 [cross_crate_inlinable] whether the item should be made inlinable across crates
#2 [optimized_mir] optimizing MIR for `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@matthiaskrgr matthiaskrgr added 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. labels Jan 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 25, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 25, 2024
@Noratrieb Noratrieb added requires-nightly This issue requires a nightly compiler in some way. A-mir-opt Area: MIR optimizations labels Jan 25, 2024
@compiler-errors
Copy link
Member

-Zunsound-mir-opts + -Zvalidate-mir seem like options that when paired together would cause issues... At first glance, I'm actually not sure why this is filed as a bug.

@saethlin
Copy link
Member

saethlin commented Jan 25, 2024

I agree. Nobody should be testing -Zunsound-mir-opts, I don't know why those passes are even in the codebase.

But this is a bug. I've found this in real code with a much smaller set of flags:

-Zmir-enable-passes=+JumpThreading

And this bisects to #119627 Bisected by hand, there's no nightly with that PR yet. Don't know where Matthias got that toolchain.

@compiler-errors
Copy link
Member

Afaict @matthiaskrgr likes to do ICE testing against master 😺

@djkoloski
Copy link
Contributor

We just hit this on Fuchsia as well. I think we should revert the PR until we fix this issue and reland it.

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jan 25, 2024

Another one with --crate-type lib --emit=mir

pub enum HiddenType {}

pub trait HiddenTrait {}

pub enum MyLibType {}


impl From<HiddenType> for MyLibType {
    fn from(it: HiddenType) -> MyLibType {
        match it {}
    }
}

pub struct T<T>(T);

impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
    fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
        todo!()
    }
}

@matthiaskrgr matthiaskrgr added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed requires-nightly This issue requires a nightly compiler in some way. labels Jan 25, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 25, 2024
@matthiaskrgr
Copy link
Member Author

Also here's a list of files from the rustc repo that all seem to trigger the problem in one way or another

+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./compiler/rustc_ast_pretty/src/pp/ring.rs",
+    "args": [
+      "--crate-type=lib",
+      "-Zmir-opt-level=5",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
--
+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./src/librustdoc/html/escape.rs",
+    "args": [
+      "--crate-type=lib",
+      "-Zmir-opt-level=5",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
--
+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./src/tools/cargo/src/cargo/util/queue.rs",
+    "args": [
+      "--crate-type=lib",
+      "-Zmir-opt-level=5",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
--
+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./src/tools/rust-analyzer/crates/rust-analyzer/src/version.rs",
+    "args": [
+      "--crate-type=lib",
+      "-Zmir-opt-level=5",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
+  },
+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./tests/codegen/set-discriminant-invalid.rs",
+    "args": [
+      "-Zmir-opt-level=2",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at /rustc/5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c/compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
--
+  },
+  {
+    "regresses_on": "Master",
+    "needs_feature": true,
+    "file": "./src/tools/miri/tests/fail/never_transmute_void.rs",
+    "args": [
+      "--emit=mir",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
--
+  {
+    "regresses_on": "Master",
+    "needs_feature": false,
+    "file": "./tests/rustdoc/same-crate-hidden-impl-parameter.rs",
+    "args": [
+      "--crate-type=lib",
+      "--emit=mir",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
+  },
+  {
+    "regresses_on": "Master",
+    "needs_feature": true,
+    "file": "./tests/ui/intrinsics/panic-uninitialized-zeroed.rs",
+    "args": [
+      "--emit=mir",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
+  },
+  {
+    "regresses_on": "Master",
+    "needs_feature": true,
+    "file": "./tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/indirect_match_with_exhaustive_patterns_same_crate.rs",
+    "args": [
+      "--emit=mir",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
+    }
+  },
+  {
+    "regresses_on": "Master",
+    "needs_feature": true,
+    "file": "./tests/ui/rfcs/rfc-2008-non-exhaustive/uninhabited/match_with_exhaustive_patterns_same_crate.rs",
+    "args": [
+      "--emit=mir",
+      "-ooutputfile",
+      "-Zdump-mir-dir=dir"
+    ],
+    "error_reason": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "ice_msg": "thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:222:9: 'assertion failed: !layout.abi.is_uninhabited()'",
+    "executable": "Rustc",
+    "kind": {
+      "Ice": "Interesting"
     }

@tmiasko
Copy link
Contributor

tmiasko commented Jan 25, 2024

Looks like there is one more issue in GVN (rustc +039d887928361df98ca530471b609378be93983a c.rs -O --crate-type=lib):

#![feature(never_type)]
#[derive(Copy, Clone)]
pub enum E { A(!, u32), }
pub union U { i: u32, e: E, }
pub const fn f() -> u32 {
    let E::A(_, i) = unsafe { (&U { i: 0 }).e } ;
    i 
}

@tmiasko
Copy link
Contributor

tmiasko commented Jan 25, 2024

There is no basis for the assumption that interpreter will never downcast to an uninhabited variant:

#![feature(never_type)]
#[derive(Copy, Clone)]
pub enum E { A(!), }
pub union U { u: (), e: E, }
pub const C: () = {
    let E::A(ref a) = unsafe { &(&U { u: () }).e};
};

@RalfJung
Copy link
Member

@tmiasko nice example!
That assert was added as an experiment to see if we ever hit that codepath, and it seems like the answer is yes. It should thus be removed, with a suitable const-eval test case.

@RalfJung
Copy link
Member

I wonder if that code shouldn't have a Discriminant read somewhere though... it is conceptually a match after all.

Still, the assertion should go: #120367.
That adds @tmiasko's test, but not the others.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 26, 2024
@bors bors closed this as completed in cdd4ff8 Jan 26, 2024
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 31, 2024
interpret: project_downcast: do not ICE for uninhabited variants

Fixes rust-lang/rust#120337

This assertion was already under discussion for a bit; I think the [example](rust-lang/rust#120337 (comment)) `@tmiasko` found is the final nail in the coffin. One could argue maybe MIR building should read the discriminant before projecting, but even then MIR optimizations should be allowed to remove that read, so the downcast should still not ICE. Maybe the downcast should be UB, but in this example UB already arises earlier when a value of type `E` is constructed.

r? `@oli-obk`
@fmease fmease added the -Zvalidate-mir Unstable option: MIR validation label May 16, 2024
@fmease fmease added the -Zvalidate-mir Unstable option: MIR validation label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zvalidate-mir Unstable option: MIR validation A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
10 participants