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 for custom_mir #114771

Closed
thomasyonug opened this issue Aug 13, 2023 · 2 comments
Closed

ICE for custom_mir #114771

thomasyonug opened this issue Aug 13, 2023 · 2 comments
Labels
C-bug Category: This is a bug. F-core_intrinsics Issue in the "core intrinsics" for internal usage only. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@thomasyonug
Copy link

I tried this code:

// compile-flags: -O -C no-prepopulate-passes
// only-64bit (so I don't need to worry about usize)

#![crate_type = "lib"]
#![feature(core_intrinsics)]
#![feature(custom_mir)]
#![feature(inline_const)]
#![allow(unreachable_code)]

use std::intrinsics::{transmute, transmute_unchecked};
use std::mem::MaybeUninit;

// Some of these need custom MIR to not get removed by MIR optimizations.
use std::intrinsics::mir::*;

pub enum ZstNever {}

#[repr(align(2))]
pub struct BigNever(ZstNever, u16, ZstNever);



#[custom_mir(diIlect = "runtime", phase = "optimized")]
pub unsafe fn check_to_uninhabited(x: u16) {
    // CHECK-NOT: trap
    // CHECK: call void @llvm.trap
    // CHECK-NOT: trap
    mir! {
        let temp: BigNever;
        {
            temp = CastTransmute(x);
            Return()
        }
    }
}

I expected to see this happen: Non-ICE

Instead, this happened: ICE

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (439d066bc 2023-08-10)
Backtrace

stack backtrace:
   0:     0x7f51d20ab51c - std::backtrace_rs::backtrace::libunwind::trace::h06a38b6c9cfdbe9b
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f51d20ab51c - std::backtrace_rs::backtrace::trace_unsynchronized::h94621a8f307a6745
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f51d20ab51c - std::sys_common::backtrace::_print_fmt::hf5460897cc05e754
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f51d20ab51c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb14c2a33405c8b33
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f51d2110bec - core::fmt::rt::Argument::fmt::hd08db6f9245effbc
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/core/src/fmt/rt.rs:138:9
   5:     0x7f51d2110bec - core::fmt::write::h2fbfad941b9ca326
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f51d209dfde - std::io::Write::write_fmt::hbae1d126fc741d4e
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/io/mod.rs:1714:15
   7:     0x7f51d20ab304 - std::sys_common::backtrace::_print::h98a242d0e78fe80f
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f51d20ab304 - std::sys_common::backtrace::print::h516820fddd883c60
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f51d20ae3fa - std::panicking::panic_hook_with_disk_dump::{{closure}}::h4e2be5b3f48d15f4
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/panicking.rs:278:22
  10:     0x7f51d20ae0e7 - std::panicking::panic_hook_with_disk_dump::ha6499705648762bb
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/panicking.rs:312:9
  11:     0x7f51d0e96b09 - <rustc_driver_impl[f783b04e83c0df3b]::install_ice_hook::{closure#0} as core[a0b4be78361556fd]::ops::function::FnOnce<(&core[a0b4be78361556fd]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f51d20aeca0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8c8459870bc88f61
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/alloc/src/boxed.rs:2021:9
  13:     0x7f51d20aeca0 - std::panicking::rust_panic_with_hook::h68612cf24b5c7f54
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/panicking.rs:733:13
  14:     0x7f51d14ecf11 - std[4b3dd1ed457c0d21]::panicking::begin_panic::<rustc_errors[9a55ef62f22b6c30]::ExplicitBug>::{closure#0}
  15:     0x7f51d14ecc56 - std[4b3dd1ed457c0d21]::sys_common::backtrace::__rust_end_short_backtrace::<std[4b3dd1ed457c0d21]::panicking::begin_panic<rustc_errors[9a55ef62f22b6c30]::ExplicitBug>::{closure#0}, !>
  16:     0x7f51d14e3486 - std[4b3dd1ed457c0d21]::panicking::begin_panic::<rustc_errors[9a55ef62f22b6c30]::ExplicitBug>
  17:     0x7f51d14e11fe - <rustc_errors[9a55ef62f22b6c30]::HandlerInner>::span_bug::<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span, alloc[e72aa507bd8026b6]::string::String>
  18:     0x7f51d14e108f - <rustc_errors[9a55ef62f22b6c30]::Handler>::span_bug::<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span, alloc[e72aa507bd8026b6]::string::String>
  19:     0x7f51d14d34dd - rustc_middle[a10becc82a328565]::util::bug::opt_span_bug_fmt::<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span>::{closure#0}
  20:     0x7f51d14d350a - rustc_middle[a10becc82a328565]::ty::context::tls::with_opt::<rustc_middle[a10becc82a328565]::util::bug::opt_span_bug_fmt<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f51d14d2308 - rustc_middle[a10becc82a328565]::ty::context::tls::with_context_opt::<rustc_middle[a10becc82a328565]::ty::context::tls::with_opt<rustc_middle[a10becc82a328565]::util::bug::opt_span_bug_fmt<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f51cf54e3b4 - rustc_middle[a10becc82a328565]::util::bug::span_bug_fmt::<rustc_span[441fdda0b5fbcdf8]::span_encoding::Span>
  23:     0x7f51d14fdafb - rustc_mir_build[6083803230f11000]::build::custom::build_custom_mir
  24:     0x7f51cfad475b - rustc_mir_build[6083803230f11000]::build::mir_built
  25:     0x7f51cef603bc - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7f51cef6039e - <rustc_query_impl[1ba32842ec703289]::query_impl::mir_built::dynamic_query::{closure#2} as core[a0b4be78361556fd]::ops::function::FnOnce<(rustc_middle[a10becc82a328565]::ty::context::TyCtxt, rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId)>>::call_once
  27:     0x7f51cf040b8d - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::VecCache<rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  28:     0x7f51d081310f - rustc_query_impl[1ba32842ec703289]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f51d0050989 - rustc_mir_transform[66f4d6d4d3dc81de]::check_unsafety::unsafety_check_result
  30:     0x7f51cef603fc - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::unsafety_check_result::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7f51cef603de - <rustc_query_impl[1ba32842ec703289]::query_impl::unsafety_check_result::dynamic_query::{closure#2} as core[a0b4be78361556fd]::ops::function::FnOnce<(rustc_middle[a10becc82a328565]::ty::context::TyCtxt, rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId)>>::call_once
  32:     0x7f51cf040b8d - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::VecCache<rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  33:     0x7f51d08198df - rustc_query_impl[1ba32842ec703289]::query_impl::unsafety_check_result::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7f51d00c2388 - rustc_mir_transform[66f4d6d4d3dc81de]::mir_const
  35:     0x7f51cef6d75e - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::mir_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>
  36:     0x7f51cef6d72e - <rustc_query_impl[1ba32842ec703289]::query_impl::mir_const::dynamic_query::{closure#2} as core[a0b4be78361556fd]::ops::function::FnOnce<(rustc_middle[a10becc82a328565]::ty::context::TyCtxt, rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId)>>::call_once
  37:     0x7f51cf040b8d - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::VecCache<rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  38:     0x7f51d081345f - rustc_query_impl[1ba32842ec703289]::query_impl::mir_const::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7f51cf0be070 - rustc_mir_transform[66f4d6d4d3dc81de]::mir_promoted
  40:     0x7f51cf0bdc51 - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 16usize]>>
  41:     0x7f51cf5aa19c - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::VecCache<rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  42:     0x7f51d0813dd2 - rustc_query_impl[1ba32842ec703289]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7f51cfb402a3 - rustc_borrowck[6a3907173fd0d14e]::mir_borrowck
  44:     0x7f51cef6d6fe - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>
  45:     0x7f51cef6d6ce - <rustc_query_impl[1ba32842ec703289]::query_impl::mir_borrowck::dynamic_query::{closure#2} as core[a0b4be78361556fd]::ops::function::FnOnce<(rustc_middle[a10becc82a328565]::ty::context::TyCtxt, rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId)>>::call_once
  46:     0x7f51cf040b8d - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::VecCache<rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  47:     0x7f51d081cd3f - rustc_query_impl[1ba32842ec703289]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7f51d0362151 - rustc_data_structures[41f7ec6fd6255c47]::sync::par_for_each_in::<&[rustc_span[441fdda0b5fbcdf8]::def_id::LocalDefId], <rustc_middle[a10becc82a328565]::hir::map::Map>::par_body_owners<rustc_interface[2d5c0dcf3991e511]::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  49:     0x7f51d0361e6d - <rustc_session[66a9703df185abe3]::session::Session>::time::<(), rustc_interface[2d5c0dcf3991e511]::passes::analysis::{closure#1}>
  50:     0x7f51d03615de - rustc_interface[2d5c0dcf3991e511]::passes::analysis
  51:     0x7f51d0397a0a - rustc_query_impl[1ba32842ec703289]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1ba32842ec703289]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 1usize]>>
  52:     0x7f51d03979f9 - <rustc_query_impl[1ba32842ec703289]::query_impl::analysis::dynamic_query::{closure#2} as core[a0b4be78361556fd]::ops::function::FnOnce<(rustc_middle[a10becc82a328565]::ty::context::TyCtxt, ())>>::call_once
  53:     0x7f51d0537038 - rustc_query_system[8c83781a6e447705]::query::plumbing::try_execute_query::<rustc_query_impl[1ba32842ec703289]::DynamicConfig<rustc_query_system[8c83781a6e447705]::query::caches::SingleCache<rustc_middle[a10becc82a328565]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1ba32842ec703289]::plumbing::QueryCtxt, false>
  54:     0x7f51d0536dc7 - rustc_query_impl[1ba32842ec703289]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  55:     0x7f51d0504606 - <rustc_middle[a10becc82a328565]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[f783b04e83c0df3b]::run_compiler::{closure#1}::{closure#2}::{closure#6}, core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>>
  56:     0x7f51d0145801 - rustc_span[441fdda0b5fbcdf8]::set_source_map::<core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>, rustc_interface[2d5c0dcf3991e511]::interface::run_compiler<core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>, rustc_driver_impl[f783b04e83c0df3b]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  57:     0x7f51d013fcf0 - std[4b3dd1ed457c0d21]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2d5c0dcf3991e511]::util::run_in_thread_pool_with_globals<rustc_interface[2d5c0dcf3991e511]::interface::run_compiler<core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>, rustc_driver_impl[f783b04e83c0df3b]::run_compiler::{closure#1}>::{closure#0}, core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>>
  58:     0x7f51d070a245 - <<std[4b3dd1ed457c0d21]::thread::Builder>::spawn_unchecked_<rustc_interface[2d5c0dcf3991e511]::util::run_in_thread_pool_with_globals<rustc_interface[2d5c0dcf3991e511]::interface::run_compiler<core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>, rustc_driver_impl[f783b04e83c0df3b]::run_compiler::{closure#1}>::{closure#0}, core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[a0b4be78361556fd]::result::Result<(), rustc_span[441fdda0b5fbcdf8]::ErrorGuaranteed>>::{closure#1} as core[a0b4be78361556fd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  59:     0x7f51d20b92d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h06f83e8f760fbb5a
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/alloc/src/boxed.rs:2007:9
  60:     0x7f51d20b92d5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha5f3dc237aa42fcb
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/alloc/src/boxed.rs:2007:9
  61:     0x7f51d20b92d5 - std::sys::unix::thread::Thread::new::thread_start::ha3ae3b93312e3d63
                               at /rustc/439d066bcf9496b1b8c8dde8bef3bce607a621bb/library/std/src/sys/unix/thread.rs:108:17
  62:     0x7f51cd7206db - start_thread
                               at /build/glibc-S9d2JN/glibc-2.27/nptl/pthread_create.c:463
  63:     0x7f51cd44971f - __GI___clone
                               at /build/glibc-S9d2JN/glibc-2.27/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  64:                0x0 - <unknown>

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 `/home/ywz/Ruzzing/rustc-ice-2023-08-13T05:18:28.145290239Z-24828.txt` to your bug report

query stack during panic:
#0 [mir_built] building MIR for `check_to_uninhabited`
#1 [unsafety_check_result] unsafety-checking `check_to_uninhabited`
#2 [mir_const] preparing `check_to_uninhabited` for borrow checking
#3 [mir_promoted] promoting constants in MIR for `check_to_uninhabited`
#4 [mir_borrowck] borrow-checking `check_to_uninhabited`
#5 [analysis] running analysis passes on this crate
end of query stack

@thomasyonug thomasyonug added the C-bug Category: This is a bug. label Aug 13, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 13, 2023
@fmease
Copy link
Member

fmease commented Aug 13, 2023

ICE message (since it's missing from the PR description):

error: internal compiler error: compiler/rustc_mir_build/src/build/custom/mod.rs:121:17: Unexpected key while parsing custom_mir attribute: 'diIlect'
  --> src/lib.rs:23:14
   |
23 | #[custom_mir(diIlect = "runtime", phase = "optimized")]
   |              ^^^^^^^^^^^^^^^^^^^

Doesn't contain any inline_consts therefore not labeling as such. The label F-custom_mir doesn't exist at the time of writing.

@rustbot label -needs-triage I-ICE T-compiler requires-internal-features F-core_intrinsics

@rustbot rustbot added F-core_intrinsics Issue in the "core intrinsics" for internal usage only. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 13, 2023
@scottmcm
Copy link
Member

Note that ICEs in very-internal stuff like custom MIR are allowed, not bugs, per rust-lang/compiler-team#620

Given that this already has a span pointing right at the issue, that's about as good as can be expected for something that triggers the internal_features warning:

warning: the feature custom_mir is internal to the compiler or standard library

So I'm closing this as not something we'll spend effort to fix.

@scottmcm scottmcm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2023
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. F-core_intrinsics Issue in the "core intrinsics" for internal usage only. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants